This commit is contained in:
parent
1531aa66f3
commit
099b6a1d43
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue