Skip to content

Commit

Permalink
[query] Fix to regexes with leading wildcard (#2505)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnikola authored Aug 1, 2020
1 parent f8b6379 commit efd2505
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,16 @@ docker-integration-test:
@echo "--- Running Docker integration test"
./scripts/docker-integration-tests/run.sh


.PHONY: docker-compatibility-test
docker-compatibility-test:
@echo "--- Running Prometheus compatibility test"
./scripts/comparator/run.sh

.PHONY: prom-compat
prom-compat:
@echo "--- Running local Prometheus compatibility test"
CI="false" make docker-compatibility-test

.PHONY: site-build
site-build:
@echo "Building site"
Expand Down
3 changes: 2 additions & 1 deletion src/query/storage/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func isSpecialCaseMatcher(matcher models.Matcher) specialCase {
return specialCase{}
}

if len(matcher.Value) != 2 && matcher.Value[0] != dot {
if len(matcher.Value) != 2 || matcher.Value[0] != dot {
return specialCase{}
}

Expand Down Expand Up @@ -235,6 +235,7 @@ func matcherToQuery(matcher models.Matcher) (idx.Query, error) {
query idx.Query
err error
)

query, err = idx.NewRegexpQuery(matcher.Name, matcher.Value)
if err != nil {
return idx.Query{}, err
Expand Down
46 changes: 45 additions & 1 deletion src/query/storage/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestFetchQueryToM3Query(t *testing.T) {
},
},
{
name: "regexp match dot star -> field",
name: "regexp match dot star -> all",
expected: "all()",
matchers: models.Matchers{
{
Expand Down Expand Up @@ -191,6 +191,50 @@ func TestFetchQueryToM3Query(t *testing.T) {
},
},
},
{
name: "regexp match dot star with trailing characters -> regex",
expected: "regexp(t1, .*foo)",
matchers: models.Matchers{
{
Type: models.MatchRegexp,
Name: []byte("t1"),
Value: []byte(".*foo"),
},
},
},
{
name: "regexp match dot plus with trailing characters -> regex",
expected: "regexp(t1, .+foo)",
matchers: models.Matchers{
{
Type: models.MatchRegexp,
Name: []byte("t1"),
Value: []byte(".+foo"),
},
},
},
{
name: "not regexp match dot star with trailing characters -> regex",
expected: "negation(regexp(t1, .*foo))",
matchers: models.Matchers{
{
Type: models.MatchNotRegexp,
Name: []byte("t1"),
Value: []byte(".*foo"),
},
},
},
{
name: "not regexp match dot plus with trailing characters -> regex",
expected: "negation(regexp(t1, .+foo))",
matchers: models.Matchers{
{
Type: models.MatchNotRegexp,
Name: []byte("t1"),
Value: []byte(".+foo"),
},
},
},
}

for _, test := range tests {
Expand Down
44 changes: 44 additions & 0 deletions src/query/test/compatibility/testdata/regression.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# this test data represents previous regressions
load 5m
http_requests{job="foo", instance="bar"} 0+10x10
http_requests{job="foo", instance="baz"} 0+20x10
http_requests{job="baz", instance="bar"} 0+30x10
http_requests{instance="bar", group="foo"} 0+40x10
http_requests{instance="bar", group="baz"} 0+50x10
http_requests{instance="baz", group="foo"} 0+60x10

eval instant at 0s http_requests{job=~".*foo"}
http_requests{job="foo", instance="bar"} 0
http_requests{job="foo", instance="baz"} 0

eval instant at 0s http_requests{job!~".*foo"}
http_requests{job="baz", instance="bar"} 0
http_requests{instance="bar", group="foo"} 0
http_requests{instance="bar", group="baz"} 0
http_requests{instance="baz", group="foo"} 0

eval instant at 0s http_requests{job=~".+oo"}
http_requests{job="foo", instance="bar"} 0
http_requests{job="foo", instance="baz"} 0

eval instant at 0s http_requests{job!~".+oo"}
http_requests{job="baz", instance="bar"} 0
http_requests{instance="bar", group="foo"} 0
http_requests{instance="bar", group="baz"} 0
http_requests{instance="baz", group="foo"} 0

eval instant at 0s http_requests{job=~".*"}
http_requests{job="foo", instance="bar"} 0
http_requests{job="foo", instance="baz"} 0
http_requests{job="baz", instance="bar"} 0
http_requests{instance="bar", group="foo"} 0
http_requests{instance="bar", group="baz"} 0
http_requests{instance="baz", group="foo"} 0

eval instant at 0s http_requests{job=~".+"}
http_requests{job="foo", instance="bar"} 0
http_requests{job="foo", instance="baz"} 0
http_requests{job="baz", instance="bar"} 0

clear

1 change: 1 addition & 0 deletions src/query/test/compatibility/testdata/selectors.test
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ eval instant at 0s http_requests{foo!~".+", job="api-server", instance="0", grou

eval instant at 0s http_requests{foo!~".*", job="api-server", instance="0", group="production"}

clear
1 change: 0 additions & 1 deletion src/query/test/compatibility/testdata/staleness.test
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ eval instant at 10s count_over_time(metric[1s])
eval instant at 20s count_over_time(metric[10s])
{} 1


clear

load 10s
Expand Down

0 comments on commit efd2505

Please sign in to comment.