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

Integrates label replace into sharding code #3132

Merged
merged 5 commits into from
Jan 7, 2021
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
2 changes: 1 addition & 1 deletion pkg/logql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ func (e *labelReplaceExpr) Extractor() (SampleExtractor, error) {
}

func (e *labelReplaceExpr) Operations() []string {
return e.left.Operations()
return append([]string{OpLabelReplace}, e.left.Operations()...)
}

func (e *labelReplaceExpr) String() string {
Expand Down
1 change: 0 additions & 1 deletion pkg/logql/sharding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func TestMappingEquivalence(t *testing.T) {
{`rate({a=~".*"}[1s])`, false},
{`sum by (a) (rate({a=~".*"}[1s]))`, false},
{`sum(rate({a=~".*"}[1s]))`, false},

{`max without (a) (rate({a=~".*"}[1s]))`, false},
{`count(rate({a=~".*"}[1s]))`, false},
{`avg(rate({a=~".*"}[1s]))`, true},
Expand Down
12 changes: 12 additions & 0 deletions pkg/logql/shardmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func (m ShardMapper) Map(expr Expr, r *shardRecorder) (Expr, error) {
return m.mapLogSelectorExpr(e.(LogSelectorExpr), r), nil
case *vectorAggregationExpr:
return m.mapVectorAggregationExpr(e, r)
case *labelReplaceExpr:
return m.mapLabelReplaceExpr(e, r)
case *rangeAggregationExpr:
return m.mapRangeAggregationExpr(e, r), nil
case *binOpExpr:
Expand Down Expand Up @@ -277,6 +279,16 @@ func (m ShardMapper) mapVectorAggregationExpr(expr *vectorAggregationExpr, r *sh
}
}

func (m ShardMapper) mapLabelReplaceExpr(expr *labelReplaceExpr, r *shardRecorder) (SampleExpr, error) {
subMapped, err := m.Map(expr.left, r)
if err != nil {
return nil, err
}
cpy := *expr
cpy.left = subMapped.(SampleExpr)
return &cpy, nil
}

func (m ShardMapper) mapRangeAggregationExpr(expr *rangeAggregationExpr, r *shardRecorder) SampleExpr {
if hasLabelModifier(expr) {
// if an expr can modify labels this means multiple shards can returns the same labelset.
Expand Down
13 changes: 13 additions & 0 deletions pkg/logql/shardmapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ func TestMappingStrings(t *testing.T) {
in: `sum by (cluster) (stddev_over_time({foo="bar"} |= "id=123" | logfmt | unwrap latency [5m]))`,
out: `sum by (cluster) (stddev_over_time({foo="bar"} |= "id=123" | logfmt | unwrap latency [5m]))`,
},
{
in: `
sum without (a) (
label_replace(
sum without (b) (
rate({foo="bar"}[5m])
),
"baz", "buz", "foo", "(.*)"
)
)
`,
out: `sum without(a)(label_replace(sum without(b)(downstream<sum without(b)(rate({foo="bar"}[5m])),shard=0_of_2>++downstream<sum without(b)(rate({foo="bar"}[5m])),shard=1_of_2>),"baz","buz","foo","(.*)"))`,
},
} {
t.Run(tc.in, func(t *testing.T) {
ast, err := ParseExpr(tc.in)
Expand Down