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

add groupKey to alerts/groups API endpoint #576

Merged
merged 1 commit into from
Dec 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions dispatch/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ type APIAlert struct {

// AlertGroup is a list of alert blocks grouped by the same label set.
type AlertGroup struct {
Labels model.LabelSet `json:"labels"`
Blocks []*AlertBlock `json:"blocks"`
Labels model.LabelSet `json:"labels"`
GroupKey uint64 `json:"groupKey"`
Blocks []*AlertBlock `json:"blocks"`
}

// AlertOverview is a representation of all active alerts in the system.
Expand All @@ -111,6 +112,7 @@ func (d *Dispatcher) Groups() AlertOverview {
alertGroup, ok := seen[ag.fingerprint()]
if !ok {
alertGroup = &AlertGroup{Labels: ag.labels}
alertGroup.GroupKey = ag.GroupKey()

seen[ag.fingerprint()] = alertGroup
overview = append(overview, alertGroup)
Expand Down Expand Up @@ -329,7 +331,7 @@ func (ag *aggrGroup) run(nf notifyFunc) {
ctx = notify.WithNow(ctx, now)

// Populate context with information needed along the pipeline.
ctx = notify.WithGroupKey(ctx, ag.labels.Fingerprint()^ag.routeFP)
ctx = notify.WithGroupKey(ctx, model.Fingerprint(ag.GroupKey()))
ctx = notify.WithGroupLabels(ctx, ag.labels)
ctx = notify.WithReceiverName(ctx, ag.opts.Receiver)
ctx = notify.WithRepeatInterval(ctx, ag.opts.RepeatInterval)
Expand Down Expand Up @@ -362,6 +364,10 @@ func (ag *aggrGroup) fingerprint() model.Fingerprint {
return ag.labels.Fingerprint()
}

func (ag *aggrGroup) GroupKey() uint64 {
return uint64(ag.labels.Fingerprint() ^ ag.routeFP)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe I'm missing something, but we can just keep the Fingerprint type here all the way no? Then we don't have to do any casting along the way.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be honest, I dislike the Fingerprint type with a passion – algorithm as well as naming. I'd like to get rid of it everywhere at some point and would rather not propagate it further.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking the same about the Fingerprint, but sticked with the grouopKey as it was already in the webhook. This is up to you guys :)

Copy link
Member

Choose a reason for hiding this comment

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

Not sticking to the "Fingerprint" type is fine by me as well as long as we stick with the same type. But in the context of this change I guess the way it is is fine then. Nevermind me here :)

}

// insert inserts the alert into the aggregation group. If the aggregation group
// is empty afterwards, it returns true.
func (ag *aggrGroup) insert(alert *types.Alert) {
Expand Down