Skip to content

Commit 38595c1

Browse files
feat: add the ability to configure partialResponseStrategy
Signed-off-by: Zach Robinson <[email protected]>
1 parent a6ea746 commit 38595c1

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

jsonnet/controller-gen/pyrra.dev_servicelevelobjectives.json

+10
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@
232232
},
233233
"type": "object"
234234
},
235+
"partial_response_strategy": {
236+
"default": "abort",
237+
"description": "PartialResponseStrategy is only used by ThanosRuler and will\nbe ignored by Prometheus instances.\nMore info: https://github.com/thanos-io/thanos/blob/main/docs/components/rule.md#partial-response",
238+
"enum": [
239+
"abort",
240+
"warn",
241+
""
242+
],
243+
"type": "string"
244+
},
235245
"target": {
236246
"description": "Target is a string that's casted to a float64 between 0 - 100.\nIt represents the desired availability of the service in the given window.\nfloat64 are not supported: https://github.com/kubernetes-sigs/controller-tools/issues/245",
237247
"type": "string"

kubernetes/api/v1alpha1/servicelevelobjective_types.go

+8
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ type ServiceLevelObjectiveSpec struct {
9090
// +optional
9191
// Alerting customizes the alerting rules generated by Pyrra.
9292
Alerting Alerting `json:"alerting"`
93+
94+
// +optional
95+
// +kubebuilder:validation:Enum:=abort;warn;""
96+
// +kubebuilder:default:=abort
97+
// PartialResponseStrategy is only used by ThanosRuler and will
98+
// be ignored by Prometheus instances.
99+
// More info: https://github.com/thanos-io/thanos/blob/main/docs/components/rule.md#partial-response
100+
PartialResponseStrategy string `json:"partial_response_strategy,omitempty"`
93101
}
94102

95103
// ServiceLevelIndicator defines the underlying indicator that is a Prometheus metric.

kubernetes/controllers/servicelevelobjective.go

+8
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ func makeConfigMap(name string, kubeObjective pyrrav1alpha1.ServiceLevelObjectiv
250250
}
251251
}
252252

253+
for i := range rule.Groups {
254+
rule.Groups[i].PartialResponseStrategy = kubeObjective.Spec.PartialResponseStrategy
255+
}
256+
253257
bytes, err := yaml.Marshal(rule)
254258
if err != nil {
255259
return nil, fmt.Errorf("failed to marshal recording rule: %w", err)
@@ -406,6 +410,10 @@ func makePrometheusRule(kubeObjective pyrrav1alpha1.ServiceLevelObjective, gener
406410
}
407411
}
408412

413+
for i := range rule.Groups {
414+
rule.Groups[i].PartialResponseStrategy = kubeObjective.Spec.PartialResponseStrategy
415+
}
416+
409417
isController := true
410418
return &monitoringv1.PrometheusRule{
411419
TypeMeta: metav1.TypeMeta{

kubernetes/controllers/servicelevelobjective_test.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var (
4747
},
4848
},
4949
},
50+
PartialResponseStrategy: "warn",
5051
},
5152
}
5253
)
@@ -84,8 +85,9 @@ func Test_makePrometheusRule(t *testing.T) {
8485
Spec: monitoringv1.PrometheusRuleSpec{
8586
Groups: []monitoringv1.RuleGroup{
8687
{
87-
Name: "http-increase",
88-
Interval: monitoringDuration("2m30s"),
88+
Name: "http-increase",
89+
PartialResponseStrategy: "warn",
90+
Interval: monitoringDuration("2m30s"),
8991
Rules: []monitoringv1.Rule{
9092
{
9193
Record: "http_requests:increase4w",
@@ -113,8 +115,9 @@ func Test_makePrometheusRule(t *testing.T) {
113115
},
114116
},
115117
{
116-
Name: "http",
117-
Interval: monitoringDuration("30s"),
118+
Name: "http",
119+
PartialResponseStrategy: "warn",
120+
Interval: monitoringDuration("30s"),
118121
Rules: []monitoringv1.Rule{
119122
{
120123
Record: "http_requests:burnrate5m",
@@ -199,6 +202,7 @@ func Test_makeConfigMap(t *testing.T) {
199202
rules := `groups:
200203
- interval: 2m30s
201204
name: http-increase
205+
partial_response_strategy: warn
202206
rules:
203207
- expr: sum by (status) (increase(http_requests_total{job="app"}[4w]))
204208
labels:
@@ -218,6 +222,7 @@ func Test_makeConfigMap(t *testing.T) {
218222
team: foo
219223
- interval: 30s
220224
name: http
225+
partial_response_strategy: warn
221226
rules:
222227
- expr: sum(rate(http_requests_total{job="app",status=~"5.."}[5m])) / sum(rate(http_requests_total{job="app"}[5m]))
223228
labels:

0 commit comments

Comments
 (0)