Skip to content

Commit

Permalink
Vertical shard binary expression using metric name when no matching l…
Browse files Browse the repository at this point in the history
…abel (#6605)

* vertically shard binary expression even if no matching labels

Signed-off-by: Ben Ye <benye@amazon.com>

* add changelog

Signed-off-by: Ben Ye <benye@amazon.com>

* fix test

Signed-off-by: Ben Ye <benye@amazon.com>

---------

Signed-off-by: Ben Ye <benye@amazon.com>
  • Loading branch information
yeya24 committed Aug 16, 2023
1 parent 553c061 commit 2b4f2a7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

### Added

- [#6605](https://github.com/thanos-io/thanos/pull/6605) Query Frontend: Support vertical sharding binary expression with metric name when no matching labels specified.

### Changed

### Removed
Expand Down
2 changes: 1 addition & 1 deletion pkg/querysharding/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (a *QueryAnalyzer) Analyze(query string) (QueryAnalysis, error) {
case *parser.BinaryExpr:
if n.VectorMatching != nil {
shardingLabels := without(n.VectorMatching.MatchingLabels, []string{"le"})
if !n.VectorMatching.On && len(shardingLabels) > 0 {
if !n.VectorMatching.On {
shardingLabels = append(shardingLabels, model.MetricNameLabel)
}
analysis = analysis.scopeToLabels(shardingLabels, n.VectorMatching.On)
Expand Down
30 changes: 21 additions & 9 deletions pkg/querysharding/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ func TestAnalyzeQuery(t *testing.T) {
name: "outer aggregation with without grouping",
expression: "count(sum without (pod) (http_requests_total))",
},
{
name: "binary expression",
expression: `http_requests_total{code="400"} / http_requests_total`,
},
{
name: "binary expression with constant",
expression: `http_requests_total{code="400"} / 4`,
Expand All @@ -48,10 +44,6 @@ func TestAnalyzeQuery(t *testing.T) {
name: "binary aggregation with different grouping labels",
expression: `sum by (pod) (http_requests_total{code="400"}) / sum by (cluster) (http_requests_total)`,
},
{
name: "multiple binary expressions",
expression: `(http_requests_total{code="400"} + http_requests_total{code="500"}) / http_requests_total`,
},
{
name: "multiple binary expressions with empty vector matchers",
expression: `
Expand Down Expand Up @@ -211,7 +203,7 @@ sum by (container) (
{
name: "binary expression with outer without grouping",
expression: `sum(http_requests_total{code="400"} * http_requests_total) without (pod)`,
shardingLabels: []string{"pod"},
shardingLabels: []string{"__name__", "pod"},
},
{
name: "binary expression with vector matching and outer without grouping",
Expand Down Expand Up @@ -256,6 +248,26 @@ http_requests_total`,
expression: `sum without (pod) (label_replace(metric, "dst_label", "$1", "src_label", "re"))`,
shardingLabels: []string{"pod", "dst_label"},
},
{
name: "binary expression",
expression: `http_requests_total{code="400"} / http_requests_total`,
shardingLabels: []string{model.MetricNameLabel},
},
{
name: "binary expression among vector and scalar",
expression: `aaaa - bbb > 1000`,
shardingLabels: []string{model.MetricNameLabel},
},
{
name: "binary expression with set operation",
expression: `aaaa and bbb`,
shardingLabels: []string{model.MetricNameLabel},
},
{
name: "multiple binary expressions",
expression: `(http_requests_total{code="400"} + http_requests_total{code="500"}) / http_requests_total`,
shardingLabels: []string{model.MetricNameLabel},
},
}

for _, test := range nonShardable {
Expand Down

0 comments on commit 2b4f2a7

Please sign in to comment.