Skip to content

test(observability): the alert rule files are checked, and their rule tests run, by a pinned promtool in the unit tests (#1492) - #1499

Merged
bpalermo merged 4 commits into
mainfrom
fix/1492-promtool-rule-tests
Oct 9, 2026
Merged

bpalermo merged 4 commits into
mainfrom
fix/1492-promtool-rule-tests

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Closes #1492

An agent wrote this pull request.

What

  • A pinned promtool. MODULE.bazel pins the official Prometheus 3.15.0 release archives for linux and darwin, amd64 and arm64, with the sha256 of each from the release's sha256sums.txt, the way oras and actionlint are pinned. //bazel/promtool selects the host's binary; bazel run //bazel/promtool -- <args> runs it from the caller's directory; //bazel/promtool:version_test fails until its EXPECTED moves with a bump.
  • A test macro. promtool_rules_test(name, rules, tests) in //bazel/promtool:defs.bzl runs promtool check rules on every rule file and promtool test rules on every rule test, reports every file, and fails if any failed.
  • The test. //:observability_rules_test applies it to docs/observability by glob: every .yml there is a rule file, except <name>_test.yml, which is a rule test. A file added there is picked up with no edit. It has no tag, so it is in the unit leg.
  • docs/observability/README.md says so at the top.

Decisions

  • The archive is the whole Prometheus release (about 110 MB), because Prometheus publishes promtool nowhere else. Only the host's archive is fetched. The alternative, building promtool from source, would put Prometheus and its dependencies into go.mod.
  • The test is in the root package. A BUILD.bazel in docs/observability would make that directory a package, and the root's glob(["docs/**/*.md"]) (the website's inputs) would stop seeing its two .md files.
  • Two ways the checker fails without promtool saying so: no rule file at all (a glob that stopped matching must not pass), and a .yml beside the files it was handed that it was not handed (a rule test listed as data and never run).
  • MODULE.bazel.lock does not change (bazel mod tidy is a no-op), so there is no lock conflict with another pull request.

Evidence

The rule files on main are valid. All three pass promtool check rules unchanged:

PASS  check rules docs/observability/agent-cni-alerts.yml
PASS  check rules docs/observability/mesh-dns-alerts.yml
PASS  check rules docs/observability/registrar-alerts.yml
promtool: 3 rule file(s) checked, 0 rule test file(s) run

