Skip to content

Commit

Permalink
Merge pull request #879 from pyrra-dev/alerting-burnrates-absent
Browse files Browse the repository at this point in the history
Add burnrate and absent alerting configuration
  • Loading branch information
metalmatze authored Aug 28, 2023
2 parents 3c84c19 + 0dce672 commit f618d80
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 126 deletions.
8 changes: 8 additions & 0 deletions config/crd/bases/pyrra.dev_servicelevelobjectives.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
"alerting": {
"description": "Alerting customizes the alerting rules generated by Pyrra.",
"properties": {
"absent": {
"default": true,
"type": "boolean"
},
"burnrates": {
"default": true,
"type": "boolean"
},
"disabled": {
"description": "Disabled is used to disable the generation of alerts. Recording rules are still generated.",
"type": "boolean"
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/pyrra.dev_servicelevelobjectives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ spec:
alerting:
description: Alerting customizes the alerting rules generated by Pyrra.
properties:
absent:
default: true
type: boolean
burnrates:
default: true
type: boolean
disabled:
description: Disabled is used to disable the generation of alerts.
Recording rules are still generated.
Expand Down
17 changes: 17 additions & 0 deletions kubernetes/api/v1alpha1/servicelevelobjective_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,18 @@ type ServiceLevelIndicator struct {

type Alerting struct {
// +optional
// +kubebuilder:deprecatedversion:warning="disabled is deprecated. Use burnrates instead."
// Disabled is used to disable the generation of alerts. Recording rules are still generated.
Disabled *bool `json:"disabled,omitempty"`

// +optional
// +kubebuilder:default:=true
Burnrates *bool `json:"burnrates,omitempty"`

// +optional
// +kubebuilder:default:=true
Absent *bool `json:"absent,omitempty"`

// +optional
// Name is used as the name of the alert generated by Pyrra. Defaults to "ErrorBudgetBurn".
Name string `json:"name,omitempty"`
Expand Down Expand Up @@ -347,6 +356,14 @@ func (in *ServiceLevelObjective) Internal() (slo.Objective, error) {
if in.Spec.Alerting.Disabled != nil {
alerting.Disabled = *in.Spec.Alerting.Disabled
}
alerting.Burnrates = true
if in.Spec.Alerting.Burnrates != nil {
alerting.Burnrates = *in.Spec.Alerting.Burnrates
}
alerting.Absent = true
if in.Spec.Alerting.Absent != nil {
alerting.Absent = *in.Spec.Alerting.Absent
}

if in.Spec.Alerting.Name != "" {
alerting.Name = in.Spec.Alerting.Name
Expand Down
24 changes: 24 additions & 0 deletions kubernetes/api/v1alpha1/servicelevelobjective_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ spec:
Description: "",
Target: 0.99,
Window: model.Duration(7 * 24 * time.Hour),
Alerting: slo.Alerting{
Burnrates: true,
Absent: true,
},
Indicator: slo.Indicator{
Ratio: &slo.RatioIndicator{
Errors: slo.Metric{
Expand Down Expand Up @@ -101,6 +105,10 @@ spec:
Description: "",
Target: 0.9990000000000001, // TODO fix this? maybe not /100?
Window: model.Duration(7 * 24 * time.Hour),
Alerting: slo.Alerting{
Burnrates: true,
Absent: true,
},
Indicator: slo.Indicator{
Ratio: &slo.RatioIndicator{
Errors: slo.Metric{
Expand Down Expand Up @@ -153,6 +161,10 @@ spec:
),
Target: 0.995,
Window: model.Duration(28 * 24 * time.Hour),
Alerting: slo.Alerting{
Burnrates: true,
Absent: true,
},
Indicator: slo.Indicator{
Latency: &slo.LatencyIndicator{
Success: slo.Metric{
Expand Down Expand Up @@ -203,6 +215,10 @@ spec:
),
Target: 0.995,
Window: model.Duration(7 * 24 * time.Hour),
Alerting: slo.Alerting{
Burnrates: true,
Absent: true,
},
Indicator: slo.Indicator{
Latency: &slo.LatencyIndicator{
Success: slo.Metric{
Expand Down Expand Up @@ -255,6 +271,10 @@ spec:
),
Target: 0.99,
Window: model.Duration(28 * 24 * time.Hour),
Alerting: slo.Alerting{
Burnrates: true,
Absent: true,
},
Indicator: slo.Indicator{
Latency: &slo.LatencyIndicator{
Success: slo.Metric{
Expand Down Expand Up @@ -306,6 +326,10 @@ spec:
),
Target: 0.99,
Window: model.Duration(14 * 24 * time.Hour),
Alerting: slo.Alerting{
Burnrates: true,
Absent: true,
},
Indicator: slo.Indicator{
Ratio: &slo.RatioIndicator{
Errors: slo.Metric{
Expand Down
10 changes: 10 additions & 0 deletions kubernetes/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions slo/promql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ var (
Labels: labels.FromStrings(labels.MetricName, "monitoring-http-errors"),
Target: 0.99,
Window: model.Duration(28 * 24 * time.Hour),
Alerting: Alerting{
Burnrates: true,
Absent: true,
},
Indicator: Indicator{
Ratio: &RatioIndicator{
Errors: Metric{
Expand Down Expand Up @@ -60,6 +64,10 @@ var (
Description: "",
Target: 0.999,
Window: model.Duration(28 * 24 * time.Hour),
Alerting: Alerting{
Burnrates: true,
Absent: true,
},
Indicator: Indicator{
Ratio: &RatioIndicator{
Errors: Metric{
Expand Down Expand Up @@ -95,6 +103,10 @@ var (
Labels: labels.FromStrings(labels.MetricName, "monitoring-http-latency"),
Target: 0.995,
Window: model.Duration(28 * 24 * time.Hour),
Alerting: Alerting{
Burnrates: true,
Absent: true,
},
Indicator: Indicator{
Latency: &LatencyIndicator{
Success: Metric{
Expand Down Expand Up @@ -156,6 +168,10 @@ var (
Labels: labels.FromStrings(labels.MetricName, "monitoring-grpc-latency"),
Target: 0.995,
Window: model.Duration(7 * 24 * time.Hour),
Alerting: Alerting{
Burnrates: true,
Absent: true,
},
Indicator: Indicator{
Latency: &LatencyIndicator{
Success: Metric{
Expand Down Expand Up @@ -191,6 +207,10 @@ var (
Labels: labels.FromStrings(labels.MetricName, "monitoring-prometheus-operator-errors"),
Target: 0.99,
Window: model.Duration(14 * 24 * time.Hour),
Alerting: Alerting{
Burnrates: true,
Absent: true,
},
Indicator: Indicator{
Ratio: &RatioIndicator{
Errors: Metric{
Expand Down Expand Up @@ -219,6 +239,10 @@ var (
Labels: labels.FromStrings(labels.MetricName, "apiserver-write-response-errors"),
Target: 0.99,
Window: model.Duration(14 * 24 * time.Hour),
Alerting: Alerting{
Burnrates: true,
Absent: true,
},
Indicator: Indicator{
Ratio: &RatioIndicator{
Errors: Metric{
Expand All @@ -243,13 +267,19 @@ var (
objectiveAPIServerRatioAlertingDisabled = func() Objective {
o := objectiveAPIServerRatio()
o.Alerting.Disabled = true
o.Alerting.Burnrates = false
o.Alerting.Absent = false
return o
}
objectiveAPIServerLatency = func() Objective {
return Objective{
Labels: labels.FromStrings(labels.MetricName, "apiserver-read-resource-latency"),
Target: 0.99,
Window: model.Duration(14 * 24 * time.Hour),
Alerting: Alerting{
Burnrates: true,
Absent: true,
},
Indicator: Indicator{
Latency: &LatencyIndicator{
Grouping: []string{
Expand Down Expand Up @@ -280,6 +310,8 @@ var (
objectiveAPIServerLatencyAlertingDisabled = func() Objective {
o := objectiveAPIServerLatency()
o.Alerting.Disabled = true
o.Alerting.Burnrates = false
o.Alerting.Absent = false
return o
}
objectiveAPIServerLatencyCustomAlertname = func() Objective {
Expand All @@ -292,6 +324,10 @@ var (
Labels: labels.FromStrings(labels.MetricName, "up-targets"),
Target: 0.99,
Window: model.Duration(28 * 24 * time.Hour),
Alerting: Alerting{
Burnrates: true,
Absent: true,
},
Indicator: Indicator{
BoolGauge: &BoolGaugeIndicator{
Metric: Metric{Name: "up"},
Expand Down
Loading

0 comments on commit f618d80

Please sign in to comment.