mirror of
https://github.com/prometheus/prometheus
synced 2025-01-13 02:14:08 +00: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) {
|
||||
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]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user