Uh oh!
There was an error while loading. Please reload this page.
fix(rule): template configured label values - #10
Draft
0x91 wants to merge 1 commit into
Draft
Conversation
Configured rule labels were copied verbatim into alerts, so
vmalert-style templates in label values (e.g. "{{ $labels.team }}")
reached Alertmanager as literal strings; only annotations were
templated. vmalert templates both, and chalert documents itself as
vmalert-compatible, so any rule ported from vmalert that templates
a label silently broke.
Run configured label values containing "{{" through the same
normalize+template pipeline as annotations. The template sees the
query row's labels (before configured overrides) as .Labels,
matching vmalert; the "exported_" collision rule applies to the
rendered value. Values without "{{" take the previous verbatim
path. On parse or exec errors the raw string is kept and a warning
is logged, as for annotations.
Rendering happens in buildLabels, before hashLabels(), so the
rendered value is the alert identity for dedup and persisted state.
Rules already using templates in labels change identity on upgrade:
their literal-keyed alerts resolve and re-fire once with rendered
keys.
Also gofmt rule/conformance_test.go (pre-existing misalignment).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>0x91
marked this pull request as draft
July 14, 2026 15:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Configured rule labels are copied verbatim into alerts, so vmalert-style templates in label values (e.g.
fluidstack_grouping_key: "Foo | {{ $labels.team }}") reach Alertmanager as literal strings; only annotations are templated. vmalert templates both, and chalert documents itself as vmalert-compatible, so any rule ported from vmalert that templates a label silently breaks.I now run configured label values containing
{{through the same normalize+template pipeline the annotations use (legacy$labels/$valuerewrite,missingkey=zero). The template sees the query row's labels before configured overrides as.Labels, matching vmalert, and theexported_collision rule applies to the rendered value. Values without{{take the previous verbatim path with no template parse. On parse or exec errors the raw string is kept and a warning is logged, same as annotations; templating can never drop a label or fail the evaluation loop.Rendering happens in buildLabels, before hashLabels(), so the rendered value is the alert identity for dedup and the persisted state tables. Migration note: rules already (mis)using templates in labels change alert identity on upgrade — their literal-keyed alerts resolve and re-fire once with rendered keys. That is the intended fix.
Tested with new table-driven cases in rule_test.go: rendering from row labels (legacy and Go syntax), missing labels rendering empty rather than
<no value>, parse and exec errors falling back to the raw string with evaluation still succeeding, non-templated labels passing through byte-identical, the pre-override template context withexported_collision, and alert-ID equality between templated and literal label sets.go test ./...,go test -tags integration ./integration(ClickHouse testcontainer),go vet ./..., and gofmt are all clean. The gofmt hunk in rule/conformance_test.go fixes a pre-existing misalignment.