Alerting: Fix use of > instead of >= when checking the For duration (#46011)

This commit is contained in:
George Robinson 2022-03-01 17:06:42 +00:00 committed by GitHub
parent 703d7deeda
commit 789cfc31e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -552,7 +552,7 @@ func TestProcessEvalResults(t *testing.T) {
},
},
},
expectedAnnotations: 2,
expectedAnnotations: 3,
expectedStates: map[string]*state.State{
`[["__alert_rule_namespace_uid__","test_namespace_uid"],["__alert_rule_uid__","test_alert_rule_uid_2"],["alertname","test_title"],["instance_label","test"],["label","test"]]`: {
AlertRuleUID: "test_alert_rule_uid_2",
@ -578,7 +578,7 @@ func TestProcessEvalResults(t *testing.T) {
Values: make(map[string]*float64),
},
},
StartsAt: evaluationTime,
StartsAt: evaluationTime.Add(20 * time.Second),
EndsAt: evaluationTime.Add(30 * time.Second).Add(state.ResendDelay * 3),
LastEvaluationTime: evaluationTime.Add(30 * time.Second),
EvaluationDuration: evaluationDuration,

View File

@ -64,7 +64,7 @@ func (a *State) resultAlerting(alertRule *ngModels.AlertRule, result eval.Result
case eval.Alerting:
a.setEndsAt(alertRule, result)
case eval.Pending:
if result.EvaluatedAt.Sub(a.StartsAt) > alertRule.For {
if result.EvaluatedAt.Sub(a.StartsAt) >= alertRule.For {
a.State = eval.Alerting
a.StartsAt = result.EvaluatedAt
a.setEndsAt(alertRule, result)