Skip to content

refactor(monitoring): render the SLO rules with sloth generate #7504

Backlog

Description

@dan-petty

Problem

devops-cli renders Prometheus SLO rules with its own copy of Sloth.

  • src/devops_cli/prometheus/slo_rules.py has 348 lines and 13 tests (commit d0bc3dffa).
  • Its docstring (:1-8) says that the runner image has no sloth, "so this module renders the prometheus/v1 format of a spec itself".
  • The specs are in k8s/devops/monitoring/slos/. The rules go to k8s/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/v1 format. 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.

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.py renders 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

Source: https://github.com/dan-petty/devops-cli/blob/d0bc3dffa781951f7b49935ba545cad82b2ecfaf/src/devops_cli/prometheus/slo_rules.py

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 and uv run devops ci --check --only k8s runs 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 k8s runs 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 k8s runs.
  • 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, slo or a severity label and uv run devops ci --check --only k8s runs.
  • 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.py runs 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 sloth with source ToolSource.DEVTOOLS and 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_tools on 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_specs reads k8s/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.prometheus and checks the package.
  • THEN No module exports SLO_BURN_RATE_ROWS, SLO_RECORD_NAMES or render_slo_groups, and devops_cli.prometheus.slo_rules does 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 in k8s/devops/monitoring/slos/. Sloth is open, actively maintained and a single binary, and its generate command 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_specs and SLO_WINDOW_DAYS to src/devops_cli/prometheus/slo_specs.py, drop the grouping property and the rule-only fields, and keep the import at src/devops_cli/k8s/catalog.py:31. Do not parse Sloth output: it holds no description and 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:31 and builds its rows at :854.
  • Where do the Sloth invocation and the marker splice live?: Delete src/devops_cli/prometheus/slo_rules.py. Add src/devops_cli/prometheus/slo_specs.py for the catalog read and src/devops_cli/prometheus/slo_render.py for the render: generate_slo_groups runs sloth generate -i <spec> for each spec and returns the parsed groups, write_slo_groups replaces only the text between the markers, and a __main__ with --write lets a person regenerate. The k8s check 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 generate with the existing --write workflow.
  • How does the update merge Sloth output into the values file?: Run sloth generate for each spec, collect its groups in file-name order, write them at the 6-space indent of serverFiles.devops_cli_alerting_rules.yml.groups, and replace only the text between # BEGIN slo-rules and # 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 k8s row check in tests/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 k8s row. The row already fails when the file and a fresh render differ, and the gate runs in the runner image that holds sloth.
  • 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 ships sloth. [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/bin and 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 the severity labels of its page and ticket alerts (critical and warning), 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 of docs/guidelines/sre.md:55: each alert carries the >= 20 condition on the spec's total_query over its long window, and the promtool case of ten requests in ten minutes stays quiet. If sloth generate does 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 service and slo, 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

  1. added
    type/refactor
    source/agent
    status/new
    value/medium
    effort/medium
    scope/monitoring
    priority/p2-medium
    on Nov 28, 2026
  2. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

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/mediumpriority/p2-mediumscope/monitoringsource/agentstatus/newtype/refactorvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions