mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
track-number-of-optimized-regexp-label-matchers - make isRegexOptimized (#481)
public Signed-off-by: dhanu <andreasdhanu@gmail.com>
This commit is contained in:
parent
c461e22341
commit
ad4dc380d5
|
@ -137,3 +137,11 @@ func (m *Matcher) Prefix() string {
|
|||
}
|
||||
return m.re.prefix
|
||||
}
|
||||
|
||||
// IsRegexOptimized returns whether regex is optimized.
|
||||
func (m *Matcher) IsRegexOptimized() bool {
|
||||
if m.re == nil {
|
||||
return false
|
||||
}
|
||||
return m.re.IsOptimized()
|
||||
}
|
||||
|
|
|
@ -186,6 +186,30 @@ func TestPrefix(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIsRegexOptimized(t *testing.T) {
|
||||
for i, tc := range []struct {
|
||||
matcher *Matcher
|
||||
isRegexOptimized bool
|
||||
}{
|
||||
{
|
||||
matcher: mustNewMatcher(t, MatchEqual, "abc"),
|
||||
isRegexOptimized: false,
|
||||
},
|
||||
{
|
||||
matcher: mustNewMatcher(t, MatchRegexp, "."),
|
||||
isRegexOptimized: false,
|
||||
},
|
||||
{
|
||||
matcher: mustNewMatcher(t, MatchRegexp, "abc.+"),
|
||||
isRegexOptimized: true,
|
||||
},
|
||||
} {
|
||||
t.Run(fmt.Sprintf("%d: %s", i, tc.matcher), func(t *testing.T) {
|
||||
require.Equal(t, tc.isRegexOptimized, tc.matcher.IsRegexOptimized())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMatchType_String(b *testing.B) {
|
||||
for i := 0; i <= b.N; i++ {
|
||||
_ = MatchType(i % int(MatchNotRegexp+1)).String()
|
||||
|
|
|
@ -151,11 +151,9 @@ func (m *FastRegexMatcher) compileMatchStringFunction() func(string) bool {
|
|||
}
|
||||
}
|
||||
|
||||
// isOptimized returns true if any fast-path optimization is applied to the
|
||||
// IsOptimized returns true if any fast-path optimization is applied to the
|
||||
// regex matcher.
|
||||
//
|
||||
//nolint:unused
|
||||
func (m *FastRegexMatcher) isOptimized() bool {
|
||||
func (m *FastRegexMatcher) IsOptimized() bool {
|
||||
return len(m.setMatches) > 0 || m.stringMatcher != nil || m.prefix != "" || m.suffix != "" || m.contains != ""
|
||||
}
|
||||
|
||||
|
|
|
@ -582,7 +582,7 @@ func TestAnalyzeRealQueries(t *testing.T) {
|
|||
numChecked++
|
||||
|
||||
// Check if each regexp matcher is supported by our optimization.
|
||||
if m.isOptimized() {
|
||||
if m.IsOptimized() {
|
||||
numOptimized++
|
||||
info.optimized = true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue