Skip to content

Commit

Permalink
Fix rangemapper with VectorExpr support (#7288)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:
The new expression type VectorExpr introduced recently in
[PR](#7007), is not taken into
account in the query mapping in the AST mapper rangemapper.
The AST mapper shardmapper was updated in
[PR](#7045).

**Special notes for your reviewer**:

**Checklist**
- [ ] Reviewed the `CONTRIBUTING.md` guide
- [ ] Documentation added
- [x] Tests updated
- [x] `CHANGELOG.md` updated
- [ ] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/upgrading/_index.md`
  • Loading branch information
ssncferreira authored Sep 29, 2022
1 parent c5ec1ac commit 10e9695
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
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

0 comments on commit 10e9695

Please sign in to comment.