Skip to content

Commit

Permalink
fix(observability-lib): updating alert rules + deleting associated al…
Browse files Browse the repository at this point in the history
…erts when deleting dashboard
  • Loading branch information
Atrax1 committed Nov 13, 2024
1 parent ad26f60 commit b9c51b6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion observability-lib/grafana/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type DeployOptions struct {

func alertRuleExist(alerts []alerting.Rule, alert alerting.Rule) bool {
for _, a := range alerts {
if reflect.DeepEqual(a, alert) {
if reflect.DeepEqual(a.Title, alert.Title) {
return true
}
}
Expand Down Expand Up @@ -212,6 +212,19 @@ func DeleteDashboard(options *DeleteOptions) error {
return errGetDashboard
}

alertsRule, errGetAlertRules := grafanaClient.GetAlertRulesByDashboardUID(*db.UID)
if errGetAlertRules != nil {
return errGetAlertRules
}

// delete existing alert rules for the dashboard if alerts are disabled
for _, rule := range alertsRule {
_, _, errDeleteAlertRule := grafanaClient.DeleteAlertRule(*rule.Uid)
if errDeleteAlertRule != nil {
return errDeleteAlertRule
}
}

_, errDelete := grafanaClient.DeleteDashboardByUID(*db.UID)
if errDelete != nil {
return errDelete
Expand Down

0 comments on commit b9c51b6

Please sign in to comment.