From a36d95abd338dac53ff36b4128bc09313b63ba7b Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Tue, 4 Nov 2025 11:15:21 -0600 Subject: [PATCH] [release-12.2.2] docs(alerting): add note about invalid numeric identifiers in templates (#113413) docs(alerting): add note about invalid numeric identifiers in templates (#113269) (cherry picked from commit ffa5e41bec36d8050bd2e9189159e8d83ea5f5f5) Co-authored-by: Pepe Cano <825430+ppcano@users.noreply.github.com> --- .../alerting/alerting-rules/templates/reference.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/sources/alerting/alerting-rules/templates/reference.md b/docs/sources/alerting/alerting-rules/templates/reference.md index d638b8e1d3c..b80aed07766 100644 --- a/docs/sources/alerting/alerting-rules/templates/reference.md +++ b/docs/sources/alerting/alerting-rules/templates/reference.md @@ -141,6 +141,20 @@ Alternatively, you can use the `index()` function to retrieve the query value: {{ index $values "B" }} CPU usage for {{ index $labels "instance" }} over the last 5 minutes. ``` +{{< admonition type="note" >}} + +Variable names that start with a number (for example, `1B`) are not [valid identifiers in Go templates](https://go.dev/ref/spec#Identifiers). + +To access a value or label whose key starts with a number, use the `index` function: + +``` +{{ index $values "1B" }} CPU usage for {{ index $labels "1instance" }} over the last 5 minutes. +``` + +Using `{{ $values.1B.Value }}` is invalid and causes the template code to render as plain text. + +{{< /admonition >}} + #### $value The `$value` variable is a string containing the labels and values of all instant queries; threshold, reduce and math expressions, and classic conditions in the alert rule.