From 1e543d5ac12d7a47310e25768a88fb2ab0cf7820 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Tue, 2 Jun 2020 19:33:13 +0300 Subject: [PATCH] Alerting: Ignore obsolete notification channels referenced by alerts (#25302) * Ignore obsolete notification channel * Fix tests * Update pkg/services/alerting/rule.go Co-authored-by: Marcus Efraimsson --- pkg/services/alerting/rule.go | 5 +++-- pkg/services/alerting/rule_test.go | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/services/alerting/rule.go b/pkg/services/alerting/rule.go index 900fc792306..037e215585e 100644 --- a/pkg/services/alerting/rule.go +++ b/pkg/services/alerting/rule.go @@ -140,9 +140,10 @@ func NewRuleFromDBAlert(ruleDef *models.Alert) (*Rule, error) { if id, err := jsonModel.Get("id").Int64(); err == nil { uid, err := translateNotificationIDToUID(id, ruleDef.OrgId) if err != nil { - return nil, ValidationError{Reason: "Unable to translate notification id to uid, " + err.Error(), DashboardID: model.DashboardID, AlertID: model.ID, PanelID: model.PanelID} + logger.Error("Unable to translate notification id to uid", "error", err.Error(), "dashboardId", model.DashboardID, "alertId", model.ID, "panelId", model.PanelID, "notificationId", id) + } else { + model.Notifications = append(model.Notifications, uid) } - model.Notifications = append(model.Notifications, uid) } else if uid, err := jsonModel.Get("uid").String(); err == nil { model.Notifications = append(model.Notifications, uid) } else { diff --git a/pkg/services/alerting/rule_test.go b/pkg/services/alerting/rule_test.go index f8e44d16302..04164000965 100644 --- a/pkg/services/alerting/rule_test.go +++ b/pkg/services/alerting/rule_test.go @@ -125,7 +125,8 @@ func TestAlertRuleModel(t *testing.T) { "frequency": "60s", "conditions": [{"type": "test", "prop": 123 }], "notifications": [ - {"id": 999} + {"id": 999}, + {"uid": "notifier2"} ] } ` @@ -142,10 +143,11 @@ func TestAlertRuleModel(t *testing.T) { Settings: alertJSON, } - _, err := NewRuleFromDBAlert(alert) - Convey("raises an error", func() { - So(err, ShouldNotBeNil) - So(err.Error(), ShouldEqual, "Alert validation error: Unable to translate notification id to uid, Alert notification [ Id: 999, OrgId: 1 ] not found AlertId: 1 PanelId: 1 DashboardId: 1") + alertRule, err := NewRuleFromDBAlert(alert) + Convey("swallows the error", func() { + So(err, ShouldBeNil) + So(alertRule.Notifications, ShouldNotContain, "999") + So(alertRule.Notifications, ShouldContain, "notifier2") }) })