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

Expose alert fingerprint in the API #786

Merged
merged 4 commits into from
Aug 18, 2017
Merged

Expose alert fingerprint in the API #786

merged 4 commits into from
Aug 18, 2017

Conversation

prymitive
Copy link
Contributor

Alert fingerprint is already provided as the value of status.inhibitedBy[] attribute that inhibited alerts have, but there's no way to get back to the alert that's inhibiting it as the fingerprint is not exposed.

I'm not sure if using fingerprints is desirable, but that's currently the value of inhibitedBy @stuartnelson3
The goal here is to be able to link back from inhibited to inhibiting alert based on the API response, which isn't currently doable.

@stuartnelson3
Copy link
Contributor

I think fingerprints are the method of identification we're going to be using for now, but with this method you're required to filter through all the alerts being sent from the current api endpoint. I think it would make more sense to have a new endpoint added, like /api/v0/alerts/abc-fingerprint-123, and then maintain a map[Fingerprint]Alert to query against. This map would have to have access coordinated to it for additions and deletions.

@fabxc is this new endpoing something that should be added?

@prymitive
Copy link
Contributor Author

prymitive commented May 10, 2017

Is there a reason to hide fingerprints in the /api/v1/alerts/groups endpoint?
A dedicated endpoint to get an alert by id seems like a good idea, but you should still be able to get an id of any alert, not just those that are inhibiting others.
Use case example: I have an alert, I want to see if it's inhibiting any other alert - for that I need to know the id. Without the id I need to get all inhibited alerts, fetch each inhibiting alert by id and compare it with the alert that I'm checking.

@stuartnelson3
Copy link
Contributor

Makes sense to me, but waiting on a response from @fabxc

@fabxc
Copy link
Contributor

fabxc commented Jun 6, 2017

Probably makes sense to add them to our API. We can make individual alerts gettable once there's a use case.

Copy link
Contributor

@stuartnelson3 stuartnelson3 left a comment

Choose a reason for hiding this comment

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

Could you also add this to https://github.com/prometheus/alertmanager/blob/master/api/api.go#L254? The frontend is now using the list endpoint instead of the groups endpoint.

@prymitive
Copy link
Contributor Author

Added to the list endpoint

api/api.go Outdated
@@ -314,6 +315,7 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) {
apiAlert := &APIAlert{
Alert: &a.Alert,
Status: status,
ID: fmt.Sprintf("%d", a.Fingerprint()),
Copy link
Member

Choose a reason for hiding this comment

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

Could we print this not as base10 but as base16 with %x?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this to reduce the length of the ID?

Copy link
Member

Choose a reason for hiding this comment

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

No, it's just the base 16, with lower-case letters for a-f. See https://golang.org/pkg/fmt/#hdr-Printing

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I'm just wondering why you want base 16 instead of base 10

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 this was a suggestion by @fabxc. @fabxc can you answer this?

Copy link
Member

Choose a reason for hiding this comment

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

I am sorry for the wrong answer here @stuartnelson3. Yes, changing to base16 is due to reducing the length. In addition we prevent someone of interpreting the fingerprint as an increasing integer, and we enforce exposing the fingerprint as a string in a JSON data structure.

@@ -81,6 +81,7 @@ type AlertBlock struct {
type APIAlert struct {
*model.Alert
Status types.AlertStatus `json:"status"`
ID string `json:"id"`
Copy link
Member

Choose a reason for hiding this comment

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

As the fingerprint is not really an id, I would prefer renaming this to HASH. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of hash since that's naming it after its implementation. I'm fine with id for now since the fingerprint is how we're identifying the alerts.

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if fingerprints are entirely unique, so thereby id might be misleading. @fabxc What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I do not think id is the right naming. An id would give it the notion of uniqueness and uniqueness over time. An alert can appear/disappear and even alerting rules get changed with or without the labels of the alert changing.

Since we all refer to it as this, why not fingerprint?

Copy link
Contributor

Choose a reason for hiding this comment

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

fingerprint is fine by me

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.

Just some small concerns.

@mxinden
Copy link
Member

mxinden commented Aug 14, 2017

@prymitive Do you have some time to finish this PR? In case you are too busy I can take over.

@prymitive
Copy link
Contributor Author

I should have, I just need to remind myself what needs to be done here, will update soon

Alert fingerprint is already provided as the value of status.inhibitedBy[] attribute that inhibited alerts have, but there's no way to get back to the alert that's inhibiting it as the fingerprint is not exposed.
@prymitive
Copy link
Contributor Author

Renamed ID->Fingerprint and using %x for printing instead of %d. I think that's all that was requested here

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.

@prymitive One more comment. I am sorry for the direction changes. Thanks a lot for bearing with me!

api/api.go Outdated
Alert: &a.Alert,
Status: status,
Receivers: receivers,
Fingerprint: fmt.Sprintf("%x", a.Fingerprint()),
Copy link
Member

Choose a reason for hiding this comment

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

@prymitive When I curl Alertmanager it does not expose the Fingerprint base16 encoded. I looked through the common package and found the String function. Would you mind changing it again to Fingerprint: a.Fingerprint().String(), then we are consistent across projects. I know there are plans to get rid of the commons repo in the future, but as we are using Fingerprint from the repo anyways, we might as well use Fingerprint.String(). Let me know if this sounds reasonable to you.

//cc @fabxc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, thanks

"fingerprint": "6f02aa263df152bc"

Status: status,
Alert: a,
Status: status,
Fingerprint: fmt.Sprintf("%x", a.Fingerprint()),
Copy link
Member

Choose a reason for hiding this comment

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

See comment in api/api.go in regards to using Fingerprint.String().

@prymitive
Copy link
Contributor Author

Anything else left here?

@prymitive
Copy link
Contributor Author

Should I squash those commits?

@mxinden
Copy link
Member

mxinden commented Aug 17, 2017

@prymitive No need to squash, can do so via Github. What is the change in the template/internal/deftmpl/bindata.go in your last commit?

@prymitive
Copy link
Contributor Author

Not sure, probably some dangling changes from building alertmanager locally for testing. Will nuke it.

@prymitive
Copy link
Contributor Author

It's gone now

@mxinden
Copy link
Member

mxinden commented Aug 18, 2017

@stuartnelson3 concern is addressed. I will merge here. Thanks @prymitive for the contribution and for the quick changes.

@mxinden mxinden merged commit 8e61ebf into prometheus:master Aug 18, 2017
iksaif pushed a commit to iksaif/alertmanager that referenced this pull request Sep 15, 2017
* Expose alert fingerprint in the API

Alert fingerprint is already provided as the value of status.inhibitedBy[] attribute that inhibited alerts have, but there's no way to get back to the alert that's inhibiting it as the fingerprint is not exposed.

* Expose alert fingerprint as ID in the list endpoint

* Rename ID to Fingerprint

* Use Fingerprint().String() in the API
@prymitive prymitive deleted the alert-fingerprint-api branch September 29, 2017 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants