-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
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 @fabxc is this new endpoing something that should be added? |
Is there a reason to hide fingerprints in the |
Makes sense to me, but waiting on a response from @fabxc |
Probably makes sense to add them to our API. We can make individual alerts gettable once there's a use case. |
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.
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.
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()), |
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.
Could we print this not as base10 but as base16 with %x
?
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.
Is this to reduce the length of the ID?
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.
No, it's just the base 16, with lower-case letters for a-f
. See https://golang.org/pkg/fmt/#hdr-Printing
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.
Right, I'm just wondering why you want base 16 instead of base 10
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.
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 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.
dispatch/dispatch.go
Outdated
@@ -81,6 +81,7 @@ type AlertBlock struct { | |||
type APIAlert struct { | |||
*model.Alert | |||
Status types.AlertStatus `json:"status"` | |||
ID string `json:"id"` |
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.
As the fingerprint is not really an id, I would prefer renaming this to HASH
. What do you think?
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 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.
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 am not sure if fingerprints are entirely unique, so thereby id
might be misleading. @fabxc What do you think?
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 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
?
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.
fingerprint is fine by me
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.
Just some small concerns.
@prymitive Do you have some time to finish this PR? In case you are too busy I can take over. |
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.
Renamed |
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.
@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()), |
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.
@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
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.
That makes sense, thanks
"fingerprint": "6f02aa263df152bc"
dispatch/dispatch.go
Outdated
Status: status, | ||
Alert: a, | ||
Status: status, | ||
Fingerprint: fmt.Sprintf("%x", a.Fingerprint()), |
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.
See comment in api/api.go
in regards to using Fingerprint.String()
.
Anything else left here? |
Should I squash those commits? |
@prymitive No need to squash, can do so via Github. What is the change in the |
Not sure, probably some dangling changes from building alertmanager locally for testing. Will nuke it. |
It's gone now |
@stuartnelson3 concern is addressed. I will merge here. Thanks @prymitive for the contribution and for the quick changes. |
* 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
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
@stuartnelson3The goal here is to be able to link back from inhibited to inhibiting alert based on the API response, which isn't currently doable.