Skip to content
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

Merged
merged 7 commits into from May 14, 2019
Merged

Sorting alerts by group name in /alerts #5448

merged 7 commits into from May 14, 2019

Conversation

pbhudiaBAE
Copy link
Contributor

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.

rules/manager.go Outdated
Groups []*AlertingGroup
}

type AlertingGroup struct {
Copy link
Member

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 {
Copy link
Member

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
Copy link
Member

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{
Copy link
Member

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
Copy link
Contributor

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 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@pbhudiaBAE
Copy link
Contributor Author

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 {
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member

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?

@juliusv
Copy link
Member

juliusv commented Apr 18, 2019

Looks great besides the one comment, thanks :)

@pbhudiaBAE
Copy link
Contributor Author

pbhudiaBAE commented Apr 18, 2019

// Sort rule groups by file, then by name.
sort.Slice(rgs, func(i, j int) bool {
	if rgs[i].file != rgs[j].file {
		return rgs[i].file < rgs[j].file
	}
	return rgs[i].name < rgs[j].name
})
return rgs
}

You mean keep the sorting of groups like how it was before (above)?

I changed the File method on the Group struct to return filepath.Base(g.file) instead of g.file (so you only get the file name and not the whole path) and made the group name italic in the HTML.

Here's a screenshot of it so far.
GroupandFile

Some suggestions for styling:

  • Move the File Name to the very end of the Group Header row.
  • Make the Group Header row thinner than the normal alert rows.
  • Make the Group header text size smaller than the alert text size.

@pbhudiaBAE
Copy link
Contributor Author

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?
SmallerGroupHeader

@pbhudiaBAE
Copy link
Contributor Author

pbhudiaBAE commented Apr 29, 2019

FileAndGroupName

@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.

@juliusv
Copy link
Member

juliusv commented May 8, 2019

Gah, so sorry for the delay again! Taking another look now!

@juliusv
Copy link
Member

juliusv commented May 8, 2019

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>
@pbhudiaBAE
Copy link
Contributor Author

File Group

@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) }
Copy link
Member

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).

@juliusv
Copy link
Member

juliusv commented May 14, 2019

Looks good besides the last comment, thanks! Could you mark the PR as ready for review as well?

@juliusv
Copy link
Member

juliusv commented May 14, 2019

(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>
@juliusv juliusv marked this pull request as ready for review May 14, 2019 21:13
@juliusv
Copy link
Member

juliusv commented May 14, 2019

I allowed myself to mark the PR as ready for review and will merge - thank you :)

@sirikhum
Copy link

Is there any configurable parameter to have /alerts sorted by status as in the 2.9.x?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants