Skip to content

Commit 6b0709e

Browse files
committed
Address comments
Signed-off-by: Eunice Kim <[email protected]>
1 parent 3cf75b5 commit 6b0709e

File tree

6 files changed

+113
-105
lines changed

6 files changed

+113
-105
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
* [ENHANCEMENT] Upgrade go to 1.22.5 #6014 #6072
2323
* [ENHANCEMENT] Ingester: Add a new experimental `-ingester.labels-string-interning-enabled` flag to enable string interning for metrics labels. #6057
2424
* [ENHANCEMENT] Ingester: Add link to renew 10% of the ingesters tokens in the admin page. #6063
25+
* [ENHANCEMENT] Ruler: Add support for filtering by `state` and `health` field on Rules API. #6040
26+
* [ENHANCEMENT] Ruler: Add support for filtering by `match` field on Rules API. #6083
2527
* [BUGFIX] Configsdb: Fix endline issue in db password. #5920
2628
* [BUGFIX] Ingester: Fix `user` and `type` labels for the `cortex_ingester_tsdb_head_samples_appended_total` TSDB metric. #5952
2729
* [BUGFIX] Querier: Enforce max query length check for `/api/v1/series` API even though `ignoreMaxQueryLength` is set to true. #6018
2830
* [BUGFIX] Ingester: Fix issue with the minimize token generator where it was not taking in consideration the current ownerhip of an instance when generating extra tokens. #6062
29-
* [ENHANCEMENT] Ruler: Add support for filtering by `state` and `health` field on Rules API. #6040
30-
* [ENHANCEMENT] Ruler: Add support for filtering by `match` field on Rules API. #6083
3131

3232
## 1.17.1 2024-05-20
3333

pkg/ruler/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (a *API) PrometheusRules(w http.ResponseWriter, req *http.Request) {
161161
Type: typ,
162162
State: state,
163163
Health: health,
164-
Matches: req.Form["match[]"],
164+
Matchers: req.Form["match[]"],
165165
}
166166

167167
w.Header().Set("Content-Type", "application/json")

pkg/ruler/ruler.go

+19-10
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ func (r *Ruler) getLocalRules(userID string, rulesRequest RulesRequest, includeB
884884
ruleType := rulesRequest.Type
885885
alertState := rulesRequest.State
886886
health := rulesRequest.Health
887-
matcherSets, err := parseMatchersParam(rulesRequest.Matches)
887+
matcherSets, err := parseMatchersParam(rulesRequest.Matchers)
888888
if err != nil {
889889
return nil, errors.Wrap(err, "error parsing matcher values")
890890
}
@@ -932,7 +932,7 @@ func (r *Ruler) getLocalRules(userID string, rulesRequest RulesRequest, includeB
932932
if !returnByHealth(health, string(r.Health())) {
933933
continue
934934
}
935-
if !matches(matcherSets, r.Labels()) {
935+
if !matchesMatcherSets(matcherSets, r.Labels()) {
936936
continue
937937
}
938938
lastError := ""
@@ -1077,7 +1077,7 @@ func (r *Ruler) ruleGroupListToGroupStateDesc(userID string, backupGroups rulesp
10771077
continue
10781078
}
10791079
}
1080-
if !matches(filters.matcherSets, cortexpb.FromLabelAdaptersToLabels(r.Labels)) {
1080+
if !matchesMatcherSets(filters.matcherSets, cortexpb.FromLabelAdaptersToLabels(r.Labels)) {
10811081
continue
10821082
}
10831083

@@ -1174,7 +1174,7 @@ func (r *Ruler) getShardedRules(ctx context.Context, userID string, rulesRequest
11741174
RuleGroupNames: rulesRequest.GetRuleGroupNames(),
11751175
Files: rulesRequest.GetFiles(),
11761176
Type: rulesRequest.GetType(),
1177-
Matches: rulesRequest.GetMatches(),
1177+
Matchers: rulesRequest.GetMatchers(),
11781178
})
11791179

11801180
if err != nil {
@@ -1356,17 +1356,26 @@ OUTER:
13561356
return matcherSets, nil
13571357
}
13581358

1359-
func matches(matcherSets [][]*labels.Matcher, l labels.Labels) bool {
1359+
func matches(l labels.Labels, matchers ...*labels.Matcher) bool {
1360+
for _, m := range matchers {
1361+
if v := l.Get(m.Name); !m.Matches(v) {
1362+
return false
1363+
}
1364+
}
1365+
return true
1366+
}
1367+
1368+
// matchesMatcherSets ensures all matches in each matcher set are ANDed and the set of those is ORed.
1369+
func matchesMatcherSets(matcherSets [][]*labels.Matcher, l labels.Labels) bool {
13601370
if len(matcherSets) == 0 {
13611371
return true
13621372
}
13631373

1374+
var ok bool
13641375
for _, matchers := range matcherSets {
1365-
for _, m := range matchers {
1366-
if v := l.Get(m.Name); m.Matches(v) {
1367-
return true
1368-
}
1376+
if matches(l, matchers...) {
1377+
ok = true
13691378
}
13701379
}
1371-
return false
1380+
return ok
13721381
}

pkg/ruler/ruler.pb.go

+67-67
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ruler/ruler.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ message RulesRequest {
2626
string type = 4;
2727
string state = 5;
2828
string health = 6;
29-
repeated string matches = 7;
29+
repeated string matchers = 7;
3030
}
3131

3232
message RulesResponse {

0 commit comments

Comments
 (0)