There is no rule test on main yet, so on this branch the test rules half of //:observability_rules_test runs nothing. Two things stand in for it:

  1. //bazel/promtool:check_rules_test runs the checker on fixtures whose verdict is known (13 cases): a good rule file and its test pass; a rule file with an unclosed parenthesis fails check rules; a scrape config fails check rules; a rule test that expects an alert for a target that is up fails test rules; a failure does not stop the files after it; a .yml beside the given files that was not given fails, also when the files are given by bare name; no rule file fails. //bazel/promtool:fixtures_rules_test runs the good pair through the macro.
  2. I copied agent-pin-alerts.yml and agent-pin-alerts_test.yml from the open fix(agent,observability): the NACK counters are seeded, a cluster with no TLS published is not reported as the validation gap, and alert rules ship for the SAN-pin state (#1480, #1482, #1481) #1490 into the tree, ran the test, and removed them:
PASS  check rules docs/observability/agent-pin-alerts.yml
PASS  test rules docs/observability/agent-pin-alerts_test.yml
promtool: 4 rule file(s) checked, 1 rule test file(s) run

So #1490's rule test passes with promtool 3.15.0 (its header says 3.5.0), and it will be run by this target as soon as both are on main, in either order: the two pull requests merge cleanly (git merge-tree).

Red, then green. Each applied alone, seen to fail, restored:

Change What failed
an expression in mesh-dns-alerts.yml given an unclosed parenthesis //:observability_rules_test: FAIL check rules docs/observability/mesh-dns-alerts.yml ... unclosed left parenthesis
(with #1490's files copied in) the first for: of agent-pin-alerts.yml changed to 3h //:observability_rules_test: FAIL test rules docs/observability/agent-pin-alerts_test.yml, expected alerts, got none
(same) an expectation in agent-pin-alerts_test.yml broken //:observability_rules_test: FAIL test rules ...
the checker does not count a failure check_rules_test: the broken rule file exits 0
the checker does not run the rule tests check_rules_test: the failing rule test exits 0
the checker prints PASS without running check rules check_rules_test
the "no rule file" check removed check_rules_test
the "beside and not given" check removed check_rules_test
the macro lists the rule tests as data and does not pass them fixtures_rules_test: good_test.yml is a rule test next to the files given, and was not run
EXPECTED in version_test.sh changed version_test

Run locally: bazel test //bazel/promtool:all //:observability_rules_test //website:all //bazel/actionlint:all, bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //bazel/promtool:all //:observability_rules_test, make format-check, scripts/check-shell-lint.sh (the four new scripts are covered), bazel mod tidy (no change).

Unverified

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Copilot AI balanced review requested due to automatic review settings October 9, 2026 10:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The checker fails to detect omitted sibling files when the macro receives package-root file paths.

1 open finding
What changed in this PR

Adds pinned promtool validation for shipped Prometheus alert rules and rule tests.

Changes:

  • Pins Prometheus 3.15.0 binaries for supported host platforms.
  • Adds a reusable Bazel test macro and validation scripts.
  • Documents and tests the observability rule workflow.
File Description
MODULE.bazel Pins Prometheus release archives.
BUILD.bazel Adds the observability rules test.
docs/​observability/​README.md Documents rule validation.
bazel/​promtool/​BUILD.bazel Defines promtool targets and tests.
bazel/​promtool/​defs.bzl Adds the reusable test macro.
bazel/​promtool/​promtool.sh Wraps the pinned binary.
bazel/​promtool/​version_test.sh Verifies the pinned version.
bazel/​promtool/​check_rules.sh Runs rule and rule-test validation.
bazel/​promtool/​check_rules_test.sh Tests checker behavior.
bazel/​promtool/​testdata/​good.yml Adds a valid rule fixture.
bazel/​promtool/​testdata/​good_test.yml Adds a passing rule-test fixture.
bazel/​promtool/​testdata/​broken.yml Adds an invalid PromQL fixture.
bazel/​promtool/​testdata/​not_rules.yml Adds a non-rule YAML fixture.
bazel/​promtool/​testdata/​failing_test.yml Adds a failing rule-test fixture.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread bazel/promtool/check_rules.sh Resolved
… tests run, by a pinned promtool in the unit tests (#1492)

Nothing in the build ran promtool, so a rule file under docs/observability
was checked by hand only, and so would be the rule test #1490 adds.

- MODULE.bazel pins the official Prometheus 3.15.0 release archives (linux
  and darwin, amd64 and arm64, sha256 from the release's sha256sums.txt), the
  way oras and actionlint are pinned. //bazel/promtool selects the host's
  promtool; :version_test fails until its EXPECTED moves with a bump.
- promtool_rules_test (//bazel/promtool:defs.bzl) runs `promtool check rules`
  on every rule file and `promtool test rules` on every rule test. It fails on
  no rule file at all, and on a .yml that sits beside the files it was handed
  and was not handed.
- //:observability_rules_test applies it to docs/observability by glob: every
  .yml there is a rule file, except <name>_test.yml, which is a rule test.
  It is in the root package because a BUILD file in docs/observability would
  take that directory's .md files out of the website's inputs.
- //bazel/promtool:check_rules_test holds the checker to fixtures written to
  fail: an invalid expression, a file that is not a rule file, a rule test
  whose expectation does not hold.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Copilot AI balanced review requested due to automatic review settings October 9, 2026 10:45
@bpalermo
bpalermo force-pushed the fix/1492-promtool-rule-tests branch from a84bfd3 to f96da5a Compare October 9, 2026 10:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Ignored fixture setup failures can make negative checker tests pass for the wrong reason.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

Comment thread bazel/promtool/check_rules_test.sh Resolved
Copilot AI balanced review requested due to automatic review settings October 9, 2026 11:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The pinned artifacts, Bazel integration, checker behavior, documentation, and regression coverage are consistent and complete.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 9, 2026 11:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The pinned artifacts, Bazel integration, failure handling, documentation, and regression coverage are coherent with no unresolved correctness issues.

0 open findings

🧠 Review effort: Balanced

@bpalermo
bpalermo merged commit 34d5542 into main Oct 9, 2026
31 checks passed
@bpalermo
bpalermo deleted the fix/1492-promtool-rule-tests branch October 9, 2026 11:29
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.

ci: the alert rule files under docs/observability have no promtool test in the build

2 participants