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).
pull/3274/head
Julius Volz 7 years ago
parent 73dc96e7f5
commit 33c1171b9c

@ -59,8 +59,7 @@ func NewMatcher(t MatchType, n, v string) (*Matcher, error) {
Value: v,
}
if t == MatchRegexp || t == MatchNotRegexp {
m.Value = "^(?:" + v + ")$"
re, err := regexp.Compile(m.Value)
re, err := regexp.Compile("^(?:" + v + ")$")
if err != nil {
return nil, err
}

@ -233,14 +233,14 @@ func convertMatcher(m *labels.Matcher) tsdbLabels.Matcher {
return tsdbLabels.Not(tsdbLabels.NewEqualMatcher(m.Name, m.Value))
case labels.MatchRegexp:
res, err := tsdbLabels.NewRegexpMatcher(m.Name, m.Value)
res, err := tsdbLabels.NewRegexpMatcher(m.Name, "^(?:"+m.Value+")$")
if err != nil {
panic(err)
}
return res
case labels.MatchNotRegexp:
res, err := tsdbLabels.NewRegexpMatcher(m.Name, m.Value)
res, err := tsdbLabels.NewRegexpMatcher(m.Name, "^(?:"+m.Value+")$")
if err != nil {
panic(err)
}

Loading…
Cancel
Save