Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add exhaustion label to alerts #787

Merged
merged 3 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions kubernetes/controllers/servicelevelobjective_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,28 @@ func Test_makePrometheusRule(t *testing.T) {
Alert: "ErrorBudgetBurn",
Expr: intstr.FromString(`http_requests:burnrate5m{job="app",slo="http"} > (14 * (1-0.995)) and http_requests:burnrate1h{job="app",slo="http"} > (14 * (1-0.995))`),
For: "2m",
Labels: map[string]string{"severity": "critical", "job": "app", "long": "1h", "slo": "http", "short": "5m", "team": "foo"},
Labels: map[string]string{"severity": "critical", "job": "app", "long": "1h", "slo": "http", "short": "5m", "team": "foo", "exhaustion": "2d"},
Annotations: map[string]string{"description": "foo"},
},
{
Alert: "ErrorBudgetBurn",
Expr: intstr.FromString(`http_requests:burnrate30m{job="app",slo="http"} > (7 * (1-0.995)) and http_requests:burnrate6h{job="app",slo="http"} > (7 * (1-0.995))`),
For: "15m",
Labels: map[string]string{"severity": "critical", "job": "app", "long": "6h", "slo": "http", "short": "30m", "team": "foo"},
Labels: map[string]string{"severity": "critical", "job": "app", "long": "6h", "slo": "http", "short": "30m", "team": "foo", "exhaustion": "4d"},
Annotations: map[string]string{"description": "foo"},
},
{
Alert: "ErrorBudgetBurn",
Expr: intstr.FromString(`http_requests:burnrate2h{job="app",slo="http"} > (2 * (1-0.995)) and http_requests:burnrate1d{job="app",slo="http"} > (2 * (1-0.995))`),
For: "1h",
Labels: map[string]string{"severity": "warning", "job": "app", "long": "1d", "slo": "http", "short": "2h", "team": "foo"},
Labels: map[string]string{"severity": "warning", "job": "app", "long": "1d", "slo": "http", "short": "2h", "team": "foo", "exhaustion": "2w"},
Annotations: map[string]string{"description": "foo"},
},
{
Alert: "ErrorBudgetBurn",
Expr: intstr.FromString(`http_requests:burnrate6h{job="app",slo="http"} > (1 * (1-0.995)) and http_requests:burnrate4d{job="app",slo="http"} > (1 * (1-0.995))`),
For: "3h",
Labels: map[string]string{"severity": "warning", "job": "app", "long": "4d", "slo": "http", "short": "6h", "team": "foo"},
Labels: map[string]string{"severity": "warning", "job": "app", "long": "4d", "slo": "http", "short": "6h", "team": "foo", "exhaustion": "4w"},
Annotations: map[string]string{"description": "foo"},
},
},
Expand Down Expand Up @@ -268,6 +268,7 @@ func Test_makeConfigMap(t *testing.T) {
> (14 * (1-0.995))
for: 2m
labels:
exhaustion: 2d
job: app
long: 1h
severity: critical
Expand All @@ -281,6 +282,7 @@ func Test_makeConfigMap(t *testing.T) {
> (7 * (1-0.995))
for: 15m
labels:
exhaustion: 4d
job: app
long: 6h
severity: critical
Expand All @@ -294,6 +296,7 @@ func Test_makeConfigMap(t *testing.T) {
> (2 * (1-0.995))
for: 1h
labels:
exhaustion: 2w
job: app
long: 1d
severity: warning
Expand All @@ -307,6 +310,7 @@ func Test_makeConfigMap(t *testing.T) {
> (1 * (1-0.995))
for: 3h
labels:
exhaustion: 4w
job: app
long: 4d
severity: warning
Expand Down
12 changes: 12 additions & 0 deletions slo/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ func (o Objective) Burnrates() (monitoringv1.RuleGroup, error) {
}
}
}

// Propagate useful SLO information to alerts' labels
alertLabels["short"] = model.Duration(w.Short).String()
alertLabels["long"] = model.Duration(w.Long).String()
alertLabels["severity"] = string(w.Severity)
alertLabels["exhaustion"] = o.Exhausts(w.Factor).String()

r := monitoringv1.Rule{
Alert: o.AlertName(),
Expand Down Expand Up @@ -205,9 +208,12 @@ func (o Objective) Burnrates() (monitoringv1.RuleGroup, error) {
}
}
}

// Propagate useful SLO information to alerts' labels
alertLabels["short"] = model.Duration(w.Short).String()
alertLabels["long"] = model.Duration(w.Long).String()
alertLabels["severity"] = string(w.Severity)
alertLabels["exhaustion"] = o.Exhausts(w.Factor).String()

r := monitoringv1.Rule{
Alert: o.AlertName(),
Expand Down Expand Up @@ -290,9 +296,12 @@ func (o Objective) Burnrates() (monitoringv1.RuleGroup, error) {
}
}
}

// Propagate useful SLO information to alerts' labels
alertLabels["short"] = model.Duration(w.Short).String()
alertLabels["long"] = model.Duration(w.Long).String()
alertLabels["severity"] = string(w.Severity)
alertLabels["exhaustion"] = o.Exhausts(w.Factor).String()

r := monitoringv1.Rule{
Alert: o.AlertName(),
Expand Down Expand Up @@ -375,9 +384,12 @@ func (o Objective) Burnrates() (monitoringv1.RuleGroup, error) {
}
}
}

// Propagate useful SLO information to alerts' labels
alertLabels["short"] = model.Duration(w.Short).String()
alertLabels["long"] = model.Duration(w.Long).String()
alertLabels["severity"] = string(w.Severity)
alertLabels["exhaustion"] = o.Exhausts(w.Factor).String()

r := monitoringv1.Rule{
Alert: o.AlertName(),
Expand Down
Loading