Skip to content

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

Open

Description

@dan-petty

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

Kubernetes monitoring (k8s/logging/, k8s/monitoring/prometheus-values.yaml).

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-22: in-use.
The repository already uses this tool.
Tool: grafana/loki (https://github.com/grafana/loki), AGPL-3.0, last activity 2026-11-22, maintained.
Reason: Searches found no single tool that both reads the result-line logs and computes promtool-tested grades. Loki, already the cluster's log store, covers the ruler recording rules and remote write of the one-minute aggregates; the grade and Wilson rules stay Prometheus work.

Covers:

  • Ruler loads local recording rules from a ConfigMap
  • Recording rules aggregate the LogQL result-line query every minute
  • remote_write pushes the samples to the Prometheus receiver
  • Labels roadmap_job, repo, version, success and failure_class kept

Lacks:

  • No promtool test rules for the grade formula
  • Wilson 95% bounds and point grade need Prometheus rules
  • p90 and max of tokens and seconds need raw samples
  • No 6h, 24h and 7d ratio history without remote write

Proposed design

Problem statement

The Roadmap Job Success row scans seven days of Loki logs for each panel, about 414,000 lines for one ratio query on 2026-11-12. 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 records one-minute job result aggregates in Loki and remote-writes them to Prometheus, then computes the grades and Wilson bounds as Prometheus recording rules.

Acceptance criteria

Requirement: Loki ruler remote write

The Loki ruler SHALL load local rules from a ConfigMap, keep its WAL on a volume, and remote-write samples to the Prometheus remote-write receiver.

Scenario: Rendered Loki values enable the ruler

  • WHEN uv run devops ci --check --only k8s runs the Loki chart check.
  • THEN The check passes and the rendered Loki configuration has the ruler enabled with local rule storage, a WAL directory and a remote-write URL for Prometheus.

Requirement: Ruler network policy

The logging namespace SHALL reach the Prometheus remote-write receiver in monitoring.

Scenario: The network policy permits the remote write

  • WHEN uv run devops ci --check --only k8s runs.
  • THEN The check passes and the rendered network policy permits egress from logging pods to the Prometheus service port in monitoring.

Requirement: Loki one-minute rules

The Loki recording rules SHALL aggregate the all-streams result-line query every minute into the attempt count and five sum series, with roadmap_job, repo, version, success, first_pass, infra and failure_class labels on the attempt count and roadmap_job, repo, version and success on each sum.

Scenario: The rule group is valid

  • WHEN uv run devops ci --check --only k8s renders the Loki rules.
  • THEN The check passes and the group holds devops_cli:job_attempts:count1m, devops_cli:job_tokens:sum1m, devops_cli:job_seconds:sum1m, devops_cli:job_cost_usd_micros:sum1m, devops_cli:job_model_calls:sum1m and devops_cli:job_gh_requests:sum1m with the required labels.

Requirement: Prometheus grade rules

The Prometheus recording rules SHALL compute attempts, successes, first-pass attempts, infrastructure share, p, Wilson 95% bounds, and the point grade in bands 100, 90, 80, 70, 60 and 0 for 6h, 24h and 7d, with no grade series under 30 attempts.

Scenario: The grade rule cases pass

  • WHEN promtool test rules runs on the new Prometheus rule test files.
  • THEN Every case passes, including 22 successes of 25 attempts as grade 80, fewer than 30 attempts with no grade series, and infrastructure cuts left out of the success ratio.

Requirement: Prometheus per-success resources

The Prometheus recording rules SHALL compute tokens, seconds, cost, model calls and GitHub requests for each success.

Scenario: The resource rule cases pass

  • WHEN promtool test rules runs on the new Prometheus rule test files.
  • THEN Each case passes and each per-success series equals the fixture sum divided by the success count.

Requirement: Prometheus rule file registration

The Prometheus server SHALL load the new recording rule file from serverFiles.prometheus.yml.rule_files with the four chart defaults and devops_cli_alerting_rules.yml.

Scenario: The rendered Prometheus config lists the new rule file

  • WHEN uv run devops ci --check --only k8s runs the Prometheus chart check.
  • THEN The check passes and the rendered prometheus.yml rule_files lists the new recording rule file after devops_cli_alerting_rules.yml.

Requirement: Live Prometheus and Loki parity

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: The live parity check passes

  • WHEN The live check 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 proposal uses the Loki ruler and remote write for the one-minute aggregates. It uses Prometheus recording rules for the promtool-tested grade and Wilson rules, which Loki lacks. The change builds configuration, not code.

Key questions

  • Which component records the one-minute job result aggregates?: Use the Loki ruler with recording rules and remote write to Prometheus. Loki holds the result-line streams. Prometheus already accepts remote write. (best practice) [sources: k8s/logging/loki-values.yaml, k8s/monitoring/prometheus-values.yaml, docs/roadmap/job-success.md]
    • Chosen: Loki ruler and Prometheus rules. It reads the log lines where they live and writes samples to the existing receiver.
    • Rejected: Prometheus scrape of a Service counter. docs/roadmap/job-success.md rejects a counter in the Service.
    • Rejected: Grafana-managed recording rules. The rules live in the Grafana database and promtool cannot test them.
    • Rejected: Sloth SLO rules. One objective and burn windows need more attempts than tens a day.
  • How do the Prometheus grade rules prove the formula offline?: Use promtool test rules with fixture series for the 6h, 24h and 7d windows. The tests cover 22 of 25 attempts, fewer than 30 attempts, and infrastructure cuts. (best practice) [sources: k8s/monitoring/prometheus-values.yaml, docs/roadmap/job-success.md]
    • Chosen: promtool test rules. The project keeps Prometheus rule files in serverFiles and can test them with promtool.
    • Rejected: Python unit tests on query strings. They check text, not the result of the rule.
    • Rejected: No rule tests. The issue requires a test case for the grade formula.
  • What is the grade formula and the minimum attempt count?: The grade is the floor of the success ratio of attempts with no infrastructure cut, in bands 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]
  • What is the base query for the Loki recording rules?: The base query is the all-streams result-line query in docs/roadmap/job-success.md from child 4. The rules aggregate it over [1m] and keep roadmap_job, repo, version, success, first_pass, infra and failure_class. [sources: docs/roadmap/job-success.md, src/devops_cli/roadmap/job_result.py]
  • 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 issue records no histogram buckets for a quantile rule.
  • Where does the Prometheus server load the new recording rules?: Add the new recording rule file to serverFiles.prometheus.yml.rule_files. Keep the four chart defaults and devops_cli_alerting_rules.yml. [sources: k8s/monitoring/prometheus-values.yaml]

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.

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