Skip to content

Commit c41ab01

Browse files
committed
Add rule intervals SLO plugin
Signed-off-by: Xabier Larrakoetxea <me@slok.dev>
1 parent 81da3a3 commit c41ab01

7 files changed

Lines changed: 508 additions & 0 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
# Specific contrib SLO owners.
88
/internal/plugin/slo/contrib/info_labels_v1/ @cxdy @slok @wbollock
99
/internal/plugin/slo/contrib/validate_victoria_metrics_v1/ @slok
10+
/internal/plugin/slo/contrib/rule_intervals_v1/ @cxdy @slok @wbollock

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Contrib plugin: `/internal/plugin/slo/contrib/info_labels_v1/`.
99
- Allow `github.com/VictoriaMetrics/metricsql` module in SLO plugins.
1010
- Contrib plugin: `sloth.dev/contrib/validate_victoria_metrics/v1`.
11+
- Contrib plugin: `sloth.dev/contrib/rule_intervals/v1`.
1112

1213
## [v0.13.0] - 2025-09-10
1314

examples/_gen/contrib-slo-plugins.yml

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,249 @@ groups:
250250
summary: High error rate on 'myservice' requests responses
251251
title: (ticket) {{$labels.sloth_service}} {{$labels.sloth_slo}} SLO error budget
252252
burn rate is too fast.
253+
- name: sloth-slo-sli-recordings-myservice-requests-availability-contrib-plugin-rule-intervals-v1
254+
interval: 5m
255+
rules:
256+
- record: slo:sli_error:ratio_rate5m
257+
expr: |
258+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[5m])))
259+
/
260+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[5m])))
261+
labels:
262+
cmd: examplesgen.sh
263+
owner: myteam
264+
repo: myorg/myservice
265+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
266+
sloth_service: myservice
267+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
268+
sloth_window: 5m
269+
tier: "2"
270+
- record: slo:sli_error:ratio_rate30m
271+
expr: |
272+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[30m])))
273+
/
274+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[30m])))
275+
labels:
276+
cmd: examplesgen.sh
277+
owner: myteam
278+
repo: myorg/myservice
279+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
280+
sloth_service: myservice
281+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
282+
sloth_window: 30m
283+
tier: "2"
284+
- record: slo:sli_error:ratio_rate1h
285+
expr: |
286+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[1h])))
287+
/
288+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[1h])))
289+
labels:
290+
cmd: examplesgen.sh
291+
owner: myteam
292+
repo: myorg/myservice
293+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
294+
sloth_service: myservice
295+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
296+
sloth_window: 1h
297+
tier: "2"
298+
- record: slo:sli_error:ratio_rate2h
299+
expr: |
300+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[2h])))
301+
/
302+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[2h])))
303+
labels:
304+
cmd: examplesgen.sh
305+
owner: myteam
306+
repo: myorg/myservice
307+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
308+
sloth_service: myservice
309+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
310+
sloth_window: 2h
311+
tier: "2"
312+
- record: slo:sli_error:ratio_rate6h
313+
expr: |
314+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[6h])))
315+
/
316+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[6h])))
317+
labels:
318+
cmd: examplesgen.sh
319+
owner: myteam
320+
repo: myorg/myservice
321+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
322+
sloth_service: myservice
323+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
324+
sloth_window: 6h
325+
tier: "2"
326+
- record: slo:sli_error:ratio_rate1d
327+
expr: |
328+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[1d])))
329+
/
330+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[1d])))
331+
labels:
332+
cmd: examplesgen.sh
333+
owner: myteam
334+
repo: myorg/myservice
335+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
336+
sloth_service: myservice
337+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
338+
sloth_window: 1d
339+
tier: "2"
340+
- record: slo:sli_error:ratio_rate3d
341+
expr: |
342+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[3d])))
343+
/
344+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[3d])))
345+
labels:
346+
cmd: examplesgen.sh
347+
owner: myteam
348+
repo: myorg/myservice
349+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
350+
sloth_service: myservice
351+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
352+
sloth_window: 3d
353+
tier: "2"
354+
- record: slo:sli_error:ratio_rate30d
355+
expr: |
356+
sum_over_time(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"}[30d])
357+
/ ignoring (sloth_window)
358+
count_over_time(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"}[30d])
359+
labels:
360+
cmd: examplesgen.sh
361+
owner: myteam
362+
repo: myorg/myservice
363+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
364+
sloth_service: myservice
365+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
366+
sloth_window: 30d
367+
tier: "2"
368+
- name: sloth-slo-meta-recordings-myservice-requests-availability-contrib-plugin-rule-intervals-v1
369+
interval: 5m
370+
rules:
371+
- record: slo:objective:ratio
372+
expr: vector(0.9990000000000001)
373+
labels:
374+
cmd: examplesgen.sh
375+
owner: myteam
376+
repo: myorg/myservice
377+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
378+
sloth_service: myservice
379+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
380+
tier: "2"
381+
- record: slo:error_budget:ratio
382+
expr: vector(1-0.9990000000000001)
383+
labels:
384+
cmd: examplesgen.sh
385+
owner: myteam
386+
repo: myorg/myservice
387+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
388+
sloth_service: myservice
389+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
390+
tier: "2"
391+
- record: slo:time_period:days
392+
expr: vector(30)
393+
labels:
394+
cmd: examplesgen.sh
395+
owner: myteam
396+
repo: myorg/myservice
397+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
398+
sloth_service: myservice
399+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
400+
tier: "2"
401+
- record: slo:current_burn_rate:ratio
402+
expr: |
403+
slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"}
404+
/ on(sloth_id, sloth_slo, sloth_service) group_left
405+
slo:error_budget:ratio{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"}
406+
labels:
407+
cmd: examplesgen.sh
408+
owner: myteam
409+
repo: myorg/myservice
410+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
411+
sloth_service: myservice
412+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
413+
tier: "2"
414+
- record: slo:period_burn_rate:ratio
415+
expr: |
416+
slo:sli_error:ratio_rate30d{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"}
417+
/ on(sloth_id, sloth_slo, sloth_service) group_left
418+
slo:error_budget:ratio{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"}
419+
labels:
420+
cmd: examplesgen.sh
421+
owner: myteam
422+
repo: myorg/myservice
423+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
424+
sloth_service: myservice
425+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
426+
tier: "2"
427+
- record: slo:period_error_budget_remaining:ratio
428+
expr: 1 - slo:period_burn_rate:ratio{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1",
429+
sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"}
430+
labels:
431+
cmd: examplesgen.sh
432+
owner: myteam
433+
repo: myorg/myservice
434+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
435+
sloth_service: myservice
436+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
437+
tier: "2"
438+
- record: sloth_slo_info
439+
expr: vector(1)
440+
labels:
441+
cmd: examplesgen.sh
442+
owner: myteam
443+
repo: myorg/myservice
444+
sloth_id: myservice-requests-availability-contrib-plugin-rule-intervals-v1
445+
sloth_mode: cli-gen-prom
446+
sloth_objective: "99.9"
447+
sloth_service: myservice
448+
sloth_slo: requests-availability-contrib-plugin-rule-intervals-v1
449+
sloth_spec: prometheus/v1
450+
sloth_version: dev
451+
tier: "2"
452+
- name: sloth-slo-alerts-myservice-requests-availability-contrib-plugin-rule-intervals-v1
453+
interval: 5m
454+
rules:
455+
- alert: MyServiceHighErrorRate
456+
expr: |
457+
(
458+
max(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"} > (14.4 * 0.0009999999999999432)) without (sloth_window)
459+
and
460+
max(slo:sli_error:ratio_rate1h{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"} > (14.4 * 0.0009999999999999432)) without (sloth_window)
461+
)
462+
or
463+
(
464+
max(slo:sli_error:ratio_rate30m{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"} > (6 * 0.0009999999999999432)) without (sloth_window)
465+
and
466+
max(slo:sli_error:ratio_rate6h{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"} > (6 * 0.0009999999999999432)) without (sloth_window)
467+
)
468+
labels:
469+
category: availability
470+
routing_key: myteam
471+
severity: pageteam
472+
sloth_severity: page
473+
annotations:
474+
summary: High error rate on 'myservice' requests responses
475+
title: (page) {{$labels.sloth_service}} {{$labels.sloth_slo}} SLO error budget
476+
burn rate is too fast.
477+
- alert: MyServiceHighErrorRate
478+
expr: |
479+
(
480+
max(slo:sli_error:ratio_rate2h{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"} > (3 * 0.0009999999999999432)) without (sloth_window)
481+
and
482+
max(slo:sli_error:ratio_rate1d{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"} > (3 * 0.0009999999999999432)) without (sloth_window)
483+
)
484+
or
485+
(
486+
max(slo:sli_error:ratio_rate6h{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"} > (1 * 0.0009999999999999432)) without (sloth_window)
487+
and
488+
max(slo:sli_error:ratio_rate3d{sloth_id="myservice-requests-availability-contrib-plugin-rule-intervals-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-rule-intervals-v1"} > (1 * 0.0009999999999999432)) without (sloth_window)
489+
)
490+
labels:
491+
category: availability
492+
severity: slack
493+
slack_channel: '#alerts-myteam'
494+
sloth_severity: ticket
495+
annotations:
496+
summary: High error rate on 'myservice' requests responses
497+
title: (ticket) {{$labels.sloth_service}} {{$labels.sloth_slo}} SLO error budget
498+
burn rate is too fast.

examples/contrib-slo-plugins.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,32 @@ slos:
3636
labels:
3737
severity: "slack"
3838
slack_channel: "#alerts-myteam"
39+
40+
- name: "requests-availability-contrib-plugin-rule-intervals-v1"
41+
objective: 99.9
42+
description: "Common SLO based on availability for HTTP request responses."
43+
plugins:
44+
chain:
45+
- id: "sloth.dev/contrib/rule_intervals/v1"
46+
config:
47+
interval:
48+
default: 5m
49+
sli:
50+
events:
51+
error_query: sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[{{.window}}]))
52+
total_query: sum(rate(http_request_duration_seconds_count{job="myservice"}[{{.window}}]))
53+
alerting:
54+
name: MyServiceHighErrorRate
55+
labels:
56+
category: "availability"
57+
annotations:
58+
# Overwrite default Sloth SLO alert summmary on ticket and page alerts.
59+
summary: "High error rate on 'myservice' requests responses"
60+
page_alert:
61+
labels:
62+
severity: pageteam
63+
routing_key: myteam
64+
ticket_alert:
65+
labels:
66+
severity: "slack"
67+
slack_channel: "#alerts-myteam"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# sloth.dev/contrib/rule_intervals/v1
2+
3+
This plugin sets Prom rule evaluation intervals to the Prometheus generated rules. The intervals can be different depending on the type of rules, SLI, metadata and alerts. A default interval can be set for all rules.
4+
5+
## Config
6+
7+
| Field | Type | Required | Default | Description |
8+
|-------------------|--------------------------|----------|---------|-------------------------------------------------------------------|
9+
| `interval.default` | Prom time duration string | Yes || Fallback interval to use if no other interval is set. |
10+
| `interval.sliError`| Prom time duration string | No || Evaluation rule interval for generated SLI error rules. |
11+
| `interval.metadata`| Prom time duration string | No || Evaluation rule interval for generated metadata rules. |
12+
| `interval.alert` | Prom time duration string | No || Evaluation rule interval for generated alert rules. |
13+
14+
## Env var
15+
16+
None
17+
18+
## Order requirement
19+
20+
This plugin must be placed **after** all rule generation.
21+
22+
## Usage examples
23+
24+
### Specific settings in an SLO group
25+
26+
```yaml
27+
slo_plugins:
28+
chain:
29+
- id: sloth.dev/contrib/validate_victoria_metrics/v1 # Custom validation.
30+
config:
31+
interval:
32+
default: 1m
33+
sliError: 42s
34+
metadata: 55s
35+
alert: 11s
36+
```
37+
38+
### Add a custom default interval to all rules and SLOs
39+
40+
By adding a default interval at app level, all generated rules by sloth will have that interval
41+
42+
```bash
43+
sloth generate \
44+
-i ./examples/getting-started.yml \
45+
-s '{"id": "sloth.dev/contrib/rule_intervals/v1","config":{"interval": {"default":"2m"}}}'
46+
```

0 commit comments

Comments
 (0)