Skip to content

fix(monitoring): runner Job duration rules fail on duplicate series #7247

Done

Description

@dan-petty

Bug

The recording rules of group slo-runner-jobs-duration (k8s/devops/monitoring/prometheus-rules-values.yaml) join kube_job_status_completion_time and kube_job_status_start_time with on (job_name). When Prometheus holds two series of one Job, for example from two kube-state-metrics, the evaluation fails with found duplicate series for the match group and PrometheusRuleEvaluationFailures fires.

Evidence

On 2026-11-25 a second kube-state-metrics was left over in the cluster until the prune of #5134 step 13. The rule still failed after the prune, because the 3-day window holds the old series. It clears when that window passes.

Expected

The rules aggregate each side by job_name before the join, so a second series of one Job does not fail the evaluation. A promtool case holds two series of one Job.

Alternatives check of 2026-11-25: in-use.
The repository already uses this tool.
Tool: prometheus/prometheus (https://github.com/prometheus/prometheus), Apache-2.0, last activity 2026-11-25, maintained.
Reason: Searches found no tool that rewrites the join; promtool, which the issue names, unit-tests rule files with two series of one Job and fails on the duplicate-series error, but the sum by (job_name) aggregation stays a hand edit.

Covers:

  • Rule unit tests with fixture series and expected output
  • Fails the test on duplicate series for a match group
  • Offline validation of rule files and expressions

Lacks:

  • No rewrite of the join to aggregate by job_name
  • No automatic detection of many-to-many joins in existing rules
  • No fix suggestion for the offending expression

Proposed design

Problem statement

The slo-runner-jobs-duration rules come from the Sloth spec k8s/devops/monitoring/slos/runner-jobs-duration.yaml and render into k8s/devops/monitoring/prometheus-rules-values.yaml. They join the Job start and completion gauges with on (job_name). Two series of one Job make the join fail with found duplicate series for the match group, and PrometheusRuleEvaluationFailures fires. The fix collapses each side to one series for each job_name before the join. A promtool case holds two series of one Job.

Acceptance criteria

Requirement: Sloth spec aggregates each side by job_name

The Sloth spec k8s/devops/monitoring/slos/runner-jobs-duration.yaml SHALL aggregate each side of the Job duration join by job_name before the arithmetic.

Scenario: The spec renders an aggregated join

  • WHEN the render command uv run python src/devops_cli/prometheus/slo_rules.py k8s/devops/monitoring/slos k8s/devops/monitoring/prometheus-rules-values.yaml --write runs, then uv run devops ci --check --only k8s.
  • THEN the slo-runner-jobs-duration group aggregates each side by job_name and the k8s check passes.

Requirement: Duplicate series do not fail the duration rules

The rendered slo-runner-jobs-duration rules SHALL pass the promtool case with two series of one Job.

Scenario: Two series of one Job

  • WHEN promtool test rules tests/fixtures/prometheus_rules/slo_runner_jobs_duration_tests.yaml runs with two kube_job_status_completion_time series and two kube_job_status_start_time series for one job_name.
  • THEN the case passes and the rule evaluation reports no found duplicate series for the match group error.

Requirement: One duration series for each Job

The duration rule SHALL produce one series for each job_name when duplicate series of that Job exist.

Scenario: Duplicate gauges collapse to one value

  • WHEN the promtool case holds two series of one Job on each side of the join with the same timestamp values.
  • THEN the rule output has one series for that job_name and its duration equals the completion time minus the start time.

Requirement: Promtool case covers two series of one Job

The promtool case file tests/fixtures/prometheus_rules/slo_runner_jobs_duration_tests.yaml MUST hold two series of one Job for each joined metric.

Scenario: Case file holds the duplicate series

  • WHEN promtool test rules tests/fixtures/prometheus_rules/slo_runner_jobs_duration_tests.yaml runs.
  • THEN the slo-runner-jobs-duration case includes two series of one Job on each side of the join and passes.

Existing Tool Considered

prometheus/prometheus (in-use): the alternatives block in the issue body records the verdict, the tool and what it covers and lacks. The proposal edits the Sloth spec and uses promtool to prove the duplicate-series case. It keeps the max by (job_name) hand edit because the tool has no rewrite of the join.

Key questions

  • Which file is the source of the slo-runner-jobs-duration group?: k8s/devops/monitoring/slos/runner-jobs-duration.yaml is the Sloth spec. The renderer src/devops_cli/prometheus/slo_rules.py writes the group into k8s/devops/monitoring/prometheus-rules-values.yaml. [sources: k8s/devops/monitoring/slos/runner-jobs-duration.yaml, src/devops_cli/prometheus/slo_rules.py, k8s/devops/monitoring/prometheus-rules-values.yaml]
  • Which aggregation should collapse duplicate series on each side of the Job duration join?: Use max by (job_name) on each side before the subtraction. The joined metrics are gauges of timestamps, so duplicate series of one Job carry the same value. max keeps the duration unchanged, while sum doubles it. (best practice) [sources: k8s/devops/monitoring/slos/runner-jobs-duration.yaml]
    • Chosen: max by (job_name). Collapses duplicate gauge series and keeps the timestamp value for the duration calculation.
    • Rejected: sum by (job_name). Collapses duplicate series but doubles each timestamp, so the duration doubles.
    • Rejected: min by (job_name). Collapses duplicate series but can select an older timestamp if the series disagree.
  • Which offline check proves the duplicate-series case?: The promtool case file tests/fixtures/prometheus_rules/slo_runner_jobs_duration_tests.yaml proves it. Run promtool test rules tests/fixtures/prometheus_rules/slo_runner_jobs_duration_tests.yaml; the case fails on duplicate series before the fix and passes after it. The k8s row of devops ci refuses a rule file that is not the render. [sources: tests/fixtures/prometheus_rules/slo_runner_jobs_duration_tests.yaml, tests/prometheus/test_k8s_monitoring_alerting.py, k8s/devops/monitoring/prometheus-rules-values.yaml]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    source/agent
    status/new
    value/medium
    effort/low
    on Nov 25, 2026
  2. dan-petty commented on Nov 25, 2026

    @dan-petty
    OwnerAuthor
  3. added
    scope/monitoring
    priority/p2-medium
    on Nov 25, 2026
  4. devops-cli-service commented on Nov 25, 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:

    • promtool unit test recording rule duplicate series same job_name, results: 5
    • Prometheus recording rule "found duplicate series for the match group" aggregate by label before join, results: 5
    • Prometheus recording rules best practices aggregation duplicate series join, results: 5
    • promtool test rules prometheus unit testing recording rules github, results: 5
    • pint promql vector-matching check duplicate series on() prometheus rule linter, results: 5
    • Cloudflare pint prometheus linting tool github, results: 5
    • promtool, results: 5
    • promtool test rules unit testing rules documentation prometheus.io, results: 5

    Sources:

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

    @devops-cli-service
    Contributor

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

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
  9. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 05:10 UTC

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/lowpriority/p2-mediumscope/monitoringsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions