fix: render {{ $labels.X }} in alert summaries #62

Open
jared wants to merge 1 commits from fix-alert-label-templates into main
pull from: fix-alert-label-templates
Owner

The Ops alert list showed "PIA VPN tunnel is down on {{ $labels.job }}". The Grafana rule is fine: Grafana renders it as "…down on pia-vpn-transmission". The problem was in cmd_alerts, which took summary/description from the rule-level annotations (raw templates) and only substituted {{ $value }}.

Change (libexec/devdesk-ops.sh)

  • One active instance: use the annotations Grafana already rendered for that instance.
  • Several active instances: replace each {{ $labels.X }} with the distinct values across them (a-job, b-job), or ? if none has the label. {{ $value }} still comes from the first instance.
  • The description gets the same treatment. Before, it was never substituted.

Tested by running cmd_alerts against a fake /api/prometheus/grafana/api/v1/rules:

Case Result
1 firing PIA VPN tunnel is down on pia-vpn-transmission / No tun on 10.10.10.54:9101
2 firing + 1 Normal Down on a-job, b-job (?) value 1.5 / inst i1, i2 (Normal instance excluded)
description only Only desc for solo

bash -n and shellcheck are clean. The version number is not bumped.

🤖 Generated with Claude Code

https://claude.ai/code/session_012T5EBQfEofzrZbp3aTiMku

The Ops alert list showed **"PIA VPN tunnel is down on {{ $labels.job }}"**. The Grafana rule is fine: Grafana renders it as "…down on pia-vpn-transmission". The problem was in `cmd_alerts`, which took `summary`/`description` from the **rule-level** annotations (raw templates) and only substituted `{{ $value }}`. **Change (`libexec/devdesk-ops.sh`)** - **One active instance:** use the annotations Grafana already rendered for that instance. - **Several active instances:** replace each `{{ $labels.X }}` with the distinct values across them (`a-job, b-job`), or `?` if none has the label. `{{ $value }}` still comes from the first instance. - The description gets the same treatment. Before, it was never substituted. **Tested** by running `cmd_alerts` against a fake `/api/prometheus/grafana/api/v1/rules`: | Case | Result | |---|---| | 1 firing | `PIA VPN tunnel is down on pia-vpn-transmission` / `No tun on 10.10.10.54:9101` | | 2 firing + 1 Normal | `Down on a-job, b-job (?) value 1.5` / `inst i1, i2` (Normal instance excluded) | | description only | `Only desc for solo` | `bash -n` and `shellcheck` are clean. The version number is not bumped. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_012T5EBQfEofzrZbp3aTiMku
jared added 1 commit 2026-11-10 14:07:12 -05:00
fix: render {{ $labels.X }} in alert summaries
build-deb / Lint, test, package (pull_request) Successful in 3m56s
build-deb / Lint, test, package (push) Successful in 4m11s
build-deb / Deploy to CT 126 (pull_request) Skipped
build-deb / Notify on failure (pull_request) Skipped
build-deb / Deploy to CT 126 (push) Skipped
build-deb / Notify on failure (push) Skipped
af718955fe
The Ops alert list took summary/description from the rule-level
annotations, which are raw Go templates, and only substituted
{{ $value }}. A rule like "PIA VPN tunnel is down on {{ $labels.job }}"
showed the template literally.

- One active instance: use the annotations Grafana already rendered for it.
- Several: fill each {{ $labels.X }} with the distinct values across the
  active instances ("a-job, b-job"), "?" if none has the label.
- The description gets the same treatment (it was never substituted).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012T5EBQfEofzrZbp3aTiMku
All checks were successful
build-deb / Lint, test, package (pull_request) Successful in 3m56s
build-deb / Lint, test, package (push) Successful in 4m11s
build-deb / Deploy to CT 126 (pull_request) Skipped
build-deb / Notify on failure (pull_request) Skipped
build-deb / Deploy to CT 126 (push) Skipped
build-deb / Notify on failure (push) Skipped
You are not authorized to merge this pull request.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix-alert-label-templates:fix-alert-label-templates
git checkout fix-alert-label-templates
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/devdesk#62