mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
Correctly sort alerts in dedup code
This commit is contained in:
@@ -33,8 +33,8 @@ func DedupAlerts() []models.AlertGroup {
|
||||
if found {
|
||||
for _, am := range alert.Alertmanager {
|
||||
a.Alertmanager = append(a.Alertmanager, am)
|
||||
alerts[alertLFP] = a
|
||||
}
|
||||
alerts[alertLFP] = a
|
||||
} else {
|
||||
alerts[alertLFP] = alert
|
||||
}
|
||||
@@ -43,6 +43,10 @@ func DedupAlerts() []models.AlertGroup {
|
||||
ag := models.AlertGroup(agList[0])
|
||||
ag.Alerts = models.AlertList{}
|
||||
for _, alert := range alerts {
|
||||
// sort Alertmanager instances for every alert
|
||||
sort.Slice(alert.Alertmanager, func(i, j int) bool {
|
||||
return alert.Alertmanager[i].Name < alert.Alertmanager[j].Name
|
||||
})
|
||||
ag.Alerts = append(ag.Alerts, alert)
|
||||
}
|
||||
sort.Sort(ag.Alerts)
|
||||
@@ -52,7 +56,9 @@ func DedupAlerts() []models.AlertGroup {
|
||||
|
||||
// sort alert groups so they are always returned in the same order
|
||||
// use group ID which is unique and immutable
|
||||
sort.Slice(dedupedGroups, func(i, j int) bool { return dedupedGroups[i].ID < dedupedGroups[j].ID })
|
||||
sort.Slice(dedupedGroups, func(i, j int) bool {
|
||||
return dedupedGroups[i].ID < dedupedGroups[j].ID
|
||||
})
|
||||
|
||||
return dedupedGroups
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user