app/vmselect/promql: properly handle {__name__ op "string"} queries

This has been broken in 7294ef333ad26f4f6578b783e97649e58b1f8945 .
This commit is contained in:
Aliaksandr Valialkin 2019-06-07 02:01:04 +03:00
parent fbd7044b2b
commit c1f18ee48d
2 changed files with 6 additions and 2 deletions

View file

@ -1128,6 +1128,10 @@ func (tfe *tagFilterExpr) toTagFilter() (*storage.TagFilter, error) {
} else {
tf.Value = []byte(tfe.Value.S)
}
if string(tf.Key) == "__name__" {
// This is required for storage.Search
tf.Key = nil
}
tf.IsRegexp = tfe.IsRegexp
tf.IsNegative = tfe.IsNegative
if !tf.IsRegexp {

View file

@ -119,7 +119,7 @@ func TestParsePromQLSuccess(t *testing.T) {
same("WITH")
same("With")
// identifiers with with escape chars
same(`{__name__="foo bar"}`)
same(`foo\ bar`)
same(`foo\-bar\{{baz\+bar="aa"}`)
another(`\x2E\x2ef\oo{b\xEF\ar="aa"}`, `\x2e.foo{b\xefar="aa"}`)
// Duplicate filters
@ -305,7 +305,7 @@ func TestParsePromQLSuccess(t *testing.T) {
`(({job="test", i="bar"} + {job="test", i="bar", x="d"}) + foo{job="test", i="bar"}) + ctx(1)`)
another(`with (foo = bar) {__name__=~"foo"}`, `{__name__=~"foo"}`)
another(`with (foo = bar) foo{__name__="foo"}`, `bar`)
another(`with (foo = bar) {__name__="foo", x="y"}`, `{__name__="foo", x="y"}`)
another(`with (foo = bar) {__name__="foo", x="y"}`, `bar{x="y"}`)
another(`with (foo(bar) = {__name__!="bar"}) foo(x)`, `{__name__!="bar"}`)
another(`with (foo(bar) = bar{__name__="bar"}) foo(x)`, `x`)
another(`with (foo\-bar(baz) = baz + baz) foo\-bar((x,y))`, `(x, y) + (x, y)`)