Skip to content

feat(monitoring): record job grades from result lines in Prometheus #5172

Open

Description

@dan-petty

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-receiver and keeps 30 days. Its rules live in serverFiles of k8s/monitoring/prometheus-values.yaml.

Proposed Solution & Architectural Design

  • Turn on the Loki ruler: local rule storage from a ConfigMap, remote_write to the Prometheus remote-write receiver, a WAL directory. Add the network policy from logging to monitoring.
  • Loki recording rules, every 1 minute, over [1m], on the base query of job-success.md (all streams, child 4):
    • devops_cli:job_attempts:count1m by roadmap_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) by roadmap_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 (sqrt arithmetic, 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 RoadmapJobResultsMissing of 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 rules passes 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:count1m has series in Prometheus, and the 24-hour sums equal the Loki count_over_time of 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 rules runs on the new Prometheus test file with a fixture of 22 successes in 25 attempts.
  • THEN Every case passes and the p series 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 rules runs 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 rules runs 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 rules runs 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 rules runs 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=false attempts, 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 rules runs 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 k8s runs.
  • THEN The check passes and the rendered devops_cli_alerting_rules.yml holds the new group with no rule_files change.

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#293 deploys, a person runs promtool query instant on Prometheus and logcli instant-query on Loki for the same 24-hour window.
  • THEN Prometheus returns devops_cli:job_attempts:count1m series 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.yml in k8s/devops/monitoring/prometheus-rules-values.yaml. Do not add a rule_files line, 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 rules with 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.

Dependencies

#5168, #5169

Activity

  1. added
    source/agent
    type/feature
    scope/monitoring
    status/new
    value/medium
    effort/high
    on Nov 12, 2026
  2. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 12, 2026
  4. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.

  5. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    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:

    • Loki ruler recording rules remote_write Prometheus, results: 5
    • Prometheus recording rules Wilson score success ratio from logs SLI, results: 5
    • Grafana Loki recording rules ruler remote_write documentation, results: 5
    • google mtail extract Prometheus metrics from log lines, results: 5
    • Loki ruler recording rules, results: 5
    • promtool test rules recording rule unit test, results: 5
    • loki ruler remote_write url wal recording rule config, results: 5
    • mtail github, results: 5

    Sources:

  6. added
    status/ready
    and removed
    status/new
    on Nov 22, 2026
  7. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  8. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    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:

    • Loki ruler recording rules remote_write Prometheus, results: 5
    • Sloth SLO recording rules Prometheus burn rate, results: 5
    • Prometheus recording rules promtool test rules unit testing, results: 5
    • promtool test rules documentation prometheus unit test recording rule, results: 5
    • github prometheus prometheus promtool, results: 5
    • grafana loki recording rules ruler configuration, results: 5
    • prometheus recording rules rules yml documentation, results: 5
    • prometheus.io docs configuration recording rules, results: 5
    • prometheus.io docs promtool unit testing rules, results: 5
    • promtool test rules yaml example promql_expr_test, results: 5

    Sources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p2-mediumscope/monitoringsource/agentstatus/readytype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions