Skip to content

Commit bc4e71c

Browse files
authored
Merge pull request #667 from slok/slok/contrib-plugins
Add info_labels_v1 contrib SLO plugin
2 parents 7419227 + b6233fc commit bc4e71c

7 files changed

Lines changed: 569 additions & 0 deletions

File tree

.github/CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
# Default owners.
12
* @slok
23

4+
# Contrib SLO plugins default owners.
5+
/internal/plugin/slo/contrib/ @slok
6+
7+
# Specific contrib SLO owners.
8+
/internal/plugin/slo/contrib/info_labels_v1/ @cxdy @slok @wbollock

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- Add contrib plugin directory and CODEOWNERS policies.
8+
- Contrib plugin: `info_labels_v1`.
9+
510
## [v0.13.0] - 2025-09-10
611

712
### Changed
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
2+
---
3+
# Code generated by Sloth (dev): https://github.com/slok/sloth.
4+
# DO NOT EDIT.
5+
6+
groups:
7+
- name: sloth-slo-sli-recordings-myservice-requests-availability-contrib-plugin-info-labels-v1
8+
rules:
9+
- record: slo:sli_error:ratio_rate5m
10+
expr: |
11+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[5m])))
12+
/
13+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[5m])))
14+
labels:
15+
cmd: examplesgen.sh
16+
owner: myteam
17+
repo: myorg/myservice
18+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
19+
sloth_service: myservice
20+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
21+
sloth_window: 5m
22+
tier: "2"
23+
- record: slo:sli_error:ratio_rate30m
24+
expr: |
25+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[30m])))
26+
/
27+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[30m])))
28+
labels:
29+
cmd: examplesgen.sh
30+
owner: myteam
31+
repo: myorg/myservice
32+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
33+
sloth_service: myservice
34+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
35+
sloth_window: 30m
36+
tier: "2"
37+
- record: slo:sli_error:ratio_rate1h
38+
expr: |
39+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[1h])))
40+
/
41+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[1h])))
42+
labels:
43+
cmd: examplesgen.sh
44+
owner: myteam
45+
repo: myorg/myservice
46+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
47+
sloth_service: myservice
48+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
49+
sloth_window: 1h
50+
tier: "2"
51+
- record: slo:sli_error:ratio_rate2h
52+
expr: |
53+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[2h])))
54+
/
55+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[2h])))
56+
labels:
57+
cmd: examplesgen.sh
58+
owner: myteam
59+
repo: myorg/myservice
60+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
61+
sloth_service: myservice
62+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
63+
sloth_window: 2h
64+
tier: "2"
65+
- record: slo:sli_error:ratio_rate6h
66+
expr: |
67+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[6h])))
68+
/
69+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[6h])))
70+
labels:
71+
cmd: examplesgen.sh
72+
owner: myteam
73+
repo: myorg/myservice
74+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
75+
sloth_service: myservice
76+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
77+
sloth_window: 6h
78+
tier: "2"
79+
- record: slo:sli_error:ratio_rate1d
80+
expr: |
81+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[1d])))
82+
/
83+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[1d])))
84+
labels:
85+
cmd: examplesgen.sh
86+
owner: myteam
87+
repo: myorg/myservice
88+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
89+
sloth_service: myservice
90+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
91+
sloth_window: 1d
92+
tier: "2"
93+
- record: slo:sli_error:ratio_rate3d
94+
expr: |
95+
(sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[3d])))
96+
/
97+
(sum(rate(http_request_duration_seconds_count{job="myservice"}[3d])))
98+
labels:
99+
cmd: examplesgen.sh
100+
owner: myteam
101+
repo: myorg/myservice
102+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
103+
sloth_service: myservice
104+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
105+
sloth_window: 3d
106+
tier: "2"
107+
- record: slo:sli_error:ratio_rate30d
108+
expr: |
109+
sum_over_time(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"}[30d])
110+
/ ignoring (sloth_window)
111+
count_over_time(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"}[30d])
112+
labels:
113+
cmd: examplesgen.sh
114+
owner: myteam
115+
repo: myorg/myservice
116+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
117+
sloth_service: myservice
118+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
119+
sloth_window: 30d
120+
tier: "2"
121+
- name: sloth-slo-meta-recordings-myservice-requests-availability-contrib-plugin-info-labels-v1
122+
rules:
123+
- record: slo:objective:ratio
124+
expr: vector(0.9990000000000001)
125+
labels:
126+
cmd: examplesgen.sh
127+
owner: myteam
128+
repo: myorg/myservice
129+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
130+
sloth_service: myservice
131+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
132+
tier: "2"
133+
- record: slo:error_budget:ratio
134+
expr: vector(1-0.9990000000000001)
135+
labels:
136+
cmd: examplesgen.sh
137+
owner: myteam
138+
repo: myorg/myservice
139+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
140+
sloth_service: myservice
141+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
142+
tier: "2"
143+
- record: slo:time_period:days
144+
expr: vector(30)
145+
labels:
146+
cmd: examplesgen.sh
147+
owner: myteam
148+
repo: myorg/myservice
149+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
150+
sloth_service: myservice
151+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
152+
tier: "2"
153+
- record: slo:current_burn_rate:ratio
154+
expr: |
155+
slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"}
156+
/ on(sloth_id, sloth_slo, sloth_service) group_left
157+
slo:error_budget:ratio{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"}
158+
labels:
159+
cmd: examplesgen.sh
160+
owner: myteam
161+
repo: myorg/myservice
162+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
163+
sloth_service: myservice
164+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
165+
tier: "2"
166+
- record: slo:period_burn_rate:ratio
167+
expr: |
168+
slo:sli_error:ratio_rate30d{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"}
169+
/ on(sloth_id, sloth_slo, sloth_service) group_left
170+
slo:error_budget:ratio{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"}
171+
labels:
172+
cmd: examplesgen.sh
173+
owner: myteam
174+
repo: myorg/myservice
175+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
176+
sloth_service: myservice
177+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
178+
tier: "2"
179+
- record: slo:period_error_budget_remaining:ratio
180+
expr: 1 - slo:period_burn_rate:ratio{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1",
181+
sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"}
182+
labels:
183+
cmd: examplesgen.sh
184+
owner: myteam
185+
repo: myorg/myservice
186+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
187+
sloth_service: myservice
188+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
189+
tier: "2"
190+
- record: sloth_slo_info
191+
expr: vector(1)
192+
labels:
193+
cmd: examplesgen.sh
194+
owner: myteam
195+
plug-l1: in-k1
196+
plug-l2: in-k2
197+
plug-l3: in-k3
198+
repo: myorg/myservice
199+
sloth_id: myservice-requests-availability-contrib-plugin-info-labels-v1
200+
sloth_mode: cli-gen-prom
201+
sloth_objective: "99.9"
202+
sloth_service: myservice
203+
sloth_slo: requests-availability-contrib-plugin-info-labels-v1
204+
sloth_spec: prometheus/v1
205+
sloth_version: dev
206+
tier: "2"
207+
- name: sloth-slo-alerts-myservice-requests-availability-contrib-plugin-info-labels-v1
208+
rules:
209+
- alert: MyServiceHighErrorRate
210+
expr: |
211+
(
212+
max(slo:sli_error:ratio_rate5m{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"} > (14.4 * 0.0009999999999999432)) without (sloth_window)
213+
and
214+
max(slo:sli_error:ratio_rate1h{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"} > (14.4 * 0.0009999999999999432)) without (sloth_window)
215+
)
216+
or
217+
(
218+
max(slo:sli_error:ratio_rate30m{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"} > (6 * 0.0009999999999999432)) without (sloth_window)
219+
and
220+
max(slo:sli_error:ratio_rate6h{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"} > (6 * 0.0009999999999999432)) without (sloth_window)
221+
)
222+
labels:
223+
category: availability
224+
routing_key: myteam
225+
severity: pageteam
226+
sloth_severity: page
227+
annotations:
228+
summary: High error rate on 'myservice' requests responses
229+
title: (page) {{$labels.sloth_service}} {{$labels.sloth_slo}} SLO error budget
230+
burn rate is too fast.
231+
- alert: MyServiceHighErrorRate
232+
expr: |
233+
(
234+
max(slo:sli_error:ratio_rate2h{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"} > (3 * 0.0009999999999999432)) without (sloth_window)
235+
and
236+
max(slo:sli_error:ratio_rate1d{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"} > (3 * 0.0009999999999999432)) without (sloth_window)
237+
)
238+
or
239+
(
240+
max(slo:sli_error:ratio_rate6h{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"} > (1 * 0.0009999999999999432)) without (sloth_window)
241+
and
242+
max(slo:sli_error:ratio_rate3d{sloth_id="myservice-requests-availability-contrib-plugin-info-labels-v1", sloth_service="myservice", sloth_slo="requests-availability-contrib-plugin-info-labels-v1"} > (1 * 0.0009999999999999432)) without (sloth_window)
243+
)
244+
labels:
245+
category: availability
246+
severity: slack
247+
slack_channel: '#alerts-myteam'
248+
sloth_severity: ticket
249+
annotations:
250+
summary: High error rate on 'myservice' requests responses
251+
title: (ticket) {{$labels.sloth_service}} {{$labels.sloth_slo}} SLO error budget
252+
burn rate is too fast.

examples/contrib-slo-plugins.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: "prometheus/v1"
2+
service: "myservice"
3+
labels:
4+
owner: "myteam"
5+
repo: "myorg/myservice"
6+
tier: "2"
7+
8+
slos:
9+
- name: "requests-availability-contrib-plugin-info-labels-v1"
10+
objective: 99.9
11+
description: "Common SLO based on availability for HTTP request responses."
12+
plugins:
13+
chain:
14+
- id: "sloth.dev/contrib/info_labels/v1"
15+
config:
16+
labels:
17+
plug-l1: in-k1
18+
plug-l2: in-k2
19+
plug-l3: in-k3
20+
sli:
21+
events:
22+
error_query: sum(rate(http_request_duration_seconds_count{job="myservice",code=~"(5..|429)"}[{{.window}}]))
23+
total_query: sum(rate(http_request_duration_seconds_count{job="myservice"}[{{.window}}]))
24+
alerting:
25+
name: MyServiceHighErrorRate
26+
labels:
27+
category: "availability"
28+
annotations:
29+
# Overwrite default Sloth SLO alert summmary on ticket and page alerts.
30+
summary: "High error rate on 'myservice' requests responses"
31+
page_alert:
32+
labels:
33+
severity: pageteam
34+
routing_key: myteam
35+
ticket_alert:
36+
labels:
37+
severity: "slack"
38+
slack_channel: "#alerts-myteam"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# sloth.dev/contrib/info_labels/v1
2+
3+
This plugin adds labels to the `info` metric created by Sloth metadata recording rules.
4+
5+
## Config
6+
7+
- `labels` (**Required**, `map[string]string`): The labels to be added to the metric.
8+
- `metricName` (**Optional**, `string`): If you want to customize the info metric where the labels will be added, by default Sloth info metadata metric: `sloth_slo_info`.
9+
10+
## Env vars
11+
12+
None
13+
14+
## Order requirement
15+
16+
This plugin should run after metadata rules generation plugins.
17+
18+
## Usage examples
19+
20+
### Custom labels
21+
22+
```yaml
23+
chain:
24+
- id: "sloth.dev/contrib/info_labels/v1"
25+
config:
26+
labels:
27+
label_k_1: label_v_2
28+
label_k_3: label_v_4
29+
```
30+
31+
### Custom info name
32+
33+
```yaml
34+
chain:
35+
- id: "sloth.dev/contrib/info_labels/v1"
36+
config:
37+
metricName: 🦥_info
38+
labels:
39+
label_k_1: label_v_2
40+
label_k_3: label_v_4
41+
```

0 commit comments

Comments
 (0)