Skip to content

Commit

Permalink
Merge pull request #614 from pyrra-dev/release-0.5-generic-rules-fix
Browse files Browse the repository at this point in the history
Fix ratio generic recording rules for SLOs with different metric names
  • Loading branch information
metalmatze authored Feb 17, 2023
2 parents 61eb388 + d73bd6f commit 9505c21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions slo/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,15 +749,15 @@ func (o Objective) GenericRules() (monitoringv1.RuleGroup, error) {
return monitoringv1.RuleGroup{}, err
}

name := o.Indicator.Ratio.Total.Name
increaseName := increaseName(name, o.Window)
totalIncreaseName := increaseName(o.Indicator.Ratio.Total.Name, o.Window)

// Copy the list of matchers to modify them
totalMatchers := make([]*labels.Matcher, 0, len(o.Indicator.Ratio.Total.LabelMatchers))

for _, m := range o.Indicator.Ratio.Total.LabelMatchers {
value := m.Value
if m.Name == labels.MetricName {
value = increaseName
value = totalIncreaseName
}
totalMatchers = append(totalMatchers, &labels.Matcher{
Type: m.Type,
Expand All @@ -766,11 +766,13 @@ func (o Objective) GenericRules() (monitoringv1.RuleGroup, error) {
})
}

errorsIncreaseName := increaseName(o.Indicator.Ratio.Errors.Name, o.Window)

errorMatchers := make([]*labels.Matcher, 0, len(o.Indicator.Ratio.Errors.LabelMatchers))
for _, m := range o.Indicator.Ratio.Errors.LabelMatchers {
value := m.Value
if m.Name == labels.MetricName {
value = increaseName
value = errorsIncreaseName
}
errorMatchers = append(errorMatchers, &labels.Matcher{
Type: m.Type,
Expand All @@ -780,9 +782,9 @@ func (o Objective) GenericRules() (monitoringv1.RuleGroup, error) {
}

objectiveReplacer{
metric: increaseName,
metric: totalIncreaseName,
matchers: totalMatchers,
errorMetric: increaseName,
errorMetric: errorsIncreaseName,
errorMatchers: errorMatchers,
}.replace(availability)

Expand Down
2 changes: 1 addition & 1 deletion slo/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@ func TestObjective_GrafanaRules(t *testing.T) {
Labels: map[string]string{"slo": "monitoring-prometheus-operator-errors"},
}, {
Record: "pyrra_availability",
Expr: intstr.FromString(`1 - sum(prometheus_operator_reconcile_operations:increase2w or vector(0)) / sum(prometheus_operator_reconcile_operations:increase2w)`),
Expr: intstr.FromString(`1 - sum(prometheus_operator_reconcile_errors:increase2w or vector(0)) / sum(prometheus_operator_reconcile_operations:increase2w)`),
Labels: map[string]string{"slo": "monitoring-prometheus-operator-errors"},
}, {
Record: "pyrra_requests_total",
Expand Down

0 comments on commit 9505c21

Please sign in to comment.