Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes logql.QueryType. #2913

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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