Commit 8fb997d9 by bergquist

should not notify when going from unknown to pending

parent 1958de72
...@@ -71,6 +71,11 @@ func (n *NotifierBase) ShouldNotify(ctx context.Context, context *alerting.EvalC ...@@ -71,6 +71,11 @@ func (n *NotifierBase) ShouldNotify(ctx context.Context, context *alerting.EvalC
return false return false
} }
// Do not notify when we become OK for the first time.
if context.PrevAlertState == models.AlertStateUnknown && context.Rule.State == models.AlertStatePending {
return false
}
// Do not notify when we become OK from pending // Do not notify when we become OK from pending
if context.PrevAlertState == models.AlertStatePending && context.Rule.State == models.AlertStateOK { if context.PrevAlertState == models.AlertStatePending && context.Rule.State == models.AlertStateOK {
return false return false
......
...@@ -29,7 +29,6 @@ func TestShouldSendAlertNotification(t *testing.T) { ...@@ -29,7 +29,6 @@ func TestShouldSendAlertNotification(t *testing.T) {
newState: m.AlertStateOK, newState: m.AlertStateOK,
prevState: m.AlertStatePending, prevState: m.AlertStatePending,
sendReminder: false, sendReminder: false,
state: &m.AlertNotificationState{},
expect: false, expect: false,
}, },
...@@ -38,7 +37,6 @@ func TestShouldSendAlertNotification(t *testing.T) { ...@@ -38,7 +37,6 @@ func TestShouldSendAlertNotification(t *testing.T) {
newState: m.AlertStateAlerting, newState: m.AlertStateAlerting,
prevState: m.AlertStateOK, prevState: m.AlertStateOK,
sendReminder: false, sendReminder: false,
state: &m.AlertNotificationState{},
expect: true, expect: true,
}, },
...@@ -47,7 +45,6 @@ func TestShouldSendAlertNotification(t *testing.T) { ...@@ -47,7 +45,6 @@ func TestShouldSendAlertNotification(t *testing.T) {
newState: m.AlertStatePending, newState: m.AlertStatePending,
prevState: m.AlertStateOK, prevState: m.AlertStateOK,
sendReminder: false, sendReminder: false,
state: &m.AlertNotificationState{},
expect: false, expect: false,
}, },
...@@ -56,7 +53,6 @@ func TestShouldSendAlertNotification(t *testing.T) { ...@@ -56,7 +53,6 @@ func TestShouldSendAlertNotification(t *testing.T) {
newState: m.AlertStateOK, newState: m.AlertStateOK,
prevState: m.AlertStateOK, prevState: m.AlertStateOK,
sendReminder: false, sendReminder: false,
state: &m.AlertNotificationState{},
expect: false, expect: false,
}, },
...@@ -65,7 +61,6 @@ func TestShouldSendAlertNotification(t *testing.T) { ...@@ -65,7 +61,6 @@ func TestShouldSendAlertNotification(t *testing.T) {
newState: m.AlertStateOK, newState: m.AlertStateOK,
prevState: m.AlertStateOK, prevState: m.AlertStateOK,
sendReminder: true, sendReminder: true,
state: &m.AlertNotificationState{},
expect: false, expect: false,
}, },
...@@ -74,7 +69,6 @@ func TestShouldSendAlertNotification(t *testing.T) { ...@@ -74,7 +69,6 @@ func TestShouldSendAlertNotification(t *testing.T) {
newState: m.AlertStateOK, newState: m.AlertStateOK,
prevState: m.AlertStateAlerting, prevState: m.AlertStateAlerting,
sendReminder: false, sendReminder: false,
state: &m.AlertNotificationState{},
expect: true, expect: true,
}, },
...@@ -94,7 +88,6 @@ func TestShouldSendAlertNotification(t *testing.T) { ...@@ -94,7 +88,6 @@ func TestShouldSendAlertNotification(t *testing.T) {
prevState: m.AlertStateAlerting, prevState: m.AlertStateAlerting,
frequency: time.Minute * 10, frequency: time.Minute * 10,
sendReminder: true, sendReminder: true,
state: &m.AlertNotificationState{},
expect: true, expect: true,
}, },
...@@ -138,7 +131,13 @@ func TestShouldSendAlertNotification(t *testing.T) { ...@@ -138,7 +131,13 @@ func TestShouldSendAlertNotification(t *testing.T) {
name: "unknown -> ok", name: "unknown -> ok",
prevState: m.AlertStateUnknown, prevState: m.AlertStateUnknown,
newState: m.AlertStateOK, newState: m.AlertStateOK,
state: &m.AlertNotificationState{},
expect: false,
},
{
name: "unknown -> pending",
prevState: m.AlertStateUnknown,
newState: m.AlertStatePending,
expect: false, expect: false,
}, },
...@@ -146,7 +145,6 @@ func TestShouldSendAlertNotification(t *testing.T) { ...@@ -146,7 +145,6 @@ func TestShouldSendAlertNotification(t *testing.T) {
name: "unknown -> alerting", name: "unknown -> alerting",
prevState: m.AlertStateUnknown, prevState: m.AlertStateUnknown,
newState: m.AlertStateAlerting, newState: m.AlertStateAlerting,
state: &m.AlertNotificationState{},
expect: true, expect: true,
}, },
...@@ -157,6 +155,10 @@ func TestShouldSendAlertNotification(t *testing.T) { ...@@ -157,6 +155,10 @@ func TestShouldSendAlertNotification(t *testing.T) {
State: tc.prevState, State: tc.prevState,
}) })
if tc.state == nil {
tc.state = &m.AlertNotificationState{}
}
evalContext.Rule.State = tc.newState evalContext.Rule.State = tc.newState
nb := &NotifierBase{SendReminder: tc.sendReminder, Frequency: tc.frequency} nb := &NotifierBase{SendReminder: tc.sendReminder, Frequency: tc.frequency}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment