-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support extra label selectors on mimir.rules.kubernetes #1773
Support extra label selectors on mimir.rules.kubernetes #1773
Conversation
for i := range ruleGroup.Rules { | ||
if ruleGroup.Rules[i].Labels == nil { | ||
ruleGroup.Rules[i].Labels = make(map[string]string, len(e.externalLabels)) | ||
} | ||
maps.Copy(ruleGroup.Rules[i].Labels, e.externalLabels) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a rename of non-idiomatic rule_group variable here.
if e.extraQueryMatchers != nil { | ||
for _, ruleGroup := range groups { | ||
for i := range ruleGroup.Rules { | ||
query := ruleGroup.Rules[i].Expr.Value | ||
newQuery, err := addMatchersToQuery(query, e.extraQueryMatchers.Matchers) | ||
if err != nil { | ||
level.Error(e.logger).Log("msg", "failed to add labels to PrometheusRule query", "query", query, "err", err) | ||
} | ||
maps.Copy(rule_group.Rules[i].Labels, e.externalLabels) | ||
ruleGroup.Rules[i].Expr.Value = newQuery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is new.
|
||
expectedRule := `- name: group1 | ||
rules: | ||
- expr: "sum by (namespace) (rate(success{cluster=~\"prod-.*\",job=\"good\"}[10m]) / rate(total{cluster=~\"prod-.*\",job=\"good\"}[10m]))" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shows how for queries that refer multiple metrics, the extra matchers will be added to all metric selectors.
extra_query_matchers { | ||
matcher { | ||
name = "job" | ||
match_type = "!=" | ||
value = "bar" | ||
} | ||
matcher { | ||
name = "namespace" | ||
match_type = "=" | ||
value = "all" | ||
} | ||
matcher { | ||
name = "namespace" | ||
match_type = "!~" | ||
value = ".+" | ||
} | ||
matcher { | ||
name = "cluster" | ||
match_type = "=~" | ||
value = "prod-.*" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example of user-facing config.
docs/sources/reference/components/mimir/mimir.rules.kubernetes.md
Outdated
Show resolved
Hide resolved
docs/sources/reference/components/mimir/mimir.rules.kubernetes.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
PR Description
The goal is to allow mimir.rules.kubernetes to add extra matchers to queries, using the same code as the promtool does here.
Which issue(s) this PR fixes
Internal request.
Notes to the Reviewer
PR Checklist