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

Sort dispatched alerts by job+instance in the correct order (#1178) #1339

Closed
wants to merge 1 commit into from

Conversation

tzz
Copy link
Contributor

@tzz tzz commented Apr 23, 2018

Alert order was wrongly implemented, trivial change. Followup fix to #1234

@tiagoapimenta
Copy link

@tzz Don't you believe you should switch the true/false on lines 433 and 437 as well?

@tzz tzz force-pushed the sort-alerts-in-correct-order branch from 5aa4256 to d1f5589 Compare April 23, 2018 14:20
@tzz
Copy link
Contributor Author

tzz commented Apr 23, 2018

@tiagoapimenta yes you're right. Fixed. This really should have an acceptance test to avoid the hassle but I don't know how to write it.

@tzz tzz force-pushed the sort-alerts-in-correct-order branch from d1f5589 to cde5c77 Compare April 23, 2018 14:22
@simonpasquier
Copy link
Member

This really should have an acceptance test to avoid the hassle but I don't know how to write it.

AFAICT the existing sort algorithm on types.Alert is only used by dispatch/dispatch_test.go.

alertmanager/types/types.go

Lines 269 to 271 in cecfe5b

func (as AlertSlice) Less(i, j int) bool { return as[i].UpdatedAt.Before(as[j].UpdatedAt) }
func (as AlertSlice) Swap(i, j int) { as[i], as[j] = as[j], as[i] }
func (as AlertSlice) Len() int { return len(as) }

I guess that you can replace it by what you have implemented in dispatch/dispatch.go. Then you can add the unit tests to types/types_test.go which is simpler than doing it in dispatch/dispatch_test.go.

@tzz
Copy link
Contributor Author

tzz commented Apr 27, 2018

@simonpasquier thanks for the advice. Is the test a blocker for this PR or can we add it later (so it won't block the 0.15 release)? I definitely can't work on it in the next 2 weeks.

@simonpasquier
Copy link
Member

I would rather have some unit tests because it may surface other sorting problems. I could give it a try if you don't mind.

@tzz
Copy link
Contributor Author

tzz commented Apr 27, 2018

Please do! I would really appreciate it.

@mxinden
Copy link
Member

mxinden commented Jun 16, 2018

#1349 included this patch with additional tests. I will close here. @tzz please feel free to reopen in case I am missing something.

Thanks a lot for the fix!

@mxinden mxinden closed this Jun 16, 2018
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.

4 participants