slo-toolkit 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. slo_toolkit-0.1.1/.github/dependabot.yml +20 -0
  2. slo_toolkit-0.1.1/.github/workflows/ci.yml +80 -0
  3. slo_toolkit-0.1.1/.github/workflows/release.yml +69 -0
  4. slo_toolkit-0.1.1/.gitignore +9 -0
  5. slo_toolkit-0.1.1/.python-version +1 -0
  6. slo_toolkit-0.1.1/LICENSE +21 -0
  7. slo_toolkit-0.1.1/Makefile +22 -0
  8. slo_toolkit-0.1.1/PKG-INFO +195 -0
  9. slo_toolkit-0.1.1/README.md +170 -0
  10. slo_toolkit-0.1.1/docs/adr/0001-multiwindow-multi-burn-rate-alerts.md +35 -0
  11. slo_toolkit-0.1.1/docs/adr/0002-generate-and-test-rules.md +29 -0
  12. slo_toolkit-0.1.1/docs/adr/0003-what-counts-as-an-error.md +31 -0
  13. slo_toolkit-0.1.1/docs/runbooks/llm-gateway-availability.md +50 -0
  14. slo_toolkit-0.1.1/generated/grafana/credit-default-scoring.json +421 -0
  15. slo_toolkit-0.1.1/generated/grafana/llm-gateway.json +421 -0
  16. slo_toolkit-0.1.1/generated/prometheus/credit-default-scoring.rules.yml +341 -0
  17. slo_toolkit-0.1.1/generated/prometheus/llm-gateway.rules.yml +323 -0
  18. slo_toolkit-0.1.1/pyproject.toml +60 -0
  19. slo_toolkit-0.1.1/slos/credit-default-scoring.yaml +22 -0
  20. slo_toolkit-0.1.1/slos/llm-gateway.yaml +26 -0
  21. slo_toolkit-0.1.1/src/slo_toolkit/__init__.py +3 -0
  22. slo_toolkit-0.1.1/src/slo_toolkit/cli.py +94 -0
  23. slo_toolkit-0.1.1/src/slo_toolkit/dashboards.py +128 -0
  24. slo_toolkit-0.1.1/src/slo_toolkit/py.typed +0 -0
  25. slo_toolkit-0.1.1/src/slo_toolkit/rules.py +162 -0
  26. slo_toolkit-0.1.1/src/slo_toolkit/spec.py +126 -0
  27. slo_toolkit-0.1.1/stack/alertmanager.yml +20 -0
  28. slo_toolkit-0.1.1/stack/docker-compose.yml +51 -0
  29. slo_toolkit-0.1.1/stack/gateway.yaml +19 -0
  30. slo_toolkit-0.1.1/stack/grafana/provisioning/dashboards/slo.yml +7 -0
  31. slo_toolkit-0.1.1/stack/grafana/provisioning/datasources/prometheus.yml +8 -0
  32. slo_toolkit-0.1.1/stack/prometheus.yml +16 -0
  33. slo_toolkit-0.1.1/stack/traffic.sh +15 -0
  34. slo_toolkit-0.1.1/tests/promtool/credit-default-scoring.test.yml +43 -0
  35. slo_toolkit-0.1.1/tests/promtool/llm-gateway.test.yml +119 -0
  36. slo_toolkit-0.1.1/tests/test_slo_toolkit.py +183 -0
  37. slo_toolkit-0.1.1/uv.lock +788 -0
