Fix incorrect start time for DatasourceError alerts (#59903)

This commit is contained in:
George Robinson 2022-12-06 18:44:06 +00:00 committed by GitHub
parent 7e339decfe
commit 3c249e1b99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -1868,7 +1868,7 @@ func TestProcessEvalResults(t *testing.T) {
Values: make(map[string]*float64),
},
},
StartsAt: evaluationTime.Add(20 * time.Second),
StartsAt: evaluationTime.Add(30 * time.Second),
EndsAt: evaluationTime.Add(50 * time.Second).Add(state.ResendDelay * 3),
LastEvaluationTime: evaluationTime.Add(50 * time.Second),
EvaluationDuration: evaluationDuration,

View File

@ -198,6 +198,11 @@ func (a *State) resultError(alertRule *models.AlertRule, result eval.Result) {
// is unavailable or queries against the datasource returns errors, and is
// then resolved as soon as the datasource is available and queries return
// without error
if a.State != execErrState {
// Set the start time if the state changes from Alerting to Error or from
// Error to Alerting
a.StartsAt = result.EvaluatedAt
}
a.State = execErrState
a.setEndsAt(alertRule, result)
case eval.Pending: