From 360b022603f6a21872141e42ac1d1b69b5d2c52c Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Fri, 16 Sep 2022 16:19:10 +0200 Subject: [PATCH] vmalert: always re-evaluate Annotations (#3119) * vmalert: always re-evaluate Annotations Previously, Annotations were evaluated only: 1. On alert creating. 2. On alert's value change. This is premature optimization. It was assumed that since annotations could contain only text with alert's labels or value - there is no need in spending resources to re-compile Annotations. Later, template function `query` was added, which can execute arbitrary queries and return different results on every evaluation. So if it was used in annotations, it would be executed only on init or value change. Another case when optimization caused an issue - annotations hot reload. In this case, annotations of the active alert won't change even if Rule's annotations were changed. This fix enables Annotations re-evaluation on each iteration to resolve issues above. It would have some impact on performance, but it is unlikely it will be noticeable. Signed-off-by: hagen1778 * vmalert: add tp Changelog Signed-off-by: hagen1778 Signed-off-by: hagen1778 --- app/vmalert/alerting.go | 15 +++++---------- docs/CHANGELOG.md | 1 + 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/vmalert/alerting.go b/app/vmalert/alerting.go index c35acdce43..89b35deb35 100644 --- a/app/vmalert/alerting.go +++ b/app/vmalert/alerting.go @@ -324,16 +324,11 @@ func (ar *AlertingRule) Exec(ctx context.Context, ts time.Time, limit int) ([]pr a.ActiveAt = ts ar.logDebugf(ts, a, "INACTIVE => PENDING") } - if a.Value != m.Values[0] { - // update Value field with the latest value - a.Value = m.Values[0] - // and re-exec template since Value can be used - // in annotations - a.Annotations, err = a.ExecTemplate(qFn, ls.origin, ar.Annotations) - if err != nil { - curState.err = err - return nil, curState.err - } + a.Value = m.Values[0] + // re-exec template since Value or query can be used in annotations + a.Annotations, err = a.ExecTemplate(qFn, ls.origin, ar.Annotations) + if err != nil { + return nil, err } continue } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 61e248680c..8cb11f34a6 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -31,6 +31,7 @@ The following tip changes can be tested by building VictoriaMetrics components f * BUGFIX: [VictoriaMetrics cluster](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html): properly calculate query results at `vmselect`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3067). The issue has been introduced in [v1.81.0](https://docs.victoriametrics.com/CHANGELOG.html#v1810). * BUGFIX: [VictoriaMetrics cluster](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html): log clear error when multiple identical `-storageNode` command-line flags are passed to `vmselect` or to `vminsert`. Previously these components were crashed with cryptic panic `metric ... is already registered` in this case. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3076). * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix `RangeError: Maximum call stack size exceeded` error when the query returns too many data points at `Table` view. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3092/files). +* BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert.html): re-evaluate alert's annotations on each execution. Previously, annotations were evaluated only on alert's value change. See [this PR](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3119) for details. ## [v1.81.2](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.81.2)