prometheus/cmd/promtool
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
..
testdata promtool: add --ignore-unknown-fields 2025-01-15 11:34:28 +02:00
analyze.go enable errorf rule from perfsprint linter 2024-11-06 16:50:36 +01:00
analyze_test.go Parallelize tests in cmd/promtool/ 2024-11-08 21:54:08 +05:30
archive.go Use github.com/klauspost/compress for gzip and zlib 2024-02-22 17:08:15 +00:00
backfill.go model/textparse: Change parser interface Metric(...) string to Labels(...) (#16012) 2025-02-12 15:47:56 +00:00
backfill_test.go Parallelize tests in cmd/promtool/ 2024-11-08 21:54:08 +05:30
debug.go refactor (package cmd): move from github.com/pkg/errors to 'errors' and 'fmt' packages (#10733) 2022-05-24 16:58:59 +10:00
main.go rulefmt: support YAML aliases for Alert/Record/Expr (#14957) 2025-02-13 20:48:33 +11:00
main_test.go promtool: add --ignore-unknown-fields 2025-01-15 11:34:28 +02:00
metrics.go lint: Revamp our linting rules, mostly around doc comments 2024-08-22 17:36:11 +02:00
query.go Add analyze histograms command to promtool (#12331) 2024-01-10 17:32:36 +01:00
rules.go promtool: add --ignore-unknown-fields 2025-01-15 11:34:28 +02:00
rules_test.go Parallelize tests in cmd/promtool/ 2024-11-08 21:54:08 +05:30
sd.go Scraping: stop storing discovered labels (#15261) 2024-12-21 13:33:08 +00:00
sd_test.go Parallelize tests in cmd/promtool/ 2024-11-08 21:54:08 +05:30
tsdb.go promtool: support creating tsdb blocks from a pipe (#16011) 2025-02-13 13:03:31 +11:00
tsdb_posix_test.go promtool: support creating tsdb blocks from a pipe (#16011) 2025-02-13 13:03:31 +11:00
tsdb_test.go Parallelize tests in cmd/promtool/ 2024-11-08 21:54:08 +05:30
unittest.go promtool: add --ignore-unknown-fields 2025-01-15 11:34:28 +02:00
unittest_test.go promtool: add --ignore-unknown-fields 2025-01-15 11:34:28 +02:00