diff --git a/jsonnet/controller-gen/pyrra.dev_servicelevelobjectives.json b/jsonnet/controller-gen/pyrra.dev_servicelevelobjectives.json index 7b44eb1c1..2e814da21 100644 --- a/jsonnet/controller-gen/pyrra.dev_servicelevelobjectives.json +++ b/jsonnet/controller-gen/pyrra.dev_servicelevelobjectives.json @@ -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", @@ -253,6 +260,7 @@ }, "required": [ "indicator", + "labels", "target", "window" ], diff --git a/kubernetes/api/v1alpha1/servicelevelobjective_types.go b/kubernetes/api/v1alpha1/servicelevelobjective_types.go index 1edacc306..b82aa973e 100644 --- a/kubernetes/api/v1alpha1/servicelevelobjective_types.go +++ b/kubernetes/api/v1alpha1/servicelevelobjective_types.go @@ -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 @@ -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, diff --git a/slo/rules.go b/slo/rules.go index ac469fac5..6b26573a9 100644 --- a/slo/rules.go +++ b/slo/rules.go @@ -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)), diff --git a/slo/slo.go b/slo/slo.go index 6cc2a0eb5..010aa6655 100644 --- a/slo/slo.go +++ b/slo/slo.go @@ -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