Skip to content

Commit

Permalink
Fixes logql.QueryType. (#2913)
Browse files Browse the repository at this point in the history
The bug was introduced with LogQL extensions.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
  • Loading branch information
cyriltovena authored Nov 10, 2020
1 parent ca311c4 commit 5738611
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/logql/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ func QueryType(query string) (string, error) {
if err != nil {
return "", err
}
switch expr.(type) {
switch e := expr.(type) {
case SampleExpr:
return QueryTypeMetric, nil
case *matchersExpr:
case LogSelectorExpr:
if e.HasFilter() {
return QueryTypeFilter, nil
}
return QueryTypeLimited, nil
case *pipelineExpr:
return QueryTypeFilter, nil
default:
return "", nil
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/logql/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ func TestQueryType(t *testing.T) {
{"bad", "ddd", "", true},
{"limited", `{app="foo"}`, QueryTypeLimited, false},
{"limited multi label", `{app="foo" ,fuzz=~"foo"}`, QueryTypeLimited, false},
{"limited with parser", `{app="foo" ,fuzz=~"foo"} | logfmt`, QueryTypeLimited, false},
{"filter", `{app="foo"} |= "foo"`, QueryTypeFilter, false},
{"filter string extracted label", `{app="foo"} | json | foo="a"`, QueryTypeFilter, false},
{"filter duration", `{app="foo"} | json | duration > 5s`, QueryTypeFilter, false},
{"metrics", `rate({app="foo"} |= "foo"[5m])`, QueryTypeMetric, false},
{"metrics binary", `rate({app="foo"} |= "foo"[5m]) + count_over_time({app="foo"} |= "foo"[5m]) / rate({app="foo"} |= "foo"[5m]) `, QueryTypeMetric, false},
{"filters", `{app="foo"} |= "foo" |= "f" != "b"`, QueryTypeFilter, false},
{"filters and labels filters", `{app="foo"} |= "foo" |= "f" != "b" | json | a > 5`, QueryTypeFilter, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 5738611

Please sign in to comment.