New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting alerts by group name in /alerts #5448
Changes from 6 commits
5d57868
b8e77bc
341a682
8a5fcf7
6a51154
e7f9fb8
341baa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,12 +499,16 @@ func (h *Handler) Run(ctx context.Context) error { | |
} | ||
|
||
func (h *Handler) alerts(w http.ResponseWriter, r *http.Request) { | ||
alerts := h.ruleManager.AlertingRules() | ||
alertsSorter := byAlertStateAndNameSorter{alerts: alerts} | ||
sort.Sort(alertsSorter) | ||
|
||
var groups []*rules.Group | ||
for _, group := range h.ruleManager.RuleGroups() { | ||
if group.HasAlertingRules() { | ||
groups = append(groups, group) | ||
} | ||
} | ||
|
||
alertStatus := AlertStatus{ | ||
AlertingRules: alertsSorter.alerts, | ||
Groups: groups, | ||
AlertStateToRowClass: map[rules.AlertState]string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll probably want to keep the |
||
rules.StateInactive: "success", | ||
rules.StatePending: "warning", | ||
|
@@ -926,24 +930,6 @@ func (h *Handler) executeTemplate(w http.ResponseWriter, name string, data inter | |
|
||
// AlertStatus bundles alerting rules and the mapping of alert states to row classes. | ||
type AlertStatus struct { | ||
AlertingRules []*rules.AlertingRule | ||
Groups []*rules.Group | ||
AlertStateToRowClass map[rules.AlertState]string | ||
} | ||
|
||
type byAlertStateAndNameSorter struct { | ||
alerts []*rules.AlertingRule | ||
} | ||
|
||
func (s byAlertStateAndNameSorter) Len() int { | ||
return len(s.alerts) | ||
} | ||
|
||
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 byAlertStateAndNameSorter) Swap(i, j int) { | ||
s.alerts[i], s.alerts[j] = s.alerts[j], s.alerts[i] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok to preserve the full path here (this function is already used by
/rules
as well, where it already shows the whole path, see e.g. http://demo.robustperception.io:9090/rules).