mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix send resolved notifications (#54793)
This commit fixes a bug where we did not send resolved alerts to Alertmanager for resolved alert instances. This meant that resolved notifications did not have the annotations from the resolved state, and a result did not also have the resolved screenshot.
This commit is contained in:
parent
099d3cdf72
commit
5561f935e6
@ -174,13 +174,19 @@ func (a *State) resultNoData(alertRule *models.AlertRule, result eval.Result) {
|
||||
}
|
||||
|
||||
func (a *State) NeedsSending(resendDelay time.Duration) bool {
|
||||
if a.State == eval.Pending || a.State == eval.Normal && !a.Resolved {
|
||||
switch a.State {
|
||||
case eval.Pending:
|
||||
// We do not send notifications for pending states
|
||||
return false
|
||||
}
|
||||
// if LastSentAt is before or equal to LastEvaluationTime + resendDelay, send again
|
||||
case eval.Normal:
|
||||
// We should send a notification if the state is Normal because it was resolved
|
||||
return a.Resolved
|
||||
default:
|
||||
// We should send, and re-send notifications, each time LastSentAt is <= LastEvaluationTime + resendDelay
|
||||
nextSent := a.LastSentAt.Add(resendDelay)
|
||||
return nextSent.Before(a.LastEvaluationTime) || nextSent.Equal(a.LastEvaluationTime)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *State) Equals(b *State) bool {
|
||||
return a.AlertRuleUID == b.AlertRuleUID &&
|
||||
|
@ -71,25 +71,14 @@ func TestNeedsSending(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "state: normal + resolved sends after a minute",
|
||||
name: "state: normal + resolved should send without waiting",
|
||||
resendDelay: 1 * time.Minute,
|
||||
expected: true,
|
||||
testState: &State{
|
||||
State: eval.Normal,
|
||||
Resolved: true,
|
||||
LastEvaluationTime: evaluationTime,
|
||||
LastSentAt: evaluationTime.Add(-1 * time.Minute),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "state: normal + resolved does _not_ send after 30 seconds (before one minute)",
|
||||
resendDelay: 1 * time.Minute,
|
||||
expected: false,
|
||||
testState: &State{
|
||||
State: eval.Normal,
|
||||
Resolved: true,
|
||||
LastEvaluationTime: evaluationTime,
|
||||
LastSentAt: evaluationTime.Add(-30 * time.Second),
|
||||
LastSentAt: evaluationTime,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user