Repository navigation
Description
Update 2026-11-26 (infra move): the Loki ruler and its network rule go to dan-petty/homelab.
This issue keeps the Prometheus recording rules and their promtool tests in k8s/devops/monitoring/prometheus-rules-values.yaml. The ruler settings (k8s/logging/) and the path from logging to Prometheus are the homelab follow-up, which also gives #4868 its ruler. The server already loads devops_cli_alerting_rules.yml, so a group there needs no new rule_files line.
Follow-up: dan-petty/homelab#293.
Part of #5164 (child 7).
Problem or Motivation
The job grades (#5164) must show on a dashboard and drive alerts. Today each panel of the row Roadmap Job Success scans 7 days of the Service log: one 7-day ratio query scanned about 414,000 lines on 2026-11-12. Prometheus has no series of the result lines, so an alert with a promtool test cannot read them, and no history of a ratio exists for the baselines of child 9.
- Loki (
k8s/logging/loki-values.yaml, Monolithic) has no ruler configuration. - Prometheus has
web.enable-remote-write-receiverand keeps 30 days. Its rules live inserverFilesofk8s/monitoring/prometheus-values.yaml.
Proposed Solution & Architectural Design
- Turn on the Loki ruler: local rule storage from a ConfigMap,
remote_writeto the Prometheus remote-write receiver, a WAL directory. Add the network policy fromloggingtomonitoring. - Loki recording rules, every 1 minute, over
[1m], on the base query ofjob-success.md(all streams, child 4):devops_cli:job_attempts:count1mbyroadmap_job,repo,version,success,first_pass,infra,failure_class.devops_cli:job_tokens:sum1m,devops_cli:job_seconds:sum1m,devops_cli:job_cost_usd_micros:sum1m,devops_cli:job_model_calls:sum1m,devops_cli:job_gh_requests:sum1m(sum_over_time ... | unwrap) byroadmap_job,repo,version,success.
- Prometheus recording rules, with promtool tests, for the windows 6h, 24h and 7d: attempts, successes and first-pass attempts with
infra=false, the infrastructure share,p, the Wilson 95% lower and upper bounds (sqrtarithmetic, z = 1.96), the point grade (100, 90, 80, 70, 60, 0; no series under 30 attempts), and tokens, seconds, cost, model calls and GitHub requests for each success. - The p90 and max of tokens and seconds stay Loki queries: a quantile does not come from 1-minute sums.
- A missed ruler evaluation loses 1 minute of counts. The alert
RoadmapJobResultsMissingof feat(roadmap): a dashboard and alerts for the pipeline #3655 finds a gap.
Target Subsystem
Product rules in k8s/devops/monitoring/. The Loki ruler is in dan-petty/homelab.
Existing Tool Considered
Loki ruler recording rules with remote write (Grafana Loki docs, "Recording rules") and Prometheus recording rules. Rejected: Grafana-managed recording rules (state in the Grafana database, no promtool); Sloth (#4709) for each job (one objective and burn windows; tens of attempts a day are too few); a Prometheus counter in the Service (job-success.md gives the reason). Cost: about 300,000 tokens, 6 hours elapsed.
Acceptance Criteria
promtool test rulespasses for each Prometheus rule, with a case at 22 of 25, a case under 30 attempts and a case with infrastructure cuts.- The Loki rules pass
lokitool rules lint(or the check that the Loki chart gives). - After the deploy,
devops_cli:job_attempts:count1mhas series in Prometheus, and the 24-hour sums equal the Lokicount_over_timeof the same window within 2%.
Dependencies
#5168 (the counts), #5169 (the streams).
Alternatives check of 2026-11-28: in-use.
The repository already uses this tool.
Tool: prometheus/prometheus (https://github.com/prometheus/prometheus), Apache-2.0, last activity 2026-11-28, maintained.
Reason: Searches on Prometheus rule testing were thin, but the facts confirm Prometheus, already the project's rules engine, supplies recording rules plus promtool unit tests that compute the ratio, Wilson bounds, grade and per-success series offline.
Covers:
- Recording rules compute ratio, Wilson bounds and grade in PromQL
- promtool test rules evaluates rule expressions against fixture series
- sqrt, comparison and aggregation support z = 1.96 arithmetic
Lacks:
- No log store or ruler to turn Service log lines into 1m series
- No quantile over raw samples, so p90 and max stay Loki queries
- No live parity check, a person compares sums with Loki counts
Proposed design
Problem statement
The Roadmap Job Success panels scan seven days of Loki logs for each ratio. Prometheus holds no series of the job result lines, so a promtool alert test cannot read the grades and child 9 has no ratio history. This change adds Prometheus recording rules and promtool tests in k8s/devops/monitoring/prometheus-rules-values.yaml. The rules compute the grade, the Wilson bounds and the per-success resources from the one-minute series that the homelab Loki ruler will remote-write. The live parity proof waits on dan-petty/homelab#293.
Acceptance criteria
Requirement: Prometheus ratio measures
The Prometheus recording rules SHALL compute attempts, successes, first-pass attempts, infrastructure share and p for 6h, 24h and 7d.
Scenario: Ratio measures for 22 of 25 attempts
- WHEN
promtool test rulesruns on the new Prometheus test file with a fixture of 22 successes in 25 attempts. - THEN Every case passes and the
pseries for each window is 0.88.
Requirement: Prometheus Wilson bounds
The Prometheus recording rules SHALL compute the Wilson 95% lower and upper bounds with z = 1.96 for 6h, 24h and 7d.
Scenario: Wilson bounds for 22 of 25 attempts
- WHEN
promtool test rulesruns on the new Prometheus test file with a fixture of 22 successes in 25 attempts. - THEN Every case passes and the Wilson lower and upper bounds for each window are 0.700 and 0.958, within 0.001.
Requirement: Prometheus point grade
The Prometheus recording rules SHALL compute the point grade in bands 100, 90, 80, 70, 60 and 0 for 6h, 24h and 7d.
Scenario: Grade of 22 successes in 25 attempts
- WHEN
promtool test rulesruns on the new Prometheus test file with a fixture of 22 successes in 25 attempts. - THEN Every case passes and the grade series for each window is 80.
Requirement: No grade under 30 attempts
The Prometheus grade rules SHALL record no grade series when the attempt count is fewer than 30.
Scenario: Under 30 attempts
- WHEN
promtool test rulesruns on the new Prometheus test file with a fixture of fewer than 30 attempts. - THEN The case passes and no grade series is present for that window.
Requirement: Infrastructure cuts leave the ratio
The Prometheus grade rules SHALL leave infra=true attempts out of the success ratio and the first-pass ratio, and SHALL count them in the infrastructure share.
Scenario: Infrastructure cut in the fixture
- WHEN
promtool test rulesruns on the new Prometheus test file with a fixture that holds infrastructure cuts. - THEN The case passes and the success ratio and grade use only
infra=falseattempts, while the infrastructure share counts the cut.
Requirement: Per-success resources
The Prometheus recording rules SHALL compute tokens, seconds, cost, model calls and GitHub requests for each success for 6h, 24h and 7d.
Scenario: Per-success resource values
- WHEN
promtool test rulesruns on the new Prometheus test file with a fixture of known sums and successes. - THEN Every case passes and each per-success series equals the fixture sum divided by the success count.
Requirement: Rule group in the loaded file
The new Prometheus recording rules SHALL be a group in serverFiles.devops_cli_alerting_rules.yml of k8s/devops/monitoring/prometheus-rules-values.yaml.
Scenario: Rendered rule file holds the group
- WHEN
uv run devops ci --check --only k8sruns. - THEN The check passes and the rendered
devops_cli_alerting_rules.ymlholds the new group with norule_fileschange.
Requirement: Pending a person after the merge
The deployed Prometheus SHALL hold the one-minute attempt series, and each 24-hour sum SHALL match the Loki count of the same window within 2%.
Scenario: Live parity after the homelab ruler deploys
- WHEN After
dan-petty/homelab#293deploys, a person runspromtool query instanton Prometheus andlogcli instant-queryon Loki for the same 24-hour window. - THEN Prometheus returns
devops_cli:job_attempts:count1mseries and each sum differs from the Loki count by no more than 2%.
Existing Tool Considered
The alternatives check in the issue body records an in-use verdict for grafana/loki (https://github.com/grafana/loki), an open, maintained tool. The check gives what Loki covers and lacks. This change does not build a log store or a ruler. It adds the Prometheus grade and resource recording rules and their promtool tests, which the check says Loki lacks. The homelab follow-up uses the Loki ruler and remote write to produce the one-minute input series. The change builds configuration and test files, not code.
Key questions
- Where do the new Prometheus recording rules go?: Add a new group to
serverFiles.devops_cli_alerting_rules.ymlink8s/devops/monitoring/prometheus-rules-values.yaml. Do not add arule_filesline, because the server already loads this file. (best practice) [sources: k8s/devops/monitoring/prometheus-rules-values.yaml]- Chosen: New group in devops_cli_alerting_rules.yml. The file says the server loads it and a group name is unique over both files.
- Rejected: New rule file with a rule_files line. The issue update says the server already loads the file and needs no new rule_files line.
- Rejected: Grafana-managed recording rules. The rules live in the Grafana database and promtool cannot test them.
- What grade formula and minimum attempt count do the Prometheus rules use?: The grade is the floor of the success ratio of attempts with no infrastructure cut. The bands are 100, 90, 80, 70, 60 and 0. It is 100 when each attempt is a first pass. Fewer than 30 attempts gives no grade. [sources: src/devops_cli/roadmap/job_grade.py:166, docs/roadmap/job-success.md, CONTEXT.md]
- How do the Prometheus rules prove the grade formula offline?: Use
promtool test ruleswith fixture series for 6h, 24h and 7d. Cover 22 successes of 25 attempts, fewer than 30 attempts, and infrastructure cuts. (best practice) [sources: k8s/devops/monitoring/prometheus-rules-values.yaml]- Chosen: promtool test rules. It evaluates the rule expressions against fixture series and the project keeps Prometheus rules in this file.
- Rejected: Python unit tests on query strings. They check text, not the result of the rule.
- Rejected: No rule tests. The issue requires a case for the grade formula and the edge cases.
- Should the p90 and max of tokens and seconds become Prometheus rules?: No. Keep the p90 and max as Loki queries. A quantile does not come from one-minute sums. (best practice) [sources: docs/roadmap/job-success.md]
- Chosen: Keep p90 and max in Loki. A quantile needs the raw samples, not one-minute sums.
- Rejected: Add Prometheus quantile rules. The one-minute sums have no histogram buckets for a quantile.
Fit
Fits in one pull request.
Suspected block
None.
Activity
dan-petty commentedon Nov 12, 2026
Both are children of #5164 and deal with job grades, but #5165 delivers a CLI command while this candidate delivers Prometheus and Loki recording rules.devops-cli-service commentedon Nov 17, 2026
Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.
devops-cli-service commentedon Nov 22, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (8)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 22, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
devops-cli-service commentedon Nov 28, 2026
The result in the alternatives block of the issue body changed. Before this check:
in-use, tool https://github.com/grafana/loki. A person decides what the new result means for the item.Searches (10)
Tools considered:
Searches run:
Sources: