Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve getting/updating contact points for Grafana Alerting integration #2742

Merged
merged 49 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1649bd9
some initial refactoring&cleanup, first lines for supporting custom s…
teodosii Jul 28, 2023
8c18192
typing
teodosii Jul 31, 2023
2f5c213
render custom fields in gform
teodosii Jul 31, 2023
32b5f44
Merge branch 'dev' into rares/new-integrations-alerting
teodosii Jul 31, 2023
abf9ffe
lint fix
teodosii Jul 31, 2023
3922952
Merge branch 'dev' into rares/new-integrations-alerting
teodosii Aug 1, 2023
82eab15
minor changes, added mocking
teodosii Aug 1, 2023
3c91d7a
Add draft for getting alerting contact points endpoints and update al…
Ferril Aug 3, 2023
e906483
Merge branch 'grafana-alerting-integration-v2' into rares/new-integra…
teodosii Aug 4, 2023
0efa8d4
Add draft for updating alerting contact points endpoints and update a…
Ferril Aug 4, 2023
2bd741c
make gform work with custom fields renderer
teodosii Aug 4, 2023
6db987e
Merge branch 'grafana-alerting-integration-v2' into rares/new-integra…
teodosii Aug 7, 2023
4a518e2
connect contact point
teodosii Aug 7, 2023
4c6b99c
remaining code for creating new contact point
teodosii Aug 7, 2023
3d39489
Update grafana alerting sync manager
Ferril Aug 8, 2023
6639b79
Add tests for getting/connecting/creating/disconnecting contact point…
Ferril Aug 8, 2023
6bb8ce0
contact points
teodosii Aug 8, 2023
b46ecf3
added contact points table
teodosii Aug 9, 2023
4322b19
drawer table view changes
teodosii Aug 9, 2023
0a2d28a
added open contactpoint/disconnect in the table view
teodosii Aug 10, 2023
b20993b
Add removing oncall integration config from alerting configs on delet…
Ferril Aug 10, 2023
44446b1
Update grafana alerting sync manager, update response error details f…
Ferril Aug 10, 2023
a22e464
Update grafana alerting sync manager
Ferril Aug 10, 2023
6c92a51
figured out mobx issue on updating contactpoints
teodosii Aug 10, 2023
9c7f101
better handling on table actions
teodosii Aug 10, 2023
81d3806
minor changes
teodosii Aug 10, 2023
b055a8a
fix
teodosii Aug 11, 2023
296f5a0
added validation
teodosii Aug 11, 2023
23d28e5
ui tweak for showing validation
teodosii Aug 14, 2023
313dc77
added check for unifiedAlerting
teodosii Aug 14, 2023
5d89f82
open drawer from link
teodosii Aug 14, 2023
b6436ec
linter
teodosii Aug 14, 2023
4ea7395
Fix grafana alerting sync manager, add tests
Ferril Aug 14, 2023
ac5bd5f
Fix grafana alerting sync manager
Ferril Aug 14, 2023
36166cd
Fix grafana alerting sync manager, add tests
Ferril Aug 14, 2023
ebaf942
refactored integrations component to reduce lines count
teodosii Aug 14, 2023
f45ef80
imports
teodosii Aug 14, 2023
e5ecb44
lint suggestions
teodosii Aug 14, 2023
4048978
minor improvements
teodosii Aug 14, 2023
d11ecab
linter imports
teodosii Aug 14, 2023
48af199
Merge branch 'rares/new-integrations-alerting' into grafana-alerting-…
teodosii Aug 14, 2023
2cd81c1
minor changes
teodosii Aug 14, 2023
aa96dc3
Merge branch 'dev' into grafana-alerting-integration-v2
teodosii Aug 14, 2023
cd37e53
import fix
teodosii Aug 14, 2023
20ea668
Merge branch 'dev' into grafana-alerting-integration-v2
teodosii Aug 17, 2023
a00e40c
added Raphael's mentions
teodosii Aug 17, 2023
bbca401
better form validation
teodosii Aug 17, 2023
a5720f1
Return default contact point if config was deleted for mimir alertman…
Ferril Aug 17, 2023
104a7b8
Update CHANGELOG.md
Ferril Aug 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed

