diff --git a/pkg/services/ngalert/state/manager.go b/pkg/services/ngalert/state/manager.go index c55437c8502..d081614fd1a 100644 --- a/pkg/services/ngalert/state/manager.go +++ b/pkg/services/ngalert/state/manager.go @@ -557,6 +557,10 @@ func (st *Manager) processMissingSeriesStates(logger log.Logger, evaluatedAt tim } staleStatesCount++ + } else if s.State == eval.Alerting { + // We need to update EndsAt for the state so that it will not be resolved by the + // Alertmanager automatically. + s.Maintain(alertRule.IntervalSeconds, evaluatedAt) } record := StateTransition{ diff --git a/pkg/services/ngalert/state/manager_private_test.go b/pkg/services/ngalert/state/manager_private_test.go index e4ee2a27422..45ffba11fff 100644 --- a/pkg/services/ngalert/state/manager_private_test.go +++ b/pkg/services/ngalert/state/manager_private_test.go @@ -671,7 +671,7 @@ func TestProcessEvalResults_StateTransitions(t *testing.T) { State: eval.Alerting, LatestResult: newEvaluation(t1, eval.Alerting), StartsAt: t1, - EndsAt: t1.Add(ResendDelay * 4), + EndsAt: t2.Add(ResendDelay * 4), LastEvaluationTime: t1, LastSentAt: &t1, }, @@ -1037,7 +1037,7 @@ func TestProcessEvalResults_StateTransitions(t *testing.T) { State: eval.Alerting, LatestResult: newEvaluation(t1, eval.Alerting), StartsAt: t1, - EndsAt: t1.Add(ResendDelay * 4), + EndsAt: t2.Add(ResendDelay * 4), LastEvaluationTime: t1, LastSentAt: &t1, }, @@ -1113,7 +1113,7 @@ func TestProcessEvalResults_StateTransitions(t *testing.T) { State: eval.Alerting, LatestResult: newEvaluation(t1, eval.Alerting), StartsAt: t1, - EndsAt: t1.Add(ResendDelay * 4), + EndsAt: t3.Add(ResendDelay * 4), LastEvaluationTime: t1, LastSentAt: &t1, }, @@ -1647,7 +1647,7 @@ func TestProcessEvalResults_StateTransitions(t *testing.T) { State: eval.Alerting, LatestResult: newEvaluation(t1, eval.Alerting), StartsAt: t1, - EndsAt: t1.Add(ResendDelay * 4), + EndsAt: t2.Add(ResendDelay * 4), LastEvaluationTime: t1, LastSentAt: &t1, EvaluationDuration: time.Millisecond * 10, @@ -2327,7 +2327,7 @@ func TestProcessEvalResults_StateTransitions(t *testing.T) { State: eval.Alerting, LatestResult: newEvaluation(t1, eval.Alerting), StartsAt: t1, - EndsAt: t1.Add(ResendDelay * 4), + EndsAt: t2.Add(ResendDelay * 4), LastEvaluationTime: t1, LastSentAt: &t1, EvaluationDuration: time.Millisecond * 10, @@ -3063,7 +3063,7 @@ func TestProcessEvalResults_StateTransitions(t *testing.T) { State: eval.Alerting, LatestResult: newEvaluation(t1, eval.Alerting), StartsAt: t1, - EndsAt: t1.Add(ResendDelay * 4), + EndsAt: t2.Add(ResendDelay * 4), LastEvaluationTime: t1, LastSentAt: &t1, EvaluationDuration: time.Millisecond * 10,