diff --git a/web/web.go b/web/web.go index 97dd0b0a42..3d16e09d0e 100644 --- a/web/web.go +++ b/web/web.go @@ -274,7 +274,7 @@ func (h *Handler) Run() { func (h *Handler) alerts(w http.ResponseWriter, r *http.Request) { alerts := h.ruleManager.AlertingRules() - alertsSorter := byAlertStateSorter{alerts: alerts} + alertsSorter := byAlertStateAndNameSorter{alerts: alerts} sort.Sort(alertsSorter) alertStatus := AlertStatus{ @@ -541,18 +541,20 @@ type AlertStatus struct { AlertStateToRowClass map[rules.AlertState]string } -type byAlertStateSorter struct { +type byAlertStateAndNameSorter struct { alerts []*rules.AlertingRule } -func (s byAlertStateSorter) Len() int { +func (s byAlertStateAndNameSorter) Len() int { return len(s.alerts) } -func (s byAlertStateSorter) Less(i, j int) bool { - return s.alerts[i].State() > s.alerts[j].State() +func (s byAlertStateAndNameSorter) Less(i, j int) bool { + return s.alerts[i].State() > s.alerts[j].State() || + (s.alerts[i].State() == s.alerts[j].State() && + s.alerts[i].Name() < s.alerts[j].Name()) } -func (s byAlertStateSorter) Swap(i, j int) { +func (s byAlertStateAndNameSorter) Swap(i, j int) { s.alerts[i], s.alerts[j] = s.alerts[j], s.alerts[i] }