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

Don't notify resolved alerts if none were firing #1198

Merged
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions dispatch/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ func (ag *aggrGroup) stop() {
<-ag.done
}

// insert inserts the alert into the aggregation group. If the aggregation group
// is empty afterwards, it returns true.
// insert inserts the alert into the aggregation group.
func (ag *aggrGroup) insert(alert *types.Alert) {
ag.mtx.Lock()
defer ag.mtx.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion nflog/nflog.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Log interface {
// alert object.
Log(r *pb.Receiver, key string, firing, resolved []uint64) error

// Query the log along the given Paramteres.
// Query the log along the given Parameters.
//
// TODO(fabxc):
// - extend the interface by a `QueryOne` method?
Expand Down
9 changes: 9 additions & 0 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,15 @@ func (n *DedupStage) needsUpdate(entry *nflogpb.Entry, firing, resolved map[uint
return true, nil
}

// If the current alert group and last notification contain no firing alert
// and the resolved alerts are different, it means that some alerts have
// been fired and resolved during the last group_wait interval. In this
// case, there is no need to notify the receiver since it doesn't know
// about them.
if len(firing) == 0 && len(entry.FiringAlerts) == 0 {
return false, nil
}

if !entry.IsResolvedSubset(resolved) {
return true, nil
}
Expand Down
17 changes: 13 additions & 4 deletions notify/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ func TestDedupStageNeedsUpdate(t *testing.T) {
now := utcNow()

cases := []struct {
entry *nflogpb.Entry
firingAlerts map[uint64]struct{}
repeat time.Duration
entry *nflogpb.Entry
firingAlerts map[uint64]struct{}
resolvedAlerts map[uint64]struct{}
repeat time.Duration

res bool
resErr bool
Expand Down Expand Up @@ -135,6 +136,14 @@ func TestDedupStageNeedsUpdate(t *testing.T) {
repeat: 10 * time.Minute,
firingAlerts: alertHashSet(1, 2, 3),
res: true,
}, {
entry: &nflogpb.Entry{
ResolvedAlerts: []uint64{1, 2, 3},
Timestamp: now.Add(-11 * time.Minute),
},
repeat: 10 * time.Minute,
resolvedAlerts: alertHashSet(3, 4, 5),
res: false,
},
}
for i, c := range cases {
Expand All @@ -143,7 +152,7 @@ func TestDedupStageNeedsUpdate(t *testing.T) {
s := &DedupStage{
now: func() time.Time { return now },
}
ok, err := s.needsUpdate(c.entry, c.firingAlerts, nil, c.repeat)
ok, err := s.needsUpdate(c.entry, c.firingAlerts, c.resolvedAlerts, c.repeat)
if c.resErr {
require.Error(t, err)
} else {
Expand Down