@@ -0,0 +1,20 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: uv
4
+ directory: /
5
+ schedule:
6
+ interval: monthly
7
+ groups:
8
+ python:
9
+ patterns: ["*"]
10
+ - package-ecosystem: github-actions
11
+ directory: /
12
+ schedule:
13
+ interval: monthly
14
+ groups:
15
+ actions:
16
+ patterns: ["*"]
17
+ - package-ecosystem: docker-compose
18
+ directory: /stack
19
+ schedule:
20
+ interval: monthly
@@ -0,0 +1,80 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ concurrency:
12
+ group: ci-${{ github.ref }}
13
+ cancel-in-progress: true
14
+
15
+ jobs:
16
+ toolkit:
17
+ name: Lint, type-check, test
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
21
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
22
+ with:
23
+ enable-cache: true
24
+ - run: uv sync --locked
25
+ - run: uv run ruff check .
26
+ - run: uv run ruff format --check .
27
+ - run: uv run mypy src
28
+ - run: uv run pytest
29
+
30
+ rules:
31
+ name: Generated rules are current and pass promtool tests
32
+ runs-on: ubuntu-latest
33
+ env:
34
+ PROMETHEUS_VERSION: "3.16.0"
35
+ steps:
36
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
37
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
38
+ with:
39
+ enable-cache: true
40
+ - name: Install promtool
41
+ run: |
42
+ mkdir -p "$RUNNER_TEMP/bin"
43
+ curl -sSfL "https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz" \
44
+ | tar -xz -C "$RUNNER_TEMP/bin" --strip-components=1 "prometheus-${PROMETHEUS_VERSION}.linux-amd64/promtool"
45
+ echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH"
46
+ - name: Generated files match the specs
47
+ run: uv run slogen generate slos --check
48
+ - name: promtool check
49
+ run: promtool check rules generated/prometheus/*.yml
50
+ - name: promtool alert tests
51
+ run: promtool test rules tests/promtool/*.test.yml
52
+
53
+ stack:
54
+ name: Stack smoke test (rules evaluate against llm-gateway)
55
+ runs-on: ubuntu-latest
56
+ steps:
57
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
58
+ - name: Start the stack
59
+ working-directory: stack
60
+ run: docker compose up -d
61
+ - name: SLI series appear and every rule evaluates
62
+ run: |
63
+ query='slo:sli_error:ratio_rate5m{slo_service="llm-gateway",slo_name="availability"}'
64
+ for _ in $(seq 1 60); do
65
+ if curl -sf --get localhost:9090/api/v1/query --data-urlencode "query=${query}" | jq -e '.data.result | length == 1' >/dev/null; then
66
+ break
67
+ fi
68
+ sleep 5
69
+ done
70
+ curl -sf --get localhost:9090/api/v1/query --data-urlencode "query=${query}" | jq -e '.data.result | length == 1'
71
+ curl -sf localhost:9090/api/v1/rules | jq -e '[.data.groups[].rules[] | select(.health == "err")] | length == 0'
72
+ curl -sf localhost:3000/api/dashboards/uid/slo-llm-gateway | jq -e '.dashboard.title == "SLOs: llm-gateway"'
73
+ - name: Logs on failure
74
+ if: failure()
75
+ working-directory: stack
76
+ run: docker compose logs --tail 50
77
+ - name: Stop
78
+ if: always()
79
+ working-directory: stack
80
+ run: docker compose down
@@ -0,0 +1,69 @@
1
+ name: Release
2
+
3
+ # On a version tag: build the sdist and wheel, publish them to PyPI with trusted publishing
4
+ # (GitHub OIDC, no stored token; each file gets a signed attestation), then create the
5
+ # GitHub release with the same files.
6
+
7
+ on:
8
+ push:
9
+ tags: ["v*.*.*"]
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ build:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
19
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
20
+ - name: The tag matches the package version
21
+ env:
22
+ TAG: ${{ github.ref_name }}
23
+ run: |
24
+ python3 - <<'PY'
25
+ import os, re, tomllib
26
+ version = tomllib.load(open("pyproject.toml", "rb"))["project"]["version"]
27
+ init = re.search(r'__version__ = "([^"]+)"', open("src/slo_toolkit/__init__.py").read()).group(1)
28
+ tag = os.environ["TAG"]
29
+ assert tag == f"v{version}" == f"v{init}", f"tag {tag}, pyproject {version}, __version__ {init}"
30
+ PY
31
+ - run: uv build
32
+ - name: Check the distributions
33
+ run: uvx twine check --strict dist/*
34
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
35
+ with:
36
+ name: dist
37
+ path: dist/
38
+ if-no-files-found: error
39
+
40
+ pypi:
41
+ needs: build
42
+ runs-on: ubuntu-latest
43
+ environment:
44
+ name: pypi
45
+ url: https://pypi.org/p/slo-toolkit
46
+ permissions:
47
+ id-token: write
48
+ steps:
49
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
50
+ with:
51
+ name: dist
52
+ path: dist/
53
+ - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
54
+
55
+ github-release:
56
+ needs: pypi
57
+ runs-on: ubuntu-latest
58
+ permissions:
59
+ contents: write
60
+ steps:
61
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
62
+ with:
63
+ name: dist
64
+ path: dist/
65
+ - name: Publish the GitHub release
66
+ env:
67
+ GH_TOKEN: ${{ github.token }}
68
+ TAG: ${{ github.ref_name }}
69
+ run: gh release create "$TAG" dist/* --repo "$GITHUB_REPOSITORY" --generate-notes --verify-tag --title "$TAG"
@@ -0,0 +1,9 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ .coverage
8
+ .DS_Store
9
+ dist/
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Muhammad Fawad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ .DEFAULT_GOAL := help
2
+
3
+ help: ## Show targets
4
+ @grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-10s\033[0m %s\n", $$1, $$2}'
5
+
6
+ generate: ## Regenerate rules and dashboards from slos/
7
+ uv run slogen generate slos
8
+
9
+ test: ## Unit tests, then promtool checks and alert tests
10
+ uv run pytest
11
+ uv run slogen generate slos --check
12
+ promtool check rules generated/prometheus/*.yml
13
+ promtool test rules tests/promtool/*.test.yml
14
+
15
+ up: ## Local stack: llm-gateway, traffic, Prometheus, Alertmanager, Grafana (ERROR_PERCENT=20 for an outage)
16
+ cd stack && docker compose up -d
17
+ @echo "Prometheus http://localhost:9090 Alertmanager http://localhost:9093 Grafana http://localhost:3000"
18
+
19
+ down: ## Stop the local stack
20
+ cd stack && docker compose down
21
+
22
+ .PHONY: help generate test up down
@@ -0,0 +1,195 @@
1
+ Metadata-Version: 2.5
2
+ Name: slo-toolkit
3
+ Version: 0.1.1
4
+ Summary: SLOs as code: generate Prometheus multi-window, multi-burn-rate alerts and Grafana dashboards from YAML, verified with promtool.
5
+ Project-URL: Homepage, https://github.com/MuhFawad1/monitoring-observability-stack
6
+ Project-URL: Source, https://github.com/MuhFawad1/monitoring-observability-stack
7
+ Project-URL: Issues, https://github.com/MuhFawad1/monitoring-observability-stack/issues
8
+ Project-URL: Changelog, https://github.com/MuhFawad1/monitoring-observability-stack/releases
9
+ Author: Muhammad Fawad
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: alerting,error-budget,grafana,prometheus,slo,sre
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: System Administrators
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: System :: Monitoring
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: pydantic>=2.8
22
+ Requires-Dist: pyyaml>=6.0
23
+ Requires-Dist: typer>=0.12
24
+ Description-Content-Type: text/markdown
25
+
26
+ # monitoring-observability-stack: SLOs as code
27
+
28
+ [![CI](https://github.com/MuhFawad1/monitoring-observability-stack/actions/workflows/ci.yml/badge.svg)](https://github.com/MuhFawad1/monitoring-observability-stack/actions/workflows/ci.yml)
29
+ ![Prometheus 3](https://img.shields.io/badge/prometheus-3.x-E6522C)
30
+ ![Grafana](https://img.shields.io/badge/grafana-13-F46800)
31
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
32
+
33
+ Define service level objectives in a few lines of YAML; `slogen` generates the
34
+ Prometheus recording rules, error-budget metrics, multi-window multi-burn-rate alerts
35
+ and Grafana dashboards. The alerts are unit-tested with promtool, and a local stack
36
+ runs them against a live service.
37
+
38
+ The example SLOs cover two real services from this portfolio: the
39
+ [llm-gateway](https://github.com/MuhFawad1/llm-gateway) and the scoring API of the
40
+ [mlops-platform](https://github.com/MuhFawad1/mlops-platform). They use the metrics those
41
+ services actually export.
42
+
43
+ ## Why
44
+
45
+ Alerting on CPU or on "error rate above 1% for 5 minutes" pages people for blips users
46
+ never notice, and misses slow leaks that blow a monthly objective. Burn-rate alerting
47
+ (Google SRE Workbook) pages only when the error budget is being spent fast enough to
48
+ matter, and resets quickly once the problem stops.
49
+
50
+ ```mermaid
51
+ flowchart LR
52
+ S[slos/*.yaml] --> G[slogen generate]
53
+ G --> R[generated/prometheus<br/>recording rules + alerts]
54
+ G --> D[generated/grafana<br/>dashboards]
55
+ R --> T{{promtool unit tests}}
56
+ R --> P[Prometheus] --> A[Alertmanager<br/>page / ticket]
57
+ D --> F[Grafana]
58
+ ```
59
+
60
+ ## A spec
61
+
62
+ ```yaml
63
+ service: llm-gateway
64
+ owner: ai-platform
65
+ slos:
66
+ - name: availability
67
+ description: Chat requests that do not fail on the gateway side.
68
+ objective: 99.5
69
+ window: 30d
70
+ sli:
71
+ ratio:
72
+ errors: sum(rate(llm_gateway_requests_total{status=~"5.."}[{{window}}]))
73
+ total: sum(rate(llm_gateway_requests_total[{{window}}]))
74
+ alerting:
75
+ runbook_url: https://github.com/MuhFawad1/monitoring-observability-stack/blob/main/docs/runbooks/llm-gateway-availability.md
76
+ - name: upstream-latency
77
+ description: Upstream model calls that answer within 8 seconds.
78
+ objective: 95
79
+ sli:
80
+ latency:
81
+ histogram: llm_gateway_upstream_duration_seconds
82
+ threshold: 8
83
+ alerting:
84
+ page: false
85
+ ```
86
+
87
+ Each SLO becomes:
88
+ - seven SLI windows (5m through 3d) plus the 30-day SLI
89
+ - objective, budget, budget-remaining and burn-rate series
90
+ - a **page** alert (14.4× over 1h/5m, or 6× over 6h/30m)
91
+ - a **ticket** alert (3× over 1d/2h, or 1× over 3d/6h)
92
+
93
+ The generated page alert, for a 99.5% objective:
94
+
95
+ ```yaml
96
+ - alert: LlmGatewayAvailabilityFastBurn
97
+ expr: |-
98
+ (
99
+ slo:sli_error:ratio_rate1h{slo_service="llm-gateway",slo_name="availability"} > 0.072
100
+ and
101
+ slo:sli_error:ratio_rate5m{slo_service="llm-gateway",slo_name="availability"} > 0.072
102
+ )
103
+ or
104
+ (
105
+ slo:sli_error:ratio_rate6h{slo_service="llm-gateway",slo_name="availability"} > 0.03
106
+ and
107
+ slo:sli_error:ratio_rate30m{slo_service="llm-gateway",slo_name="availability"} > 0.03
108
+ )
109
+ labels: {slo_service: llm-gateway, slo_name: availability, severity: page}
110
+ ```
111
+
112
+ ## Install
113
+
114
+ The generator is published on PyPI as `slo-toolkit`; the command is `slogen`.
115
+
116
+ ```bash
117
+ pip install slo-toolkit # or: uv tool install slo-toolkit
118
+ slogen validate slos && slogen generate slos
119
+ ```
120
+
121
+ Releases are published from GitHub Actions with trusted publishing, so no PyPI token is
122
+ stored anywhere, and every file carries a signed attestation of the workflow that built it.
123
+
124
+ ## Quickstart
125
+
126
+ ```bash
127
+ uv sync
128
+ uv run slogen validate slos
129
+ uv run slogen generate slos # writes generated/prometheus/*.rules.yml and generated/grafana/*.json
130
+ make test # pytest, freshness check, promtool check + alert tests
131
+ ```
132
+
133
+ ## The alerts are tested, not eyeballed
134
+
135
+ [`tests/promtool/`](tests/promtool) feeds synthetic traffic through the generated rules:
136
+
137
+ | Scenario | Expected |
138
+ |---|---|
139
+ | Healthy traffic for 3 hours | no page, no ticket |
140
+ | No 5xx series has ever existed | SLI reads 0, not "no data" |
141
+ | Hard outage (17% errors) after two healthy hours | no page 4 minutes in; page by minute 40 |
142
+ | Steady 2% errors for 25 hours | ticket, never a page |
143
+ | 80% of upstream calls slower than 8s | latency ticket (paging disabled for that SLO) |
144
+ | Scoring API at 99.9%: a 9% error spike | page within the hour |
145
+
146
+ ## Run it live
147
+
148
+ ```bash
149
+ make up # 2% errors: watch a slow burn
150
+ ERROR_PERCENT=20 make up # an outage: fast burn
151
+ ```
152
+
153
+ The stack runs the published `ghcr.io/muhfawad1/llm-gateway:0.1.0` image with mock
154
+ upstreams under synthetic traffic, plus:
155
+ - Prometheus loading the generated rules
156
+ - Alertmanager routing pages and tickets separately, and suppressing a ticket while the
157
+ same SLO is paging
158
+ - Grafana with the generated dashboards: [localhost:3000](http://localhost:3000)
159
+
160
+ CI starts this stack on every change and asserts that the SLI series appear, that no
161
+ rule has an evaluation error, and that the dashboard loads.
162
+
163
+ ## Design decisions
164
+
165
+ | ADR | Decision |
166
+ |---|---|
167
+ | [0001](docs/adr/0001-multiwindow-multi-burn-rate-alerts.md) | Alert on budget burn over two windows, not on raw thresholds |
168
+ | [0002](docs/adr/0002-generate-and-test-rules.md) | Generate rules from specs, commit the output, test it with promtool |
169
+ | [0003](docs/adr/0003-what-counts-as-an-error.md) | What counts as an error, and the PromQL edge cases that keep SLIs honest |
170
+
171
+ Runbook referenced by the llm-gateway alerts:
172
+ [docs/runbooks/llm-gateway-availability.md](docs/runbooks/llm-gateway-availability.md).
173
+
174
+ ## Layout
175
+
176
+ ```text
177
+ slos/ one spec per service
178
+ src/slo_toolkit/ spec model, rule and dashboard generators, CLI (slogen)
179
+ generated/ committed output: Prometheus rules, Grafana dashboards
180
+ tests/ generator unit tests; promtool/ alert tests
181
+ stack/ local Prometheus, Alertmanager, Grafana, llm-gateway, traffic
182
+ docs/ ADRs and runbooks
183
+ ```
184
+
185
+ ## Roadmap
186
+
187
+ - Emit `PrometheusRule` resources for the Prometheus Operator next to plain rule files.
188
+ - Import OpenSLO v1 specs.
189
+ - Per-tenant SLOs (grouped by a label such as `team`) with per-tenant budgets.
190
+ - A monthly budget report (Markdown) for service reviews.
191
+ - Synthetic-probe SLIs (blackbox exporter) for low-traffic services.
192
+
193
+ ## License
194
+
195
+ [MIT](LICENSE)
@@ -0,0 +1,170 @@
1
+ # monitoring-observability-stack: SLOs as code
2
+
3
+ [![CI](https://github.com/MuhFawad1/monitoring-observability-stack/actions/workflows/ci.yml/badge.svg)](https://github.com/MuhFawad1/monitoring-observability-stack/actions/workflows/ci.yml)
4
+ ![Prometheus 3](https://img.shields.io/badge/prometheus-3.x-E6522C)
5
+ ![Grafana](https://img.shields.io/badge/grafana-13-F46800)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
7
+
8
+ Define service level objectives in a few lines of YAML; `slogen` generates the
9
+ Prometheus recording rules, error-budget metrics, multi-window multi-burn-rate alerts
10
+ and Grafana dashboards. The alerts are unit-tested with promtool, and a local stack
11
+ runs them against a live service.
12
+
13
+ The example SLOs cover two real services from this portfolio: the
14
+ [llm-gateway](https://github.com/MuhFawad1/llm-gateway) and the scoring API of the
15
+ [mlops-platform](https://github.com/MuhFawad1/mlops-platform). They use the metrics those
16
+ services actually export.
17
+
18
+ ## Why
19
+
20
+ Alerting on CPU or on "error rate above 1% for 5 minutes" pages people for blips users
21
+ never notice, and misses slow leaks that blow a monthly objective. Burn-rate alerting
22
+ (Google SRE Workbook) pages only when the error budget is being spent fast enough to
23
+ matter, and resets quickly once the problem stops.
24
+
25
+ ```mermaid
26
+ flowchart LR
27
+ S[slos/*.yaml] --> G[slogen generate]
28
+ G --> R[generated/prometheus<br/>recording rules + alerts]
29
+ G --> D[generated/grafana<br/>dashboards]
30
+ R --> T{{promtool unit tests}}
31
+ R --> P[Prometheus] --> A[Alertmanager<br/>page / ticket]
32
+ D --> F[Grafana]
33
+ ```
34
+
35
+ ## A spec
36
+
37
+ ```yaml
38
+ service: llm-gateway
39
+ owner: ai-platform
40
+ slos:
41
+ - name: availability
42
+ description: Chat requests that do not fail on the gateway side.
43
+ objective: 99.5
44
+ window: 30d
45
+ sli:
46
+ ratio:
47
+ errors: sum(rate(llm_gateway_requests_total{status=~"5.."}[{{window}}]))
48
+ total: sum(rate(llm_gateway_requests_total[{{window}}]))
49
+ alerting:
50
+ runbook_url: https://github.com/MuhFawad1/monitoring-observability-stack/blob/main/docs/runbooks/llm-gateway-availability.md
51
+ - name: upstream-latency
52
+ description: Upstream model calls that answer within 8 seconds.
53
+ objective: 95
54
+ sli:
55
+ latency:
56
+ histogram: llm_gateway_upstream_duration_seconds
57
+ threshold: 8
58
+ alerting:
59
+ page: false
60
+ ```
61
+
62
+ Each SLO becomes:
63
+ - seven SLI windows (5m through 3d) plus the 30-day SLI
64
+ - objective, budget, budget-remaining and burn-rate series
65
+ - a **page** alert (14.4× over 1h/5m, or 6× over 6h/30m)
66
+ - a **ticket** alert (3× over 1d/2h, or 1× over 3d/6h)
67
+
68
+ The generated page alert, for a 99.5% objective:
69
+
70
+ ```yaml
71
+ - alert: LlmGatewayAvailabilityFastBurn
72
+ expr: |-
73
+ (
74
+ slo:sli_error:ratio_rate1h{slo_service="llm-gateway",slo_name="availability"} > 0.072
75
+ and
76
+ slo:sli_error:ratio_rate5m{slo_service="llm-gateway",slo_name="availability"} > 0.072
77
+ )
78
+ or
79
+ (
80
+ slo:sli_error:ratio_rate6h{slo_service="llm-gateway",slo_name="availability"} > 0.03
81
+ and
82
+ slo:sli_error:ratio_rate30m{slo_service="llm-gateway",slo_name="availability"} > 0.03
83
+ )
84
+ labels: {slo_service: llm-gateway, slo_name: availability, severity: page}
85
+ ```
86
+
87
+ ## Install
88
+
89
+ The generator is published on PyPI as `slo-toolkit`; the command is `slogen`.
90
+
91
+ ```bash
92
+ pip install slo-toolkit # or: uv tool install slo-toolkit
93
+ slogen validate slos && slogen generate slos
94
+ ```
95
+
96
+ Releases are published from GitHub Actions with trusted publishing, so no PyPI token is
97
+ stored anywhere, and every file carries a signed attestation of the workflow that built it.
98
+
99
+ ## Quickstart
100
+
101
+ ```bash
102
+ uv sync
103
+ uv run slogen validate slos
104
+ uv run slogen generate slos # writes generated/prometheus/*.rules.yml and generated/grafana/*.json
105
+ make test # pytest, freshness check, promtool check + alert tests
106
+ ```
107
+
108
+ ## The alerts are tested, not eyeballed
109
+
110
+ [`tests/promtool/`](tests/promtool) feeds synthetic traffic through the generated rules:
111
+
112
+ | Scenario | Expected |
113
+ |---|---|
114
+ | Healthy traffic for 3 hours | no page, no ticket |
115
+ | No 5xx series has ever existed | SLI reads 0, not "no data" |
116
+ | Hard outage (17% errors) after two healthy hours | no page 4 minutes in; page by minute 40 |
117
+ | Steady 2% errors for 25 hours | ticket, never a page |
118
+ | 80% of upstream calls slower than 8s | latency ticket (paging disabled for that SLO) |
119
+ | Scoring API at 99.9%: a 9% error spike | page within the hour |
120
+
121
+ ## Run it live
122
+
123
+ ```bash
124
+ make up # 2% errors: watch a slow burn
125
+ ERROR_PERCENT=20 make up # an outage: fast burn
126
+ ```
127
+
128
+ The stack runs the published `ghcr.io/muhfawad1/llm-gateway:0.1.0` image with mock
129
+ upstreams under synthetic traffic, plus:
130
+ - Prometheus loading the generated rules
131
+ - Alertmanager routing pages and tickets separately, and suppressing a ticket while the
132
+ same SLO is paging
133
+ - Grafana with the generated dashboards: [localhost:3000](http://localhost:3000)
134
+
135
+ CI starts this stack on every change and asserts that the SLI series appear, that no
136
+ rule has an evaluation error, and that the dashboard loads.
137
+
138
+ ## Design decisions
139
+
140
+ | ADR | Decision |
141
+ |---|---|
142
+ | [0001](docs/adr/0001-multiwindow-multi-burn-rate-alerts.md) | Alert on budget burn over two windows, not on raw thresholds |
143
+ | [0002](docs/adr/0002-generate-and-test-rules.md) | Generate rules from specs, commit the output, test it with promtool |
144
+ | [0003](docs/adr/0003-what-counts-as-an-error.md) | What counts as an error, and the PromQL edge cases that keep SLIs honest |
145
+
146
+ Runbook referenced by the llm-gateway alerts:
147
+ [docs/runbooks/llm-gateway-availability.md](docs/runbooks/llm-gateway-availability.md).
148
+
149
+ ## Layout
150
+
151
+ ```text
152
+ slos/ one spec per service
153
+ src/slo_toolkit/ spec model, rule and dashboard generators, CLI (slogen)
154
+ generated/ committed output: Prometheus rules, Grafana dashboards
155
+ tests/ generator unit tests; promtool/ alert tests
156
+ stack/ local Prometheus, Alertmanager, Grafana, llm-gateway, traffic
157
+ docs/ ADRs and runbooks
158
+ ```
159
+
160
+ ## Roadmap
161
+
162
+ - Emit `PrometheusRule` resources for the Prometheus Operator next to plain rule files.
163
+ - Import OpenSLO v1 specs.
164
+ - Per-tenant SLOs (grouped by a label such as `team`) with per-tenant budgets.
165
+ - A monthly budget report (Markdown) for service reviews.
166
+ - Synthetic-probe SLIs (blackbox exporter) for low-traffic services.
167
+
168
+ ## License
169
+
170
+ [MIT](LICENSE)
@@ -0,0 +1,35 @@
1
+ # ADR 0001: Alert on error-budget burn rate over two windows
2
+
3
+ - **Status:** Accepted
4
+ - **Date:** 2026-11-29
5
+
6
+ ## Context
7
+
8
+ Threshold alerts on raw signals ("error rate above 1% for 5 minutes", "CPU above 80%")
9
+ page people for blips that users never notice. They also stay silent through slow leaks
10
+ that miss the objective over a month. On-call trust erodes quickly in both directions.
11
+
12
+ ## Decision
13
+
14
+ Alert on how fast the error budget is being spent, using the four conditions from the
15
+ Google SRE Workbook, each with a long window and a short window (one twelfth of it):
16
+
17
+ | Severity | Long / short window | Burn rate | Meaning |
18
+ |---|---|---|---|
19
+ | page | 1h / 5m | 14.4 | 2% of a 30-day budget gone in an hour |
20
+ | page | 6h / 30m | 6 | 5% gone in six hours |
21
+ | ticket | 1d / 2h | 3 | 10% gone in a day |
22
+ | ticket | 3d / 6h | 1 | on track to spend the whole budget |
23
+
24
+ The long window makes the alert significant; the short window makes it stop soon after
25
+ the problem does, instead of firing for another hour on stale data. Tickets are
26
+ inhibited in Alertmanager while the same SLO is paging.
27
+
28
+ ## Consequences
29
+
30
+ - Alerts track user impact, expressed in the business's own objective, and they scale
31
+ with it: a 99.9% service pages at 1.44% errors, a 99% one at 14.4%.
32
+ - Very low-traffic services make ratios noisy. For those, raise the evaluation windows
33
+ or add synthetic probes, because one failed request in five is a 20% error rate.
34
+ - Behaviour is pinned by promtool unit tests, including the "no page four minutes into
35
+ an outage" case (ADR 0002).
@@ -0,0 +1,29 @@
1
+ # ADR 0002: Generate rules from specs, commit the output, test it with promtool
2
+
3
+ - **Status:** Accepted
4
+ - **Date:** 2026-11-29
5
+
6
+ ## Context
7
+
8
+ Hand-written burn-rate rules are long and repetitive: seven recording rules per SLO,
9
+ metadata, and two multi-clause alerts. Teams copy them, change one threshold and miss
10
+ another. Reviewers can't see the intent (99.9% over 30 days) behind the arithmetic
11
+ (`> 0.0144`).
12
+
13
+ ## Decision
14
+
15
+ - Teams write a short YAML spec per service (`slos/*.yaml`). `slogen generate` produces
16
+ the Prometheus rule files and Grafana dashboards.
17
+ - Generated files are committed, so reviewers see the exact PromQL that will run and
18
+ Prometheus needs no generator at runtime. CI fails if they are stale
19
+ (`slogen generate --check`).
20
+ - promtool unit tests (`tests/promtool/`) feed synthetic traffic and assert when each
21
+ alert must and must not fire. They test the generated output, independently of the
22
+ generator's own unit tests.
23
+
24
+ ## Consequences
25
+
26
+ - A threshold change is a one-line spec diff, plus a reviewed diff of the generated rules.
27
+ - Generator bugs are caught by behaviour, not by reading code: the "missing error series
28
+ reads as no data" bug was found by running the stack, then pinned with a promtool
29
+ expression test (ADR 0003).