Skip to content

Commit 5930f2a

Browse files
CopilotchefgsCopilot
authored
fix(sre): generate error_rate SLO entry instead of empty slos: [] (#48)
* Initial plan * BUG-2: Fix empty slos:[] when slo_type=error_rate in generate_slo_manifest Co-authored-by: chefgs <7605658+chefgs@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Bump version to 0.4.2 CLI version bump * Fix: assert error_rate in all-type SLO manifest test Co-authored-by: chefgs <7605658+chefgs@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: chefgs <7605658+chefgs@users.noreply.github.com> Co-authored-by: Saravanan Gnanaguru <g.gsaravanan@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 061caaf commit 5930f2a

4 files changed

Lines changed: 38 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
---
99

10+
## [0.4.2] - 2026-03-18
11+
12+
### Fixed
13+
- **`scaffold sre` empty `slos: []` when `--slo-type error_rate`**`generate_slo_manifest()` in
14+
`cli/scaffold_sre.py` had no branch for the `error_rate` SLO type, leaving `slo.yaml` with an
15+
empty `slos: []` list. Sloth/OpenSLO tooling therefore received no SLO objectives. A dedicated
16+
`error_rate` SLO entry (with matching SLI queries and alerting config) is now generated when
17+
`--slo-type error_rate` is specified.
18+
19+
---
20+
1021
## [0.4.1] - 2026-03-17
1122

1223
### Changed

cli/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Single source of truth for the devopsos package version."""
22

3-
__version__ = "0.4.1"
3+
__version__ = "0.4.2"

cli/scaffold_sre.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,28 @@ def generate_slo_manifest(args):
347347
},
348348
})
349349

350+
if args.slo_type in ("error_rate", "all"):
351+
slos.append({
352+
"name": "error_rate",
353+
"description": f"{name} error rate SLO — error rate stays below {round(100 - args.slo_target, 4)}%",
354+
"objective": args.slo_target,
355+
"sli": {
356+
"events": {
357+
"error_query": f"rate(http_requests_total{{job=\"{name}\",status=~\"(5..)\"}}[{{{{.window}}}}])",
358+
"total_query": f"rate(http_requests_total{{job=\"{name}\"}}[{{{{.window}}}}])",
359+
}
360+
},
361+
"alerting": {
362+
"name": f"{name.title()}ErrorRateSLO",
363+
"labels": {"team": args.team},
364+
"annotations": {
365+
"runbook": f"https://wiki.example.com/runbooks/{name}/error-rate",
366+
},
367+
"page_alert": {"labels": {"severity": "critical"}},
368+
"ticket_alert": {"labels": {"severity": "warning"}},
369+
},
370+
})
371+
350372
if args.slo_type in ("latency", "all"):
351373
slos.append({
352374
"name": "latency",

tests/test_comprehensive.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -854,21 +854,11 @@ def test_slo_manifest_latency_entry(self):
854854
slo_names = [s["name"] for s in manifest["slos"]]
855855
assert "latency" in slo_names
856856

857-
# BUG-2: error_rate SLO type produces empty slos list in manifest
858-
@pytest.mark.xfail(
859-
strict=True,
860-
reason=(
861-
"BUG-2: generate_slo_manifest() only checks for 'availability' and "
862-
"'latency' slo_type values. When slo_type='error_rate', neither "
863-
"condition matches so the slos list is empty. An error_rate SLO "
864-
"entry should be generated for slo_type='error_rate'."
865-
),
866-
)
867857
def test_slo_manifest_error_rate_bug(self):
868858
"""
869859
BUG-2: When slo_type='error_rate', generate_slo_manifest() should
870860
return at least one SLO entry capturing the error rate objective,
871-
but currently returns an empty slos list.
861+
and that entry should have name == 'error_rate'.
872862
"""
873863
args = _sre_args(slo_type="error_rate")
874864
manifest = scaffold_sre.generate_slo_manifest(args)
@@ -877,13 +867,16 @@ def test_slo_manifest_error_rate_bug(self):
877867
"Expected at least one SLO entry for error_rate type, "
878868
"got empty list."
879869
)
870+
slo_names = [s["name"] for s in manifest["slos"]]
871+
assert "error_rate" in slo_names
880872

881873
def test_slo_manifest_all_type_has_both_slos(self):
882874
args = _sre_args(slo_type="all")
883875
manifest = scaffold_sre.generate_slo_manifest(args)
884876
slo_names = [s["name"] for s in manifest["slos"]]
885877
assert "availability" in slo_names
886878
assert "latency" in slo_names
879+
assert "error_rate" in slo_names
887880

888881
def test_alertmanager_config_slack_receiver(self):
889882
args = _sre_args(slack_channel="#platform-alerts")

0 commit comments

Comments
 (0)