mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): remove annotations when deleting alert, closes #6244
This commit is contained in:
@@ -46,13 +46,23 @@ func GetAllAlertQueryHandler(query *m.GetAllAlertsQuery) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteAlertByIdInternal(alertId int64, reason string, sess *xorm.Session) error {
|
||||
sqlog.Debug("Deleting alert", "id", alertId, "reason", reason)
|
||||
|
||||
if _, err := sess.Exec("DELETE FROM alert WHERE id = ?", alertId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := sess.Exec("DELETE FROM annotation WHERE alert_id = ?", alertId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteAlertById(cmd *m.DeleteAlertCommand) error {
|
||||
return inTransaction(func(sess *xorm.Session) error {
|
||||
if _, err := sess.Exec("DELETE FROM alert WHERE id = ?", cmd.AlertId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return deleteAlertByIdInternal(cmd.AlertId, "DeleteAlertCommand", sess)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -110,12 +120,7 @@ func DeleteAlertDefinition(dashboardId int64, sess *xorm.Session) error {
|
||||
sess.Where("dashboard_id = ?", dashboardId).Find(&alerts)
|
||||
|
||||
for _, alert := range alerts {
|
||||
_, err := sess.Exec("DELETE FROM alert WHERE id = ? ", alert.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sqlog.Debug("Alert deleted (due to dashboard deletion)", "name", alert.Name, "id", alert.Id)
|
||||
deleteAlertByIdInternal(alert.Id, "Dashboard deleted", sess)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -195,12 +200,7 @@ func deleteMissingAlerts(alerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xorm
|
||||
}
|
||||
|
||||
if missing {
|
||||
_, err := sess.Exec("DELETE FROM alert WHERE id = ?", missingAlert.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sqlog.Debug("Alert deleted", "name", missingAlert.Name, "id", missingAlert.Id)
|
||||
deleteAlertByIdInternal(missingAlert.Id, "Removed from dashboard", sess)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user