Repository navigation
Description
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 --writeruns, thenuv run devops ci --check --only k8s. - THEN the
slo-runner-jobs-durationgroup aggregates each side byjob_nameand thek8scheck 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.yamlruns with twokube_job_status_completion_timeseries and twokube_job_status_start_timeseries for onejob_name. - THEN the case passes and the rule evaluation reports no
found duplicate series for the match grouperror.
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_nameand 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.yamlruns. - THEN the
slo-runner-jobs-durationcase 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-durationgroup?:k8s/devops/monitoring/slos/runner-jobs-duration.yamlis the Sloth spec. The renderersrc/devops_cli/prometheus/slo_rules.pywrites the group intok8s/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.maxkeeps the duration unchanged, whilesumdoubles 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.yamlproves it. Runpromtool 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. Thek8srow ofdevops cirefuses 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
dan-petty commentedon Nov 25, 2026
Both fix Prometheus rule correctness for series issues, but #2505 fixes increase() first-value gaps in alert rules while the candidate fixes duplicate-series join failures in recording rules.devops-cli-service commentedon Nov 25, 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 28, 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 29, 2026
Released in v0.244.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.244.0
devops-cli-service commentedon Nov 29, 2026
Live since 2026-11-29 05:10 UTC