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

re-add alert groups endpoint #1791

Merged
merged 1 commit into from
Apr 17, 2019
Merged

Conversation

stuartnelson3
Copy link
Contributor

requested in #868

this contains a lot that is open to discussion, including:

  • what the definition of the returned struct/struct members for the alert groups endpoint should be
  • the implementation of finding the groups, particularly the weird bit with the giving the EnrichedAlert a reference to a slice of its receivers. staticcheck isn't happy about how I went about doing this, either.
  • all the naming (like EnhancedAlert), and the path name /alerts/groups

I decided to wait on writing any tests until we can figure out what it is we want to have in this pr

@stuartnelson3
Copy link
Contributor Author

stuartnelson3 commented Mar 11, 2019

PR that removed alert groups originally: #1525

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

Just a few notes but I haven't look into the details yet.

api/v2/api.go Outdated
matchers = []*labels.Matcher{}
)

if params.Filter != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed.

api/v2/openapi.yaml Show resolved Hide resolved
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Only looked at the API code for now. I will take a look at the dispatcher logic in a bit. This week is a bit packed, I am sorry for the delay.

api/v2/openapi.yaml Outdated Show resolved Hide resolved
labels:
$ref: '#/definitions/labelSet'
receiver:
type: string
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of reusing the receiver definition below?

Why is receiver an object? I thought we might want to expose extra info about a single receiver in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, any idea what we might expose? A receiver is mostly connection information that we don't want to expose.

Copy link
Member

Choose a reason for hiding this comment

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

Not aware of anything specific. I am fine with either way, I would just prefer to be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, I'm fine either way too :) if you want to add the extra info let me know, otherwise i'll leave it as-is

Copy link
Member

Choose a reason for hiding this comment

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

Then I would prefer reusing the receiver definition below. (We might want to expose the receiver type in the future.)

api/v2/api.go Outdated
Alerts: make([]*open_api_models.GettableAlert, 0, len(alertGroup.Alerts)),
}

for _, ea := range alertGroup.Alerts {
Copy link
Member

Choose a reason for hiding this comment

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

What does ea stand for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

enriched alert. happy to change it, it's fairly cryptic.

Copy link
Member

Choose a reason for hiding this comment

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

That would be helpful, thanks.

api/v2/api.go Outdated Show resolved Hide resolved
@stuartnelson3
Copy link
Contributor Author

Aw, if I accept your suggestions they fail because they have no DCO

dispatch/dispatch.go Outdated Show resolved Hide resolved
Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

My main feedback would be to keep the dispatch package mostly dumb and move most of the logic to the API v2.

dispatch/dispatch.go Outdated Show resolved Hide resolved
dispatch/dispatch.go Outdated Show resolved Hide resolved
dispatch/dispatch.go Outdated Show resolved Hide resolved
@stuartnelson3
Copy link
Contributor Author

Made a lot of changes based on @simonpasquier 's suggestions, when you have a chance take a look. Did some rough manual testing and it seems to be working.

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Logic in dispatch looks very clean! Just small comments, nothing major.

Given that this could fix the compatibility issues with karma, @prymitive do you have thoughts on this as well?

api/v2/api.go Outdated
@@ -53,6 +54,7 @@ type API struct {
peer *cluster.Peer
silences *silence.Silences
alerts provider.Alerts
groups groupsFn
Copy link
Member

Choose a reason for hiding this comment

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

For me this is ambiguous, does it return groups of alerts, silences, receivers, apples, ...? How about alertGroups?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apples would be nice. Will update :)

if params.Receiver != nil {
receiverFilter, err = regexp.Compile("^(?:" + *params.Receiver + ")$")
if err != nil {
return alertgroup_ops.
Copy link
Member

Choose a reason for hiding this comment

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

In the above for loop we log the error, here we don't. Can we be consistent with either way?

labels:
$ref: '#/definitions/labelSet'
receiver:
type: string
Copy link
Member

Choose a reason for hiding this comment

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

Then I would prefer reusing the receiver definition below. (We might want to expose the receiver type in the future.)

@stuartnelson3
Copy link
Contributor Author

ptal when you two have a chance

api/v2/api.go Outdated Show resolved Hide resolved
api/v2/api.go Outdated Show resolved Hide resolved
dispatch/dispatch.go Outdated Show resolved Hide resolved
@prymitive
Copy link
Contributor

Logic in dispatch looks very clean! Just small comments, nothing major.

Given that this could fix the compatibility issues with karma, @prymitive do you have thoughts on this as well?

In general this seem to make it easier for me, for example karma already has a concept of alert group, I don't see anything that could be problematic for me in any obvious ways. That being said I'm currently traveling so I'm not gonna pretend that I've put a lot of effort into reviewing this or trying to use this code.

@stuartnelson3
Copy link
Contributor Author

Added a test

@prymitive
Copy link
Contributor

FYI I'll be back home next week and I'll be able to do some integration tests agains this PR for karma, if that's helpful

@stuartnelson3
Copy link
Contributor Author

Definitely! would love to hear if this is useful for you, or if there's anything you would like to add/change

@mohsen0
Copy link

mohsen0 commented Apr 10, 2019

Can this PR be progressed?
Thanks

@stuartnelson3
Copy link
Contributor Author

Can this PR be progressed?

Waiting for some feedback from @prymitive, and if there are any more questions/comments from @mxinden and @simonpasquier

@prymitive
Copy link
Contributor

I hope to get some work done today evening

@prymitive
Copy link
Contributor

I was able to get it working easily with those changes and it seems to be working perfectly 🎉
I used the alert generator I have on http://karma-demo.herokuapp.com and I got exact same set of alerts via the v2 API 🎉
It also looks like I could kill some of the ugly code I have in the backend if I would drop support for non openapi alertmanager versions.
There's really not much feedback I can provide other than "it works" since all karma is doing is pulling all silences and alerts, so it's a very basic use of the API provided.
Thanks! Great work!

@stuartnelson3
Copy link
Contributor Author

great to hear! once I get a final 👍 from @mxinden and @simonpasquier this will be merged

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Other than #1791 (comment) this looks good to me. Thanks @stuartnelson3!

@masalawarrior
Copy link

@stuartnelson3 You got a chance to look at Max's comment ? Would be great to have this merged in soon. Thanks for your work on this :)

@stuartnelson3
Copy link
Contributor Author

@stuartnelson3 You got a chance to look at Max's comment ? Would be great to have this merged in soon. Thanks for your work on this :)

thanks for the ping, i missed his message!

Other than #1791 (comment) this looks good to me. Thanks @stuartnelson3!

sorry for missing that log line, I added it to the alert groups endpoint but not the normal alerts endpoint. hopefully now this PR is good to go

@mohsen0
Copy link

mohsen0 commented Apr 16, 2019

@mxinden Are you happy with the latest changes?

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

This looks good to me. @stuartnelson3 would you mind reducing the amount of commits in the pull request? Otherwise we can also squash them to a single one. As you wish.

@xocasdashdash
Copy link

Once this PR is merged, when do you think the next alertmanager version is going to be released?

Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
@stuartnelson3
Copy link
Contributor Author

Once this PR is merged, when do you think the next alertmanager version is going to be released?

Not sure. I would like to update the ui to use this groups endpoint by default when displaying alerts, which could hopefully be done next week.

@stuartnelson3 stuartnelson3 merged commit b694eef into master Apr 17, 2019
@stuartnelson3 stuartnelson3 deleted the stn+gs/alert-groups-endpoint branch April 17, 2019 10:24
@stuartnelson3
Copy link
Contributor Author

I plan on releasing 0.17.0 next week, which will include this PR.

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.

7 participants