mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 22:19:40 -08:00
Merge branch 'improvesetmatches' into regexpopti
This commit is contained in:
commit
54b3371060
|
@ -111,6 +111,13 @@ func (m *Matcher) Inverse() (*Matcher, error) {
|
|||
panic("labels.Matcher.Matches: invalid match type")
|
||||
}
|
||||
|
||||
func (m *Matcher) GetRegexString() string {
|
||||
if m.re == nil {
|
||||
return ""
|
||||
}
|
||||
return m.re.GetRegexString()
|
||||
}
|
||||
|
||||
// SetMatches returns a set of equality matchers for the current regex matchers if possible.
|
||||
// For examples the regexp `a(b|f)` will returns "ab" and "af".
|
||||
// Returns nil if we can't replace the regexp by only equality matchers.
|
||||
|
|
|
@ -61,6 +61,7 @@ func findSetMatches(re *syntax.Regexp, base string) []string {
|
|||
if isCaseInsensitive(re) {
|
||||
return nil
|
||||
}
|
||||
clearBeginEndText(re)
|
||||
switch re.Op {
|
||||
case syntax.OpLiteral:
|
||||
return []string{base + string(re.Rune)}
|
||||
|
@ -108,7 +109,6 @@ func findSetMatchesFromConcat(re *syntax.Regexp, base string) []string {
|
|||
if len(re.Sub) == 0 {
|
||||
return nil
|
||||
}
|
||||
clearBeginEndText(re)
|
||||
clearCapture(re.Sub...)
|
||||
matches := []string{base}
|
||||
|
||||
|
@ -209,6 +209,10 @@ func (m *FastRegexMatcher) SetMatches() []string {
|
|||
return m.setMatches
|
||||
}
|
||||
|
||||
func (m *FastRegexMatcher) GetRegexString() string {
|
||||
return m.re.String()
|
||||
}
|
||||
|
||||
// optimizeConcatRegex returns literal prefix/suffix text that can be safely
|
||||
// checked against the label value before running the regexp matcher.
|
||||
func optimizeConcatRegex(r *syntax.Regexp) (prefix, suffix, contains string) {
|
||||
|
|
|
@ -126,7 +126,7 @@ func TestFindSetMatches(t *testing.T) {
|
|||
{"^foo$", []string{"foo"}},
|
||||
// Simple sets alternates.
|
||||
{"foo|bar|zz", []string{"foo", "bar", "zz"}},
|
||||
// Simple sets alternate and concat (bar|baz is parsed as ba(r|z)).
|
||||
// Simple sets alternate and concat (bar|baz is parsed as "ba[rz]").
|
||||
{"foo|bar|baz", []string{"foo", "bar", "baz"}},
|
||||
// Simple sets alternate and concat and capture
|
||||
{"foo|bar|baz|(zz)", []string{"foo", "bar", "baz", "zz"}},
|
||||
|
|
|
@ -2042,7 +2042,7 @@ func TestPostingsForMatcher(t *testing.T) {
|
|||
{
|
||||
// Test case for double quoted regex matcher
|
||||
matcher: labels.MustNewMatcher(labels.MatchRegexp, "test", "^(?:a|b)$"),
|
||||
hasError: true,
|
||||
hasError: false,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue