Skip to content

Commit

Permalink
Rename params mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jeschkies committed Nov 16, 2023
1 parent cbf3d1c commit 9bb42ae
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
8 changes: 4 additions & 4 deletions pkg/logql/downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (ev *DownstreamEvaluator) NewStepEvaluator(
shards = append(shards, *e.shard)
}
results, err := ev.Downstream(ctx, []DownstreamQuery{{
Params: ParamsWithMappedExpression{Params: params, Mapped: e.SampleExpr},
Params: ParamsWithExpressionOverride{Params: params, ExpressionOverride: e.SampleExpr},
Shards: shards,
}})
if err != nil {
Expand All @@ -277,7 +277,7 @@ func (ev *DownstreamEvaluator) NewStepEvaluator(
var queries []DownstreamQuery
for cur != nil {
qry := DownstreamQuery{
Params: ParamsWithMappedExpression{Params: params, Mapped: cur.DownstreamSampleExpr.SampleExpr},
Params: ParamsWithExpressionOverride{Params: params, ExpressionOverride: cur.DownstreamSampleExpr.SampleExpr},
}
if shard := cur.DownstreamSampleExpr.shard; shard != nil {
qry.Shards = Shards{*shard}
Expand Down Expand Up @@ -326,7 +326,7 @@ func (ev *DownstreamEvaluator) NewIterator(
shards = append(shards, *e.shard)
}
results, err := ev.Downstream(ctx, []DownstreamQuery{{
Params: ParamsWithMappedExpression{Params: params, Mapped: e.LogSelectorExpr},
Params: ParamsWithExpressionOverride{Params: params, ExpressionOverride: e.LogSelectorExpr},
Shards: shards,
}})
if err != nil {
Expand All @@ -339,7 +339,7 @@ func (ev *DownstreamEvaluator) NewIterator(
var queries []DownstreamQuery
for cur != nil {
qry := DownstreamQuery{
Params: ParamsWithMappedExpression{Params: params, Mapped: cur.DownstreamLogSelectorExpr.LogSelectorExpr},
Params: ParamsWithExpressionOverride{Params: params, ExpressionOverride: cur.DownstreamLogSelectorExpr.LogSelectorExpr},
}
if shard := cur.DownstreamLogSelectorExpr.shard; shard != nil {
qry.Shards = Shards{*shard}
Expand Down
7 changes: 3 additions & 4 deletions pkg/logql/downstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestMappingEquivalence(t *testing.T) {
_, _, mapped, err := mapper.Parse(tc.query)
require.Nil(t, err)

shardedQry := sharded.Query(ctx, ParamsWithMappedExpression{Params: params, Mapped: mapped})
shardedQry := sharded.Query(ctx, ParamsWithExpressionOverride{Params: params, ExpressionOverride: mapped})

res, err := qry.Exec(ctx)
require.Nil(t, err)
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestShardCounter(t *testing.T) {
noop, _, mapped, err := mapper.Parse(tc.query)
require.NoError(t, err)

shardedQry := sharded.Query(ctx, ParamsWithMappedExpression{Params: params, Mapped: mapped})
shardedQry := sharded.Query(ctx, ParamsWithExpressionOverride{Params: params, ExpressionOverride: mapped})

shardedRes, err := shardedQry.Exec(ctx)
require.Nil(t, err)
Expand Down Expand Up @@ -421,8 +421,7 @@ func TestRangeMappingEquivalence(t *testing.T) {

require.False(t, noop, "downstream engine cannot execute noop")

params.queryExpr = rangeExpr
rangeQry := downstreamEngine.Query(ctx, params)
rangeQry := downstreamEngine.Query(ctx, ParamsWithExpressionOverride{Params: params, ExpressionOverride: rangeExpr})
rangeRes, err := rangeQry.Exec(ctx)
require.Nil(t, err)

Expand Down
10 changes: 5 additions & 5 deletions pkg/logql/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ func GetRangeType(q Params) QueryRangeType {
return RangeType
}

// ParamsWithMappedExpression overrides the query expression so that the query
// ParamsWithExpressionOverride overrides the query expression so that the query
// string and the expression can differ. This is useful for sharding etc.
type ParamsWithMappedExpression struct {
type ParamsWithExpressionOverride struct {
Params
Mapped syntax.Expr
ExpressionOverride syntax.Expr
}

func (p ParamsWithMappedExpression) GetExpression() syntax.Expr {
return p.Mapped
func (p ParamsWithExpressionOverride) GetExpression() syntax.Expr {
return p.ExpressionOverride
}

// Sortable logql contain sort or sort_desc.
Expand Down
3 changes: 3 additions & 0 deletions pkg/querier/queryrange/downstreamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func ParamsToLokiRequest(params logql.Params, shards logql.Shards) queryrangebas
Direction: params.Direction(),
Path: "/loki/api/v1/query", // TODO(owen-d): make this derivable
Shards: shards.Encode(),
Plan: &plan.QueryPlan{
AST: params.GetExpression(),
},
}
}
return &LokiRequest{
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/queryrange/downstreamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func TestInstanceDownstream(t *testing.T) {

queries := []logql.DownstreamQuery{
{
Params: logql.ParamsWithMappedExpression{Params: params, Mapped: expr},
Params: logql.ParamsWithExpressionOverride{Params: params, ExpressionOverride: expr},
Shards: logql.Shards{{Shard: 0, Of: 2}},
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/queryrange/querysharding.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (ast *astMapperware) Do(ctx context.Context, r queryrangebase.Request) (que
default:
return nil, fmt.Errorf("expected *LokiRequest or *LokiInstantRequest, got (%T)", r)
}
query := ast.ng.Query(ctx, logql.ParamsWithMappedExpression{Params: params, Mapped: parsed})
query := ast.ng.Query(ctx, logql.ParamsWithExpressionOverride{Params: params, ExpressionOverride: parsed})

res, err := query.Exec(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/queryrange/split_by_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *splitByRange) Do(ctx context.Context, request queryrangebase.Request) (
return nil, fmt.Errorf("expected *LokiInstantRequest")
}

query := s.ng.Query(ctx, logql.ParamsWithMappedExpression{Params: params, Mapped: parsed})
query := s.ng.Query(ctx, logql.ParamsWithExpressionOverride{Params: params, ExpressionOverride: parsed})

res, err := query.Exec(ctx)
if err != nil {
Expand Down

0 comments on commit 9bb42ae

Please sign in to comment.