Skip to content

Commit

Permalink
Update find contact point name, receiver could be missing key (#2046)
Browse files Browse the repository at this point in the history
Fixes issue when syncing contact points and there are receiver configs
with no `grafana_managed_receiver_configs` key.
(eg. `{"name": "autogen-contact-point-default"}`)
  • Loading branch information
matiasb authored May 29, 2023
1 parent 8049b50 commit bd14292
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Helm chart: fix bugs in helm chart with external postgresql configuration by @alexintech ([#2036](https://github.com/grafana/oncall/pull/2036))
- Properly address `Organization.DoesNotExist` exceptions thrown which result in HTTP 500 for the Slack `interactive_api_endpoint`
endpoint by @joeyorlando ([#2040](https://github.com/grafana/oncall/pull/2040))
- Fix issue when trying to sync Grafana contact point and config receivers miss a key ([#2046](https://github.com/grafana/oncall/pull/2046))

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def _find_name_of_contact_point_by_uid(self, contact_point_uid, receivers) -> st
name_in_alerting = None
# find name of contact point in alerting config by contact point uid
for receiver in receivers:
receiver_configs = receiver["grafana_managed_receiver_configs"]
receiver_configs = receiver.get("grafana_managed_receiver_configs", [])
for receiver_config in receiver_configs:
if receiver_config["uid"] == contact_point_uid:
name_in_alerting = receiver_config["name"]
Expand Down
26 changes: 26 additions & 0 deletions engine/apps/alerts/tests/test_grafana_alerting_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from apps.alerts.grafana_alerting_sync_manager.grafana_alerting_sync import GrafanaAlertingSyncManager


@pytest.mark.django_db
def test_find_name_of_contact_point_grafana_datasource(make_organization, make_alert_receive_channel):
organization = make_organization()
alert_receive_channel = make_alert_receive_channel(organization)
sync_manager = GrafanaAlertingSyncManager(alert_receive_channel)

receivers = [
{"name": "autogen-contact-point-default"},
{
"name": "testing",
"grafana_managed_receiver_configs": [
{
"uid": "some-uid",
"name": "testing",
}
],
},
]

name = sync_manager.find_name_of_contact_point("some-uid", True, receivers)
assert name == "testing"

0 comments on commit bd14292

Please sign in to comment.