Skip to content
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

Fix store debug matchers panic on regex matcher #7903

Merged
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#7832](https://github.com/thanos-io/thanos/pull/7832) Query Frontend: Fix cache keys for dynamic split intervals.
- [#7885](https://github.com/thanos-io/thanos/pull/7885) Store: Return chunks to the pool after completing a Series call.
- [#7893](https://github.com/thanos-io/thanos/pull/7893) Sidecar: Fix retrieval of external labels for Prometheus v3.0.0.
- [#7903](https://github.com/thanos-io/thanos/pull/7903) Query: Fix panic on regex store matchers.

### Added
- [#7763](https://github.com/thanos-io/thanos/pull/7763) Ruler: use native histograms for client latency metrics.
Expand Down
25 changes: 24 additions & 1 deletion pkg/api/query/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,16 @@ func TestParseStoreDebugMatchersParam(t *testing.T) {
labels.MustNewMatcher(labels.MatchEqual, "cluster", "test"),
}},
},
{
storeMatchers: `{__address__=~"localhost:.*"}`,
fail: false,
result: [][]*labels.Matcher{{labels.MustNewMatcher(labels.MatchRegexp, "__address__", "localhost:.*")}},
},
{
storeMatchers: `{__address__!~"localhost:.*"}`,
fail: false,
result: [][]*labels.Matcher{{labels.MustNewMatcher(labels.MatchNotRegexp, "__address__", "localhost:.*")}},
},
} {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
api := QueryAPI{
Expand All @@ -1736,11 +1746,24 @@ func TestParseStoreDebugMatchersParam(t *testing.T) {

storeMatchers, err := api.parseStoreDebugMatchersParam(r)
if !tc.fail {
testutil.Equals(t, tc.result, storeMatchers)
testutil.Equals(t, len(tc.result), len(storeMatchers))
for i, m := range tc.result {
testutil.Equals(t, len(m), len(storeMatchers[i]))
for j, n := range m {
testutil.Equals(t, n.String(), storeMatchers[i][j].String())
}
}
testutil.Equals(t, (*baseAPI.ApiError)(nil), err)
} else {
testutil.NotOk(t, err)
}

// We don't care about results but checking for panic.
for _, matchers := range storeMatchers {
for _, matcher := range matchers {
_ = matcher.Matches("")
}
}
})
}
}
Expand Down
11 changes: 1 addition & 10 deletions pkg/extpromql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,7 @@ func ParseMetricSelector(input string) ([]*labels.Matcher, error) {
return nil, fmt.Errorf("expected type *parser.VectorSelector, got %T", expr)
}

matchers := make([]*labels.Matcher, len(vs.LabelMatchers))
for i, lm := range vs.LabelMatchers {
matchers[i] = &labels.Matcher{
Type: lm.Type,
Name: lm.Name,
Value: lm.Value,
}
}

return matchers, nil
return vs.LabelMatchers, nil
}

func isEmptyNameMatcherErr(err error) bool {
Expand Down
Loading