@ -109,8 +109,9 @@ The following template variables are available when expanding annotations and la
| 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. |
| $labels | The labels from the query or condition. For example, `{{ $labels.instance }}` and `{{ $labels.job }}`. |
| $values | 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. |
| $value | The value string of the alert instance. For example, `[ var='A' labels={instance=foo} value=10 ]`. |
expectedError:errors.New("error executing template __alert_test: template: __alert_test:1:86: executing \"__alert_test\" at <$labels.instance>: map has no entry for key \"instance\""),
},{
name:"values are expanded into $values",
text:"{{ $values.A.Labels.instance }} has value {{ $values.A }}",
alertInstance:eval.Result{
Values:map[string]eval.NumberValueCapture{
"A":{
Var:"A",
Labels:data.Labels{"instance":"foo"},
Value:ptr.Float64(10),
},
},
},
expected:"foo has value 10",
},{
name:"missing label in $values returns error",
text:"{{ $values.A.Labels.instance }} has value {{ $values.A }}",
alertInstance:eval.Result{
Values:map[string]eval.NumberValueCapture{
"A":{
Var:"A",
Labels:data.Labels{},
Value:ptr.Float64(10),
},
},
},
expectedError:errors.New("error executing template __alert_test: template: __alert_test:1:86: executing \"__alert_test\" at <$values.A.Labels.instance>: map has no entry for key \"instance\""),