From ffa5e41bec36d8050bd2e9189159e8d83ea5f5f5 Mon Sep 17 00:00:00 2001 From: Pepe Cano <825430+ppcano@users.noreply.github.com> Date: Tue, 4 Nov 2025 17:56:41 +0100 Subject: [PATCH] docs(alerting): add note about invalid numeric identifiers in templates (#113269) --- .../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.