From 46f377635ea41aa05969a3b71d30188f681c6427 Mon Sep 17 00:00:00 2001 From: Alexander Weaver Date: Mon, 16 Jan 2023 02:11:52 -0600 Subject: [PATCH] Alerting: Set error annotation on EvaluationError regardless of underlying error type (#61508) * Alerting: Set error annotation on EvaluationError regardless of underlying error type (#61506) Set error annotation regardless of underlying error type (cherry picked from commit b289b8ac6e84816ebdcd00b6d76b8cd60a7bc8e8) * Also cherrypick the nilcheck that got added prior to 9.4 --- pkg/services/ngalert/state/state.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/services/ngalert/state/state.go b/pkg/services/ngalert/state/state.go index 839dc014c2c..e39ae8de732 100644 --- a/pkg/services/ngalert/state/state.go +++ b/pkg/services/ngalert/state/state.go @@ -168,6 +168,9 @@ func (a *State) resultError(alertRule *models.AlertRule, result eval.Result) { case models.AlertingErrState: execErrState = eval.Alerting case models.ErrorErrState: + if a.Error != nil { + a.Annotations["Error"] = a.Error.Error() + } // If the evaluation failed because a query returned an error then // update the state with the Datasource UID as a label and the error // message as an annotation so other code can use this metadata to @@ -181,7 +184,6 @@ func (a *State) resultError(alertRule *models.AlertRule, result eval.Result) { break } } - a.Annotations["Error"] = queryError.Error() } execErrState = eval.Error case models.OkErrState: