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

Fix rangemapper with VectorExpr support #7288

Merged
merged 2 commits into from
Sep 29, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [7263](https://github.com/grafana/loki/pull/7263) **bboreham**: Dependencies: klauspost/compress package to v1.15.11; improves performance.

##### Fixes
* [7288](https://github.com/grafana/loki/pull/7288) **ssncferreira**: Fix query mapping in AST mapper `rangemapper` to support the new `VectorExpr` expression.
* [7040](https://github.com/grafana/loki/pull/7040) **bakunowski**: Remove duplicated `loki_boltdb_shipper` prefix from `tables_upload_operation_total` metric.
* [6937](https://github.com/grafana/loki/pull/6937) **ssncferreira**: Fix topk and bottomk expressions with parameter <= 0.
* [6780](https://github.com/grafana/loki/pull/6780) **periklis**: Attach the panic recovery handler on all HTTP handlers
Expand Down
4 changes: 4 additions & 0 deletions pkg/logql/rangemapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ func (m RangeMapper) Map(expr syntax.SampleExpr, vectorAggrPushdown *syntax.Vect
return e, nil
case *syntax.LiteralExpr:
return e, nil
case *syntax.VectorExpr:
return e, nil
default:
// ConcatSampleExpr and DownstreamSampleExpr are not supported input expression types
return nil, errors.Errorf("unexpected expr type (%T) for ASTMapper type (%T) ", expr, m)
Expand Down Expand Up @@ -438,6 +440,8 @@ func isSplittableByRange(expr syntax.SampleExpr) bool {
return isSplittableByRange(e.SampleExpr) || literalLHS && isSplittableByRange(e.RHS) || literalRHS
case *syntax.LabelReplaceExpr:
return isSplittableByRange(e.Left)
case *syntax.VectorExpr:
return false
default:
return false
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/logql/rangemapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,14 @@ func Test_SplitRangeVectorMapping_Noop(t *testing.T) {
`sum by (foo) (sum_over_time({app="foo"} | json | unwrap bar [3m])) / sum_over_time({app="foo"} | json | unwrap bar [6m])`,
`(sum by (foo) (sum_over_time({app="foo"} | json | unwrap bar [3m])) / sum_over_time({app="foo"} | json | unwrap bar [6m]))`,
},
{
`count_over_time({app="foo"}[3m]) or vector(0)`,
`(count_over_time({app="foo"}[3m]) or vector(0.000000))`,
},
{
`sum(last_over_time({app="foo"} | logfmt | unwrap total_count [1d]) by (foo)) or vector(0)`,
`(sum(last_over_time({app="foo"} | logfmt | unwrap total_count [1d]) by (foo)) or vector(0.000000))`,
},

// should be noop if literal expression
{
Expand All @@ -1718,6 +1726,11 @@ func Test_SplitRangeVectorMapping_Noop(t *testing.T) {
`5 * 5`,
`25`,
},
// should be noop if VectorExpr
{
`vector(0)`,
`vector(0.000000)`,
},
} {
tc := tc
t.Run(tc.expr, func(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/logql/shardmapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ func TestMappingStrings(t *testing.T) {
in: `avg_over_time({job=~"myapps.*"} |= "stats" | json busy="utilization" | unwrap busy [5m])`,
out: `avg_over_time({job=~"myapps.*"} |= "stats" | json busy="utilization" | unwrap busy [5m])`,
},
// should be noop if VectorExpr
{
in: `vector(0)`,
out: `vector(0.000000)`,
},
} {
t.Run(tc.in, func(t *testing.T) {
ast, err := syntax.ParseExpr(tc.in)
Expand Down