mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Merge pull request #578 from grafana/logiraptor/fix-set-matches-for-regexp-literal
Fix regexp set matches for literal matchers
This commit is contained in:
commit
ae280910a1
|
@ -366,7 +366,7 @@ func optimizeAlternatingLiterals(s string) (StringMatcher, []string) {
|
||||||
// If there are no alternates, check if the string is a literal
|
// If there are no alternates, check if the string is a literal
|
||||||
if estimatedAlternates == 1 {
|
if estimatedAlternates == 1 {
|
||||||
if regexp.QuoteMeta(s) == s {
|
if regexp.QuoteMeta(s) == s {
|
||||||
return &equalStringMatcher{s: s, caseSensitive: true}, nil
|
return &equalStringMatcher{s: s, caseSensitive: true}, []string{s}
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,6 +342,14 @@ func TestFindSetMatches(t *testing.T) {
|
||||||
matches, actualCaseSensitive := findSetMatches(parsed)
|
matches, actualCaseSensitive := findSetMatches(parsed)
|
||||||
require.Equal(t, c.expMatches, matches)
|
require.Equal(t, c.expMatches, matches)
|
||||||
require.Equal(t, c.expCaseSensitive, actualCaseSensitive)
|
require.Equal(t, c.expCaseSensitive, actualCaseSensitive)
|
||||||
|
|
||||||
|
if c.expCaseSensitive {
|
||||||
|
// When the regexp is case sensitive, we want to ensure that the
|
||||||
|
// set matches are maintained in the final matcher.
|
||||||
|
r, err := newFastRegexMatcherWithoutCache(c.pattern)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, c.expMatches, r.SetMatches())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,7 @@ func benchmarkPostingsForMatchers(b *testing.B, ir IndexReader) {
|
||||||
iNotAlternate := labels.MustNewMatcher(labels.MatchNotRegexp, "i", "(1|2|3|4|5|6|20|55)")
|
iNotAlternate := labels.MustNewMatcher(labels.MatchNotRegexp, "i", "(1|2|3|4|5|6|20|55)")
|
||||||
iXYZ := labels.MustNewMatcher(labels.MatchRegexp, "i", "X|Y|Z")
|
iXYZ := labels.MustNewMatcher(labels.MatchRegexp, "i", "X|Y|Z")
|
||||||
iNotXYZ := labels.MustNewMatcher(labels.MatchNotRegexp, "i", "X|Y|Z")
|
iNotXYZ := labels.MustNewMatcher(labels.MatchNotRegexp, "i", "X|Y|Z")
|
||||||
|
literalRegexp := labels.MustNewMatcher(labels.MatchRegexp, "i_times_n", "0")
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
matchers []*labels.Matcher
|
matchers []*labels.Matcher
|
||||||
|
@ -168,6 +169,7 @@ func benchmarkPostingsForMatchers(b *testing.B, ir IndexReader) {
|
||||||
{`n="1",i=~".+",i!~"2.*",j="foo"`, []*labels.Matcher{n1, iPlus, iNot2Star, jFoo}},
|
{`n="1",i=~".+",i!~"2.*",j="foo"`, []*labels.Matcher{n1, iPlus, iNot2Star, jFoo}},
|
||||||
{`n="1",i=~".+",i!~".*2.*",j="foo"`, []*labels.Matcher{n1, iPlus, iNotStar2Star, jFoo}},
|
{`n="1",i=~".+",i!~".*2.*",j="foo"`, []*labels.Matcher{n1, iPlus, iNotStar2Star, jFoo}},
|
||||||
{`n="X",i=~".+",i!~".*2.*",j="foo"`, []*labels.Matcher{nX, iPlus, iNotStar2Star, jFoo}},
|
{`n="X",i=~".+",i!~".*2.*",j="foo"`, []*labels.Matcher{nX, iPlus, iNotStar2Star, jFoo}},
|
||||||
|
{`i_times_n=~"0"`, []*labels.Matcher{literalRegexp}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
|
Loading…
Reference in a new issue