prometheus/model/rulefmt/testdata/test_aliases.yaml
frazou 9b4c8f6be2
rulefmt: support YAML aliases for Alert/Record/Expr (#14957)
* rulefmt: add tests with YAML aliases for Alert/Record/Expr

Altough somewhat discouraged in favour of using proper configuration
management tools to generate full YAML, it can still be useful in some
situations to use YAML anchors/aliases in rules.

The current implementation is however confusing: aliases will work
everywhere except on the alert/record name and expr

This first commit adds (failing) tests to illustrate the issue, the next
one fixes it. The YAML test file is intentionally filled with anchors
and aliases. Although this is probably not representative of a real-world
use case (which would have less of them), it errs on the safer side.

Signed-off-by: François HORTA <fhorta@scaleway.com>

* rulefmt: support YAML aliases for Alert/Record/Expr

This fixes the use of YAML aliases in alert/recording rule names and
expressions. A side effect of this change is that the RuleNode YAML type is
no longer propagated deeper in the codebase, instead the generic Rule type
can now be used.

Signed-off-by: François HORTA <fhorta@scaleway.com>

* rulefmt: Add test for YAML merge combined with aliases

Currently this does work, but adding a test for the related
functionally here makes sense.

Signed-off-by: David Leadbeater <dgl@dgl.cx>

* rulefmt: Rebase to latest changes

Signed-off-by: David Leadbeater <dgl@dgl.cx>

---------

Signed-off-by: François HORTA <fhorta@scaleway.com>
Signed-off-by: David Leadbeater <dgl@dgl.cx>
Co-authored-by: David Leadbeater <dgl@dgl.cx>
2025-02-13 20:48:33 +11:00

58 lines
1.3 KiB
YAML

groups:
- name: my-group-name
interval: 30s # defaults to global interval
rules:
- &highalert
alert: &alertname HighAlert
expr: &expr |
sum without(instance) (rate(errors_total[5m]))
/
sum without(instance) (rate(requests_total[5m]))
for: 5m
labels:
severity: &severity critical
annotations:
description: &description "stuff's happening with {{ $.labels.service }}"
# Mix recording rules in the same list
- record: &recordname "new_metric"
expr: *expr
labels:
abc: edf
uvw: xyz
- alert: *alertname
expr: *expr
for: 5m
labels:
severity: *severity
annotations:
description: *description
- <<: *highalert
alert: HighAlert2
- name: my-another-name
interval: 30s # defaults to global interval
rules:
- alert: *alertname
expr: *expr
for: 5m
labels:
severity: *severity
annotations:
description: *description
- record: *recordname
expr: *expr
- alert: *alertname
expr: *expr
labels:
severity: *severity
annotations:
description: *description
- <<: *highalert
alert: HighAlert2