Skip to content

Commit

Permalink
Sort dispatched alerts by job+instance then rest by default (promethe…
Browse files Browse the repository at this point in the history
  • Loading branch information
tzz committed Mar 22, 2018
1 parent a43a513 commit 430aa44
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions dispatch/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,26 @@ func (ag *aggrGroup) flush(notify func(...*types.Alert) bool) {
alertsSlice = append(alertsSlice, alert)
}

sort.SliceStable(alertsSlice, func(i, j int) bool {
// Look at labels.job, then labels.instance.
for _, override_key := range [...]model.LabelName{"job", "instance"} {
key_i, ok_i := alertsSlice[i].Labels[override_key]
if !ok_i {
return true
}
key_j, ok_j := alertsSlice[j].Labels[override_key]
if !ok_j {
return false
}

if key_i != key_j {
return key_i > key_j
}
}

return alertsSlice[i].Labels.Before(alertsSlice[j].Labels)
})

ag.mtx.Unlock()

level.Debug(ag.logger).Log("msg", "Flushing", "alerts", fmt.Sprintf("%v", alertsSlice))
Expand Down

0 comments on commit 430aa44

Please sign in to comment.