Merge pull request #2306 from EdSchouten/sorted-alerts

Use lexicographic order to sort alerts by name.
This commit is contained in:
Julius Volz 2016-12-31 13:12:30 +01:00 committed by GitHub
commit 90dd216646
1 changed files with 8 additions and 6 deletions

View File

@ -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]
}