mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 14:17:12 +02:00
Don't add anchoring to exported Value
matcher field
Instead, just make the anchoring part of the internal regex. This helps because some users will want to read back the `Value` field and expect it to be the same as the input value (e.g. some tests in Cortex), or use the value in another context which is already expected to add its own anchoring, leading to superfluous double anchoring (such as when we translate matchers into remote read request matchers).
This commit is contained in:
parent
73dc96e7f5
commit
33c1171b9c
@ -59,8 +59,7 @@ func NewMatcher(t MatchType, n, v string) (*Matcher, error) {
|
|||||||
Value: v,
|
Value: v,
|
||||||
}
|
}
|
||||||
if t == MatchRegexp || t == MatchNotRegexp {
|
if t == MatchRegexp || t == MatchNotRegexp {
|
||||||
m.Value = "^(?:" + v + ")$"
|
re, err := regexp.Compile("^(?:" + v + ")$")
|
||||||
re, err := regexp.Compile(m.Value)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -233,14 +233,14 @@ func convertMatcher(m *labels.Matcher) tsdbLabels.Matcher {
|
|||||||
return tsdbLabels.Not(tsdbLabels.NewEqualMatcher(m.Name, m.Value))
|
return tsdbLabels.Not(tsdbLabels.NewEqualMatcher(m.Name, m.Value))
|
||||||
|
|
||||||
case labels.MatchRegexp:
|
case labels.MatchRegexp:
|
||||||
res, err := tsdbLabels.NewRegexpMatcher(m.Name, m.Value)
|
res, err := tsdbLabels.NewRegexpMatcher(m.Name, "^(?:"+m.Value+")$")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
case labels.MatchNotRegexp:
|
case labels.MatchNotRegexp:
|
||||||
res, err := tsdbLabels.NewRegexpMatcher(m.Name, m.Value)
|
res, err := tsdbLabels.NewRegexpMatcher(m.Name, "^(?:"+m.Value+")$")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user