mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
feat: dont compile regex matcher if we know its a literal (#12434)
labels: dont compile regex matcher if we know its a literal Signed-off-by: Michael Hoffmann <mhoffm@posteo.de> Co-authored-by: Sharad <sharadgaur@gmail.com>
This commit is contained in:
parent
90f6c1faba
commit
7f9fe4cb5f
|
@ -118,12 +118,12 @@ func TestInverse(t *testing.T) {
|
||||||
expected: &Matcher{Type: MatchEqual, Name: "name2", Value: "value2"},
|
expected: &Matcher{Type: MatchEqual, Name: "name2", Value: "value2"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
matcher: &Matcher{Type: MatchRegexp, Name: "name3", Value: "value3"},
|
matcher: &Matcher{Type: MatchRegexp, Name: "name3", Value: "value3.*"},
|
||||||
expected: &Matcher{Type: MatchNotRegexp, Name: "name3", Value: "value3"},
|
expected: &Matcher{Type: MatchNotRegexp, Name: "name3", Value: "value3.*"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
matcher: &Matcher{Type: MatchNotRegexp, Name: "name4", Value: "value4"},
|
matcher: &Matcher{Type: MatchNotRegexp, Name: "name4", Value: "value4.*"},
|
||||||
expected: &Matcher{Type: MatchRegexp, Name: "name4", Value: "value4"},
|
expected: &Matcher{Type: MatchRegexp, Name: "name4", Value: "value4.*"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,3 +215,13 @@ func BenchmarkMatchType_String(b *testing.B) {
|
||||||
_ = MatchType(i % int(MatchNotRegexp+1)).String()
|
_ = MatchType(i % int(MatchNotRegexp+1)).String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkNewMatcher(b *testing.B) {
|
||||||
|
b.Run("regex matcher with literal", func(b *testing.B) {
|
||||||
|
b.ReportAllocs()
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i <= b.N; i++ {
|
||||||
|
NewMatcher(MatchRegexp, "foo", "bar")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue