Repository navigation
Description
Problem
devops-cli renders Prometheus SLO rules with its own copy of Sloth.
src/devops_cli/prometheus/slo_rules.pyhas 348 lines and 13 tests (commitd0bc3dffa).- Its docstring (
:1-8) says that the runner image has nosloth, "so this module renders theprometheus/v1format of a spec itself". - The specs are in
k8s/devops/monitoring/slos/. The rules go tok8s/devops/monitoring/prometheus-rules-values.yaml. - feat(monitoring): define the Service SLOs in a Sloth spec #4709 chose Sloth v0.16.0 and its
prometheus/v1format. The module copies that format.
No bug is filed yet. But the module copies a tool exactly, so it drifts when Sloth changes.
Change
Render the rules with sloth generate.
- Tool: Sloth (https://github.com/slok/sloth), Apache-2.0, v0.16.0 (2026-04-04).
- Add the
slothbinary to the devtools image. - Render each spec in
k8s/devops/monitoring/slos/withsloth generate -i <spec> -o <file>. src/devops_cli/k8s/catalog.py:31importsSLO_WINDOW_DAYS,SloSpecandload_slo_specs. Keep only a small read of the spec YAML for the catalog.
Delete: the rule render of slo_rules.py and its tests.
Existing tool considered
- Sloth (Apache-2.0, v0.16.0). It covers the validation of a spec and the render of the recording rules and the alert rules. It does not list the SLOs for the catalog. The catalog reads the spec files.
Done when
slo_rules.pyrenders no rule. Only a spec read for the catalog stays, or the module is deleted.- The devtools image has
sloth. - CI renders each spec with
sloth generate, and fails when the committed rules differ from its output.
Source
Alternatives check of 2026-11-28: not-applicable.
Class: refactor, no model call.
Tool: none found.
Proposed design
Problem statement
devops-cli keeps a 348-line copy of Sloth's prometheus/v1 rule renderer in src/devops_cli/prometheus/slo_rules.py, and the copy drifts when Sloth changes. The change deletes the copy, renders each spec in k8s/devops/monitoring/slos/ with sloth generate, keeps a small spec read for the catalog, and makes the k8s row of devops ci compare the committed rules with the Sloth output. The devtools image must ship the sloth binary before the check can run.
Acceptance criteria
Requirement: Committed SLO rules equal the Sloth render
The SLO rule groups between the # BEGIN slo-rules and # END slo-rules markers of k8s/devops/monitoring/prometheus-rules-values.yaml SHALL equal the groups that the render writes from sloth generate for the specs in k8s/devops/monitoring/slos/.
Scenario: A changed spec fails the k8s row
- WHEN A spec in
k8s/devops/monitoring/slos/changes anduv run devops ci --check --only k8sruns without a new render. - THEN The command exits non-zero and prints the difference between the committed groups and the rendered groups.
Requirement: The k8s row renders every spec with Sloth
The k8s row of devops ci MUST run sloth generate on each SLO spec and compare its groups with the committed values file.
Scenario: Committed rules pass
- WHEN
uv run devops ci --check --only k8sruns with the committed groups equal to the render. - THEN The command exits 0 and reports the k8s check as passed.
Requirement: Sloth refuses an invalid spec
The k8s row MUST fail when sloth generate refuses a spec in k8s/devops/monitoring/slos/.
Scenario: Invalid spec fails
- WHEN A spec is invalid and
uv run devops ci --check --only k8sruns. - THEN The command exits non-zero and prints the Sloth error for that spec.
Requirement: Generated rules keep the alert labels
Each Sloth spec MUST set the service and slo labels and the critical page and warning ticket severity labels, so the generated rules keep the labels that the alerts and the dashboards select.
Scenario: A spec without the labels fails
- WHEN A spec omits
service,sloor aseveritylabel anduv run devops ci --check --only k8sruns. - THEN The command exits non-zero and names the label that the spec lacks.
Requirement: The low-sample guard stays
The rendered SLO rules MUST keep the 20-event guard of the long window, so an SLO with fewer than 20 events in that window fires no alert.
Scenario: Ten requests in ten minutes fire no alert
- WHEN
uv run devops ci test tests/prometheus/test_k8s_monitoring_alerting.pyruns the promtool cases of the four SLO groups. - THEN The case of ten requests in ten minutes stays quiet for each of the four burn-rate alerts.
Requirement: Runner tool table lists Sloth
RUNNER_TOOLS in src/devops_cli/roadmap/runner_tools.py MUST list sloth as a devtools tool whose check is sloth --version.
Scenario: The table holds Sloth
- WHEN A test reads
RUNNER_TOOLS. - THEN It finds
slothwith sourceToolSource.DEVTOOLSand check('sloth', '--version').
Requirement: Runner image provides Sloth
The runner image MUST provide the sloth binary on PATH from the pinned devtools image.
Scenario: The image smoke test proves Sloth
- WHEN The runner image smoke test runs
python -m devops_cli.roadmap.runner_toolson the built image. - THEN The command exits 0 and reports the tools ready, and it fails with the missing-tool message when the pinned devtools image holds no
sloth.
Requirement: Catalog lists SLOs from the specs
src/devops_cli/k8s/catalog.py MUST list each SLO from the spec YAML without a rule renderer.
Scenario: Catalog reads the specs
- WHEN
load_slo_specsreadsk8s/devops/monitoring/slos/and the catalog builds its SLO rows. - THEN Each spec gives one row with its service, name, objective, error budget, 28-day window, SLI and description.
Requirement: The rule copy is gone
The repository MUST NOT keep a copy of Sloth's rule render: no burn-rate table, no record-name table and no function that builds rule groups itself.
Scenario: No duplicate render path
- WHEN A test imports
devops_cli.prometheusand checks the package. - THEN No module exports
SLO_BURN_RATE_ROWS,SLO_RECORD_NAMESorrender_slo_groups, anddevops_cli.prometheus.slo_rulesdoes not exist.
Existing Tool Considered
Sloth v0.16.0 (Apache-2.0) is the open, maintained, single-binary SLO generator: sloth generate validates each prometheus/v1 spec and writes the SLI recording rules and the multi-window, multi-burn-rate alerts. It does not list SLOs for the catalog and does not splice its groups into the Helm values file, so a thin render wrapper (run sloth generate per spec, keep the project's 20-event guard, replace the text between the # BEGIN slo-rules and # END slo-rules markers) and the small spec read stay. The copy it replaces cost about 12k tokens to build, 3k tokens a year to keep and repair, and 1 day elapsed (#4709).
Key questions
- Which tool generates the SLO rule groups?: Sloth v0.16.0 with
sloth generate, run once for each spec ink8s/devops/monitoring/slos/. Sloth is open, actively maintained and a single binary, and itsgeneratecommand validates the spec as it writes the recording rules and the multi-window, multi-burn-rate alerts (fetched 2026-11-28). Keep no in-repo rule renderer; feat(monitoring): define the Service SLOs in a Sloth spec #4709 already chose this version and format. (best practice) [sources: openspec/changes/archive/2026-11-24-4709-define-the-service-slos-in-a/proposal.md:56, docs/guidelines/sre.md:59, https://github.com/slok/sloth]- Rejected: Keep the in-repo renderer. It copies Sloth's templates and drifts when Sloth changes; feat(monitoring): define the Service SLOs in a Sloth spec #4709 measured about 12k tokens to build, 3k tokens a year to keep and repair, and 1 day elapsed.
- Chosen: Use
sloth generate. Sloth validates the spec and writes the recording rules and the burn-rate alerts, so the project keeps no rule template.
- How does the catalog get its SLO list?: Keep a small YAML read. Move
SloSpec,load_slo_specsandSLO_WINDOW_DAYStosrc/devops_cli/prometheus/slo_specs.py, drop thegroupingproperty and the rule-only fields, and keep the import atsrc/devops_cli/k8s/catalog.py:31. Do not parse Sloth output: it holds nodescriptionand the spec is the source of truth. (best practice) [sources: src/devops_cli/k8s/catalog.py:31, src/devops_cli/k8s/catalog.py:854, src/devops_cli/prometheus/slo_rules.py:117, src/devops_cli/prometheus/slo_rules.py:192]- Chosen: Read the spec YAML. The catalog needs the service, name, objective, error budget, window, SLI and description, and Sloth does not list SLOs.
- Rejected: Read the generated rules. The rules do not hold the spec description and the spec is the source of truth.
- Rejected: Drop the catalog SLO list. The catalog imports the list at
src/devops_cli/k8s/catalog.py:31and builds its rows at:854.
- Where do the Sloth invocation and the marker splice live?: Delete
src/devops_cli/prometheus/slo_rules.py. Addsrc/devops_cli/prometheus/slo_specs.pyfor the catalog read andsrc/devops_cli/prometheus/slo_render.pyfor the render:generate_slo_groupsrunssloth generate -i <spec>for each spec and returns the parsedgroups,write_slo_groupsreplaces only the text between the markers, and a__main__with--writelets a person regenerate. Thek8scheck imports the render module. (best practice) [sources: src/devops_cli/prometheus/slo_rules.py:40-41, src/devops_cli/prometheus/slo_rules.py:314, tests/gate/k8s_checks/slo_rules.py:54-57, k8s/devops/monitoring/prometheus-rules-values.yaml:544]- Rejected: Keep the wrapper in
slo_rules.py. The module would still be named for rules it no longer renders, and the issue says only the spec read stays there. - Rejected: Put the render only in the gate check. A person would have no regenerate command, and product code cannot import a test module.
- Chosen: Split the spec read and the Sloth render into two modules. The catalog imports only the spec read, and the render is a thin wrapper around
sloth generatewith the existing--writeworkflow.
- Rejected: Keep the wrapper in
- How does the update merge Sloth output into the values file?: Run
sloth generatefor each spec, collect itsgroupsin file-name order, write them at the 6-space indent ofserverFiles.devops_cli_alerting_rules.yml.groups, and replace only the text between# BEGIN slo-rulesand# END slo-rules. Keep every other rule group as it is. (best practice) [sources: k8s/devops/monitoring/prometheus-rules-values.yaml:537-544, src/devops_cli/prometheus/slo_rules.py:40-41]- Rejected: Replace the whole values file. It would delete the other product rule groups in the file.
- Rejected: Edit the file by hand. A hand edit drifts and cannot be checked.
- Chosen: Splice at the SLO markers. The values file already separates the SLO groups with the two marker comments.
- How does CI prove the committed rules match Sloth?: Extend the
k8srow check intests/gate/k8s_checks/slo_rules.py: render the specs with Sloth into a copy of the values file, compare the parsed groups with the committed block, and fail with the difference and the regenerate command. Keep the SLO row and alert row checks. A test that reads the file cannot prove the Sloth output. (best practice) [sources: tests/gate/k8s_checks/slo_rules.py:80-93, tests/gate/k8s.py:1-9]- Rejected: No check. A spec change could land without its generated rules.
- Rejected: A test that reads the file. A test cannot prove that the committed rules are the current Sloth output.
- Chosen: A generator check in the
k8srow. The row already fails when the file and a fresh render differ, and the gate runs in the runner image that holdssloth.
- Which Sloth version and license does the devtools image install?: Sloth v0.16.0, Apache-2.0. The feat(monitoring): define the Service SLOs in a Sloth spec #4709 record states the version and the license, and the project pins no tool version in
runner_tools.py: the devtools image gives the version of each tool. The devtools image installs v0.16.0 when it shipssloth. [sources: openspec/changes/archive/2026-11-24-4709-define-the-service-slos-in-a/proposal.md:56, src/devops_cli/roadmap/runner_tools.py:50-54, https://github.com/slok/sloth] - Should the devtools image build Sloth from source or install a release binary?: Install the pinned v0.16.0 release binary. Sloth ships as a single binary, and the devtools image already carries each tool as a prebuilt binary under
/usr/local/binand audits what it installs; a Go build stage would add a toolchain and build time for no gain. This repository only pins the devtools image digest. (best practice) [sources: .devops/research-watch.toml:28, https://github.com/slok/sloth]- Rejected: Build from source. It adds a Go toolchain and build time to the devtools image.
- Chosen: Install the v0.16.0 release binary. Sloth publishes a single binary and the devtools image ships prebuilt binaries under
/usr/local/bin.
- How do the generated rules keep the labels and the low-sample guard of the current rules?: Each spec sets
labels: {service: <service>, slo: <slo>}and theseveritylabels of its page and ticket alerts (criticalandwarning), so Sloth's output carries the labels that the current alert rules and the homelab dashboards select. The render keeps the 20-event low-sample guard ofdocs/guidelines/sre.md:55: each alert carries the>= 20condition on the spec'stotal_queryover its long window, and the promtool case of ten requests in ten minutes stays quiet. Ifsloth generatedoes not emit that guard, the render appends it; it does not keep a rule template. (best practice) [sources: k8s/devops/monitoring/prometheus-rules-values.yaml:13-15, k8s/devops/monitoring/prometheus-rules-values.yaml:604-613, k8s/devops/monitoring/slos/llm-gateway-requests.yaml:6-19, docs/guidelines/sre.md:55, openspec/changes/archive/2026-11-24-4709-define-the-service-slos-in-a/proposal.md:52, https://github.com/slok/sloth]- Chosen: Set the labels and severity in the specs and keep the guard. The generated rules keep the labels and the 20-event behavior that the alert table and the promtool cases pin.
- Rejected: Accept Sloth's default labels and no guard. The alerts would lose their severity, the recorded series would lose
serviceandslo, and the low-sample case would fire. - Rejected: Keep the in-repo renderer. That is the copy this issue deletes.
Fit
Fits in one pull request.
Suspected block
A devtools image release (github.com/dan-petty/devtools) that ships the sloth v0.16.0 binary, and the pin bump of ghcr.io/dan-petty/devtools in this repository; the pinned 1.5.1 image holds no sloth.
Dependencies
None.
Activity
devops-cli-service commentedon Nov 28, 2026
Owner question: See Suspected block in the section Proposed design of the body.
Options
Recommendation: Decide the question: only a person can answer it.
Evidence