Skip to content

feat(alerts): configurable GeneratorURL templates (#736) - #798

Merged
jacksontj merged 1 commit into
masterfrom
feat/alert-generator-url-templates
Jul 3, 2026
Merged

feat(alerts): configurable GeneratorURL templates (#736)#798
jacksontj merged 1 commit into
masterfrom
feat/alert-generator-url-templates

Conversation

@jacksontj

Copy link
Copy Markdown
Owner

Fixes #736. Reimplements the approach from #737 on top of the current (post-Prometheus-3.5) master.

Problem

Promxy hardcodes the alert GeneratorURL to a link to its own graph page for the alert expression (matching upstream Prometheus). When promxy is the central evaluation point for many backends and operators triage alerts elsewhere — Grafana alerting, an incident manager, a per-tenant dashboard — that URL isn't useful, and it points at the wrong backend for series that originated in e.g. VictoriaMetrics.

Change

New opt-in pkg/alerttemplate renders the GeneratorURL from Go templates configured under promxy.alert_templates:

  • default — template used when no rule matches (inline body or a named reference)
  • named — reusable inline templates addressable from default/rules
  • rules — label-matched selectors, evaluated top-to-bottom, first match wins

Template data: .ExternalURL, .Expr, .AlertName, .Labels, .Annotations; plus urlquery / urlpath funcs.

Templates are compiled once on config (re)load behind a RWMutex and selected per-alert in sendAlerts. With no configuration, promxy falls back to the exact built-in URL, so default behavior is unchanged. An invalid template fails the config reload loudly and keeps the previous good config.

Scope vs. #737 / #736

Kept it minimal and close to upstream:

  • Dropped the template directory / .tmpl loader and the CLI flags — inline named templates cover the use cases in Configurable Alert GeneratorURL Templates #736 without filesystem/flag surface. Easy to add later if wanted.
  • Compiles templates once (not per-alert) and is race-free on reload.

Tests

  • pkg/alerttemplate — rule ordering, multi-label AND, named-vs-inline, data fields, render-error fallback, invalid-config rejection, bad-reload-keeps-previous-config.
  • pkg/configalert_templates YAML round-trips into a manager-accepted config.
  • Documented example in cmd/promxy/config.yaml.

Credit to @ramessesii2 for the original implementation and design in #737.

🤖 Generated with Claude Code

Promxy hardcodes the alert GeneratorURL to a link to its own graph page for
the alert expression, matching upstream Prometheus. When promxy is the central
evaluation point for many backends and operators triage alerts elsewhere
(Grafana alerting, an incident manager, a per-tenant dashboard), that URL is
not useful -- and points at the wrong backend for series that originated in
e.g. VictoriaMetrics.

Add an opt-in pkg/alerttemplate that renders the GeneratorURL from Go
templates configured under promxy.alert_templates: a default template, reusable
named templates, and label-matched rules (first match wins). Templates are
compiled once on config (re)load behind a RWMutex and selected per-alert in
sendAlerts; with no configuration promxy falls back to the exact built-in URL,
so default behavior is unchanged.

Reimplementation of the approach in #737, rebased onto the post-Prometheus-3.5
master and scoped down (no template directory / .tmpl loader, no CLI flags --
inline named templates cover the use cases in #736).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jacksontj
jacksontj force-pushed the feat/alert-generator-url-templates branch from 11636bf to 4c1dce4 Compare July 3, 2026 05:04
@jacksontj
jacksontj merged commit 012a7dd into master Jul 3, 2026
1 check passed
@jacksontj
jacksontj deleted the feat/alert-generator-url-templates branch July 3, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configurable Alert GeneratorURL Templates

1 participant