Skip to content

Commit

Permalink
Merge pull request #576 from soupdiver/add_groupkey_to_alertgroups_ap…
Browse files Browse the repository at this point in the history
…i_endpoint

add groupKey to alerts/groups API endpoint
  • Loading branch information
fabxc authored Dec 7, 2016
2 parents 1fd0950 + 9fcdb47 commit 32f28d8
Showing 1 changed file with 9 additions and 3 deletions.
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)
}

// 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

0 comments on commit 32f28d8

Please sign in to comment.