Skip to content

Improve per-tenant alert generator URL template#7458

Open
CharlieTLe wants to merge 1 commit intocortexproject:masterfrom
CharlieTLe:809
Open

Improve per-tenant alert generator URL template#7458
CharlieTLe wants to merge 1 commit intocortexproject:masterfrom
CharlieTLe:809

Conversation

@CharlieTLe
Copy link
Copy Markdown
Member

@CharlieTLe CharlieTLe commented Apr 27, 2026

Summary

  • Add jsonEscape template function for generator URL templates that escapes strings for embedding inside JSON string values (e.g., "\"). This is needed when the expression is placed inside a JSON-encoded URL parameter like Grafana's panes, where bare double quotes in PromQL expressions like {job\!="foo"} would break the JSON structure.
  • Update runtime-config.yaml examples and docs to use {{ urlquery (jsonEscape .Expression) }}
  • Register jsonEscape stub in validation so templates using it pass parsing
  • Add AlwaysFiringWithQuotes demo alert to both tenants to exercise the escaping
  • Regenerate config docs via make doc

Test plan

  • Unit test for expression with double quotes verifies %5C%22 encoding
  • Template caching test verifies reuse and invalidation with new func map
  • Verified end-to-end with docker-compose: AlwaysFiringWithQuotes alert with count(up{job\!="nonexistent"} or vector(1)) produces correct generator URL with %5C%22

🤖 Generated with Claude Code

@dosubot dosubot Bot added component/rules Bits & bobs todo with rules and alerts: the ruler, config service etc. type/feature labels Apr 27, 2026
Add a jsonEscape function to the generator URL template func map that
escapes strings for embedding inside JSON string values (e.g., " → \").
This is needed when the expression is placed inside a JSON-encoded URL
parameter like Grafana's panes, where bare double quotes would break
the JSON structure.

- Register jsonEscape in template func map and validation
- Update runtime-config.yaml and docs to use jsonEscape
- Add test for expression with double quotes
- Add AlwaysFiringWithQuotes demo alert to both tenants
- Regenerate config docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Charlie Le <charlie_le@apple.com>
Copy link
Copy Markdown
Member

@SungJin1212 SungJin1212 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, can you add a changelog?

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 28, 2026
@friedrichg
Copy link
Copy Markdown
Member

@CharlieTLe just add it to the existing changelog for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/rules Bits & bobs todo with rules and alerts: the ruler, config service etc. lgtm This PR has been approved by a maintainer size/M type/feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants