reminder: uses UpdatedAt to track state changes.
This commit is contained in:
@@ -53,8 +53,8 @@ func defaultShouldNotify(context *alerting.EvalContext, sendReminder bool, frequ
|
||||
|
||||
if context.PrevAlertState == context.Rule.State && sendReminder {
|
||||
// Do not notify if interval has not elapsed
|
||||
lastNotify := time.Unix(notificationState.SentAt, 0)
|
||||
if notificationState.SentAt != 0 && lastNotify.Add(frequency).After(time.Now()) {
|
||||
lastNotify := time.Unix(notificationState.UpdatedAt, 0)
|
||||
if notificationState.UpdatedAt != 0 && lastNotify.Add(frequency).After(time.Now()) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestShouldSendAlertNotification(t *testing.T) {
|
||||
prevState: m.AlertStateAlerting,
|
||||
frequency: time.Minute * 10,
|
||||
sendReminder: true,
|
||||
state: &m.AlertNotificationState{SentAt: tnow.Add(-time.Minute).Unix()},
|
||||
state: &m.AlertNotificationState{UpdatedAt: tnow.Add(-time.Minute).Unix()},
|
||||
|
||||
expect: true,
|
||||
},
|
||||
@@ -104,7 +104,7 @@ func TestShouldSendAlertNotification(t *testing.T) {
|
||||
prevState: m.AlertStateAlerting,
|
||||
frequency: time.Minute * 10,
|
||||
sendReminder: true,
|
||||
state: &m.AlertNotificationState{SentAt: tnow.Add(-time.Minute).Unix()},
|
||||
state: &m.AlertNotificationState{UpdatedAt: tnow.Add(-time.Minute).Unix()},
|
||||
|
||||
expect: false,
|
||||
},
|
||||
@@ -114,7 +114,7 @@ func TestShouldSendAlertNotification(t *testing.T) {
|
||||
prevState: m.AlertStateAlerting,
|
||||
frequency: time.Minute * 10,
|
||||
sendReminder: true,
|
||||
state: &m.AlertNotificationState{SentAt: tnow.Add(-11 * time.Minute).Unix()},
|
||||
state: &m.AlertNotificationState{UpdatedAt: tnow.Add(-11 * time.Minute).Unix()},
|
||||
|
||||
expect: true,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user