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
Conversation
rules/manager.go
Outdated
Groups []*AlertingGroup | ||
} | ||
|
||
type AlertingGroup struct { |
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.
Hmm, I think it might be better to just return the existing rule.Group
structs here and add Name()
and AlertingRules()
methods on that type directly.
rules/manager.go
Outdated
return alerts | ||
} | ||
|
||
type AlertingGroups struct { |
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'm not sure we need this intermediary type. Just return a slice of []*rule.Group
directly from the method that returns the rule groups?
rules/manager.go
Outdated
type AlertingGroup struct { | ||
Name string | ||
Rules []*AlertingRule | ||
AlertStateToRowClass map[AlertState]string |
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.
This map is only relevant for display purposes and shouldn't live in the rule code or be attached to every individual group. Best to keep it part of the top-level data value that is passed into the HTML template.
web/web.go
Outdated
|
||
alertStatus := AlertStatus{ | ||
AlertingRules: alertsSorter.alerts, | ||
AlertStateToRowClass: map[rules.AlertState]string{ |
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.
You'll probably want to keep the AlertStatus
struct as the top-level value that is passed into the HTML template, but change the type to take alerting groups instead of individual alerting rules. In any case, AlertStateToRowClass
should only be instantiated once, in this top-level field of that struct.
rules/manager.go
Outdated
@@ -362,6 +362,38 @@ func (g *Group) hash() uint64 { | |||
return l.Hash() | |||
} | |||
|
|||
// AlertingRules returns the list of the group's alerting rules |
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.
tiny nit: for consistency, godoc comments should be full sentences ending with a .
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.
Done :)
I think I've addressed the comments from @juliusv let me know if I've missed something or you want something changing. The "Fixed group sorting and comments" commit didn't pass the checks because I didn't run gofmt on manager.go and web.go. The new "Fixed group sorting and comments with gofmt" commit passes the checks. I've also changed how the RuleGroups() method sorts groups, before if two groups had the same name then refreshing the page would occasionally shuffle the group, so I added code to check if the group name is the same then sort by file name so that the Group position is more likely to be fixed. I welcome any feedback/ suggestions 👍 |
rules/manager.go
Outdated
@@ -871,7 +903,7 @@ func (m *Manager) RuleGroups() []*Group { | |||
|
|||
// Sort rule groups by file, then by name. | |||
sort.Slice(rgs, func(i, j int) bool { | |||
if rgs[i].file != rgs[j].file { | |||
if rgs[i].name == rgs[j].name { |
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.
It kinda seems odd to sort by file as if it's lower in the file->group->rule hierarchy than the group... how about always sorting by file first, then by group name, but surfacing the file name in the group header somehow (maybe {{.Name}} ({{.File}})
instead of just {{.Name}}
)? I don't think we should introduce a new dropdown level in the UI for just the file, but making it visible in an unobtrusive way could be good and make the file->group sorting behavior less confusing for users. Maybe even make the group name grey/italic/small or something, so it pops out less, but is still there?
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.
Hmm, your screenshots and updates say that the ordering now happens by file first, but the code here still looks like it's sorting by name first?
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.
Ah, I think a code push is missing?
Looks great besides the one comment, thanks :) |
Here's a view with setting the Group Header row padding to 2px, which style looks better to you @juliusv. Should there be a label like Group:(Group Name) and File:(File Name) in the row so users know what they mean? |
@juliusv I swapped the File and Group name since it is ordered by File name first, and made the group name smaller so it is still visible. If there aren't any more changes you would like I can make the commit and make the pull request an Open one. |
Gah, so sorry for the delay again! Taking another look now! |
Ah ok, was confused by the code not being there yet, but you said "I can make the commit", sorry :) Regarding the formatting I might find something like "foo-rules.yml > alerting" more visually pleasing than the more explicit "File: foo-rules.yml Group: alerting" (maybe in that case, even keep it the same font). Otherwise, great. |
Signed-off-by: Pritam Bhudia <pritam.bhudia@baesystems.com>
Signed-off-by: Pritam Bhudia <pritam.bhudia@baesystems.com>
Signed-off-by: Pritam Bhudia <pritam.bhudia@baesystems.com>
Signed-off-by: Pritam Bhudia <pritam.bhudia@baesystems.com>
Signed-off-by: Pritam Bhudia <pritam.bhudia@baesystems.com>
Signed-off-by: Pritam Bhudia <pritam.bhudia@baesystems.com>
@juliusv The latest commit changes the formatting to File Name > Group Name. |
rules/manager.go
Outdated
@@ -267,7 +268,7 @@ func NewGroup(name, file string, interval time.Duration, rules []Rule, shouldRes | |||
func (g *Group) Name() string { return g.name } | |||
|
|||
// File returns the group's file. | |||
func (g *Group) File() string { return g.file } | |||
func (g *Group) File() string { return filepath.Base(g.file) } |
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).
Looks good besides the last comment, thanks! Could you mark the PR as ready for review as well? |
(and as for what exactly we display how, I might still go through some iterations / tweaks of it after having experienced it for a while :)) |
Signed-off-by: Pritam Bhudia <pritam.bhudia@baesystems.com>
I allowed myself to mark the PR as ready for review and will merge - thank you :) |
Is there any configurable parameter to have /alerts sorted by status as in the 2.9.x? |
As mentioned in #1371 and #3579, this is a draft pull request for sorting alerts by group name on the alerts page. As it stands I need some help sorting the groups alphabetically, when the page is refreshed the groups shuffle position.