Skip to content
Open
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
8 changes: 8 additions & 0 deletions jsonnet/controller-gen/pyrra.dev_servicelevelobjectives.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@
},
"type": "object"
},
"labels": {
"additionalProperties": {
"type": "string"
},
"description": "Labels is a passthrough value where the labels provided in the ServiceLevelObjective\nwill be passed into the metrics generated.",
"type": "object"
},
"partial_response_strategy": {
"default": "abort",
"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",
Expand All @@ -253,6 +260,7 @@
},
"required": [
"indicator",
"labels",
"target",
"window"
],
Expand Down
19 changes: 12 additions & 7 deletions kubernetes/api/v1alpha1/servicelevelobjective_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ type ServiceLevelObjectiveSpec struct {
// gives extra context for engineers that might not directly work on the service.
Description string `json:"description"`

// Labels is a passthrough value where the labels provided in the ServiceLevelObjective
// will be passed into the metrics generated.
Labels map[string]string `json:"labels"`

// Target is a string that's casted to a float64 between 0 - 100.
// It represents the desired availability of the service in the given window.
// float64 are not supported: https://github.com/kubernetes-sigs/controller-tools/issues/245
Expand Down Expand Up @@ -566,13 +570,14 @@ func (in *ServiceLevelObjective) Internal() (slo.Objective, error) {
}

return slo.Objective{
Labels: ls,
Annotations: in.Annotations,
Description: in.Spec.Description,
Target: target / 100,
Window: window,
Config: string(config),
Alerting: alerting,
Labels: ls,
PassthroughLabels: in.Spec.Labels,
Annotations: in.Annotations,
Description: in.Spec.Description,
Target: target / 100,
Window: window,
Config: string(config),
Alerting: alerting,
Indicator: slo.Indicator{
Ratio: ratio,
Latency: latency,
Expand Down
4 changes: 4 additions & 0 deletions slo/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,10 @@ func (o Objective) GenericRules() (monitoringv1.RuleGroup, error) {

ruleLabels := o.commonRuleLabels(sloName)

for k, v := range o.PassthroughLabels {
ruleLabels[k] = v
}

rules = append(rules, monitoringv1.Rule{
Record: "pyrra_objective",
Expr: intstr.FromString(strconv.FormatFloat(o.Target, 'f', -1, 64)),
Expand Down
13 changes: 7 additions & 6 deletions slo/slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ const (
)

type Objective struct {
Labels labels.Labels
Annotations map[string]string
Description string
Target float64
Window model.Duration
Config string
Labels labels.Labels
PassthroughLabels map[string]string
Annotations map[string]string
Description string
Target float64
Window model.Duration
Config string

Alerting Alerting
Indicator Indicator
Expand Down
Loading