- Improve Grafana Alerting integration by @Ferril @teodosii ([#2742](https://github.com/grafana/oncall/pull/2742))

## v1.3.24 (2023-08-17)

### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .grafana_alerting_sync import GrafanaAlertingSyncManager # noqa: F401

Large diffs are not rendered by default.

31 changes: 13 additions & 18 deletions engine/apps/alerts/models/alert_receive_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from apps.alerts.grafana_alerting_sync_manager.grafana_alerting_sync import GrafanaAlertingSyncManager
from apps.alerts.integration_options_mixin import IntegrationOptionsMixin
from apps.alerts.models.maintainable_object import MaintainableObject
from apps.alerts.tasks import disable_maintenance, sync_grafana_alerting_contact_points
from apps.alerts.tasks import disable_maintenance, disconnect_integration_from_alerting_contact_points
from apps.base.messaging import get_messaging_backend_from_id
from apps.base.utils import live_settings
from apps.integrations.legacy_prefix import remove_legacy_prefix
Expand All @@ -41,7 +41,7 @@
if typing.TYPE_CHECKING:
from django.db.models.manager import RelatedManager

from apps.alerts.models import AlertGroup, ChannelFilter, GrafanaAlertingContactPoint
from apps.alerts.models import AlertGroup, ChannelFilter
from apps.user_management.models import Organization, Team

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -117,7 +117,6 @@ class AlertReceiveChannel(IntegrationOptionsMixin, MaintainableObject):

alert_groups: "RelatedManager['AlertGroup']"
channel_filters: "RelatedManager['ChannelFilter']"
contact_points: "RelatedManager['GrafanaAlertingContactPoint']"
organization: "Organization"
team: typing.Optional["Team"]

Expand Down Expand Up @@ -165,7 +164,7 @@ class AlertReceiveChannel(IntegrationOptionsMixin, MaintainableObject):
verbal_name = models.CharField(max_length=150, null=True, default=None)
description_short = models.CharField(max_length=250, null=True, default=None)

is_finished_alerting_setup = models.BooleanField(default=False)
is_finished_alerting_setup = models.BooleanField(default=False) # deprecated

# *_*_template fields are legacy way of storing templates
# messaging_backends_templates for new integrations' templates
Expand Down Expand Up @@ -288,6 +287,13 @@ def change_team(self, team_id, user):
def grafana_alerting_sync_manager(self):
return GrafanaAlertingSyncManager(self)

@property
def is_alerting_integration(self):
return self.integration in {
AlertReceiveChannel.INTEGRATION_GRAFANA_ALERTING,
AlertReceiveChannel.INTEGRATION_LEGACY_GRAFANA_ALERTING,
}

@cached_property
def team_name(self):
return self.team.name if self.team else "No team"
Expand Down Expand Up @@ -652,21 +658,10 @@ def listen_for_alertreceivechannel_model_save(

metrics_add_integration_to_cache(instance)

if instance.integration in {
AlertReceiveChannel.INTEGRATION_GRAFANA_ALERTING,
AlertReceiveChannel.INTEGRATION_LEGACY_GRAFANA_ALERTING,
}:
if created:
instance.grafana_alerting_sync_manager.create_contact_points()
# do not trigger sync contact points if field "is_finished_alerting_setup" was updated
elif (
kwargs is None
or not kwargs.get("update_fields")
or "is_finished_alerting_setup" not in kwargs["update_fields"]
):
sync_grafana_alerting_contact_points.apply_async((instance.pk,), countdown=5)

elif instance.deleted_at:
if instance.is_alerting_integration:
disconnect_integration_from_alerting_contact_points.apply_async((instance.pk,), countdown=5)

metrics_remove_deleted_integration_from_cache(instance)
else:
metrics_update_integration_cache(instance)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
logger = logging.getLogger(__name__)


# deprecated
class GrafanaAlertingContactPoint(models.Model):
GRAFANA_CONTACT_POINT = "grafana"
ALERTING_DATASOURCE = "alertmanager"
Expand Down
5 changes: 4 additions & 1 deletion engine/apps/alerts/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from .send_alert_group_signal import send_alert_group_signal # noqa: F401
from .send_update_log_report_signal import send_update_log_report_signal # noqa: F401
from .send_update_resolution_note_signal import send_update_resolution_note_signal # noqa: F401
from .sync_grafana_alerting_contact_points import sync_grafana_alerting_contact_points # noqa: F401
from .sync_grafana_alerting_contact_points import ( # noqa: F401
disconnect_integration_from_alerting_contact_points,
sync_grafana_alerting_contact_points,
)
from .unsilence import unsilence_task # noqa: F401
from .wipe import wipe # noqa: F401
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from apps.alerts.grafana_alerting_sync_manager.grafana_alerting_sync import GrafanaAlertingSyncManager
from common.custom_celery_tasks import shared_dedicated_queue_retry_task


# deprecated
@shared_dedicated_queue_retry_task(autoretry_for=(Exception,), retry_backoff=True, max_retries=10)
def sync_grafana_alerting_contact_points(alert_receive_channel_id):
pass


@shared_dedicated_queue_retry_task(autoretry_for=(Exception,), retry_backoff=True, max_retries=10)
def disconnect_integration_from_alerting_contact_points(alert_receive_channel_id):
from apps.alerts.models import AlertReceiveChannel

alert_receive_channel = AlertReceiveChannel.objects_with_deleted.get(pk=alert_receive_channel_id)

GrafanaAlertingSyncManager(alert_receive_channel).sync_each_contact_point()
alert_receive_channel.grafana_alerting_sync_manager.disconnect_all_contact_points()
Loading