Expand the value of math and reduce expressions in annotations and labels (#36611)

* Expand the value of math and reduce expressions in annotations and labels

This commit makes it possible to use the values of reduce and math
expressions in annotations and labels via their RefIDs. It uses the
Stringer interface to ensure that "{{ $values.A }}" still prints the
value in decimal format while also making the labels for each RefID
available with "{{ $values.A.Labels }}" and the float64 value with
"{{ $values.A.Value }}"
This commit is contained in:
George Robinson
2021-07-15 13:10:56 +01:00
committed by GitHub
parent 421f5040ec
commit 456dac1303
9 changed files with 207 additions and 16 deletions
@@ -103,6 +103,15 @@ Labels are key value pairs that categorize or identify an alert. Labels are use
![Details section](/static/img/docs/alerting/unified/rule-edit-details-8-0.png 'Details section screenshot')
#### Template variables
The following template variables are available when expanding annotations and labels.
/ Name / Description /
/ ------- / --------------- /
/ $labels / Labels contains the labels from the query or condition. For example, `{{ $labels.instance }}` and `{{ $labels.job }}`. /
/ $values / Values contains the values of all reduce and math expressions that were evaluated for this alert rule. For example, `{{ $values.A }}`, `{{ $values.A.Labels }}` and `{{ $values.A.Value }}` where `A` is the `refID` of the expression. /
## Preview alerts
To evaluate the rule and see what alerts it would produce, click **Preview alerts**. It will display a list of alerts with state and value for each one.