mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-30 07:03:06 -08:00
Merge pull request #2306 from EdSchouten/sorted-alerts
Use lexicographic order to sort alerts by name.
This commit is contained in:
commit
90dd216646
14
web/web.go
14
web/web.go
|
@ -274,7 +274,7 @@ func (h *Handler) Run() {
|
||||||
|
|
||||||
func (h *Handler) alerts(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) alerts(w http.ResponseWriter, r *http.Request) {
|
||||||
alerts := h.ruleManager.AlertingRules()
|
alerts := h.ruleManager.AlertingRules()
|
||||||
alertsSorter := byAlertStateSorter{alerts: alerts}
|
alertsSorter := byAlertStateAndNameSorter{alerts: alerts}
|
||||||
sort.Sort(alertsSorter)
|
sort.Sort(alertsSorter)
|
||||||
|
|
||||||
alertStatus := AlertStatus{
|
alertStatus := AlertStatus{
|
||||||
|
@ -541,18 +541,20 @@ type AlertStatus struct {
|
||||||
AlertStateToRowClass map[rules.AlertState]string
|
AlertStateToRowClass map[rules.AlertState]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type byAlertStateSorter struct {
|
type byAlertStateAndNameSorter struct {
|
||||||
alerts []*rules.AlertingRule
|
alerts []*rules.AlertingRule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s byAlertStateSorter) Len() int {
|
func (s byAlertStateAndNameSorter) Len() int {
|
||||||
return len(s.alerts)
|
return len(s.alerts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s byAlertStateSorter) Less(i, j int) bool {
|
func (s byAlertStateAndNameSorter) Less(i, j int) bool {
|
||||||
return s.alerts[i].State() > s.alerts[j].State()
|
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]
|
s.alerts[i], s.alerts[j] = s.alerts[j], s.alerts[i]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue