mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): delete alerts when dashboard gets deleted
This commit is contained in:
@@ -128,21 +128,47 @@ func TestAlertingDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
Convey("When dashboard is removed", func() {
|
||||||
Convey("When dashboard is removed", func() {
|
items := []m.Alert{
|
||||||
DeleteDashboard(&m.DeleteDashboardCommand{
|
{
|
||||||
OrgId: 1,
|
PanelId: 1,
|
||||||
Slug: testDash.Slug,
|
DashboardId: testDash.Id,
|
||||||
})
|
Query: "Query",
|
||||||
|
QueryRefId: "A",
|
||||||
|
WarnLevel: "> 30",
|
||||||
|
CritLevel: "> 50",
|
||||||
|
Interval: "10",
|
||||||
|
Title: "Alerting title",
|
||||||
|
Description: "Alerting description",
|
||||||
|
QueryRange: "5m",
|
||||||
|
Aggregator: "avg",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
Convey("Alerts should be removed", func() {
|
cmd := m.SaveAlertsCommand{
|
||||||
alerts, err2 := GetAlertsByDashboardId(testDash.Id)
|
Alerts: &items,
|
||||||
|
DashboardId: testDash.Id,
|
||||||
|
OrgId: 1,
|
||||||
|
UserId: 1,
|
||||||
|
}
|
||||||
|
|
||||||
So(testDash.Id, ShouldEqual, 1)
|
SaveAlerts(&cmd)
|
||||||
So(err2, ShouldBeNil)
|
|
||||||
So(len(alerts), ShouldEqual, 0)
|
DeleteDashboard(&m.DeleteDashboardCommand{
|
||||||
})
|
OrgId: 1,
|
||||||
|
Slug: testDash.Slug,
|
||||||
})
|
})
|
||||||
*/
|
|
||||||
|
/* Uncomment this once we know why inTransaction2 is failing in unit tests
|
||||||
|
|
||||||
|
Convey("Alerts should be removed", func() {
|
||||||
|
alerts, err2 := GetAlertsByDashboardId(testDash.Id)
|
||||||
|
|
||||||
|
So(testDash.Id, ShouldEqual, 1)
|
||||||
|
So(err2, ShouldBeNil)
|
||||||
|
So(len(alerts), ShouldEqual, 0)
|
||||||
|
})
|
||||||
|
*/
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,6 +227,7 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error {
|
|||||||
"DELETE FROM dashboard_tag WHERE dashboard_id = ? ",
|
"DELETE FROM dashboard_tag WHERE dashboard_id = ? ",
|
||||||
"DELETE FROM star WHERE dashboard_id = ? ",
|
"DELETE FROM star WHERE dashboard_id = ? ",
|
||||||
"DELETE FROM dashboard WHERE id = ?",
|
"DELETE FROM dashboard WHERE id = ?",
|
||||||
|
"DELETE FROM alert WHERE dashboard_id = ?",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, sql := range deletes {
|
for _, sql := range deletes {
|
||||||
|
|||||||
Reference in New Issue
Block a user