Skip to content

Commit

Permalink
Shard subqueries (#5846)
Browse files Browse the repository at this point in the history
* shard subqueries

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

* update changelog

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

Signed-off-by: Ben Ye <benye@amazon.com>
  • Loading branch information
yeya24 authored Nov 2, 2022
1 parent 5898fb8 commit 50b4156
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
### Changed

- [#5716](https://github.com/thanos-io/thanos/pull/5716) DNS: Fix miekgdns resolver LookupSRV to work with CNAME records.
- [#5846](https://github.com/thanos-io/thanos/pull/5846) Query Frontend: vertical query sharding supports subqueries.

### Removed

Expand Down
3 changes: 0 additions & 3 deletions pkg/querysharding/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ func (a *QueryAnalyzer) Analyze(query string) (QueryAnalysis, error) {
var analysis QueryAnalysis
parser.Inspect(expr, func(node parser.Node, nodes []parser.Node) error {
switch n := node.(type) {
case *parser.SubqueryExpr:
isShardable = false
return fmt.Errorf("expressions with subqueries are not shardable")
case *parser.Call:
if n.Func != nil && contains(n.Func.Name, nonShardableFuncs) {
isShardable = false
Expand Down
16 changes: 13 additions & 3 deletions pkg/querysharding/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func TestAnalyzeQuery(t *testing.T) {
expression: "count(sum without (pod) (http_requests_total))",
},
{
name: "aggregate expression with subquery",
name: "aggregate expression with label_replace",
expression: `sum by (pod) (label_replace(metric, "dst_label", "$1", "src_label", "re"))`,
},
{
name: "aggregate without expression with subquery",
name: "aggregate without expression with label_replace",
expression: `sum without (pod) (label_replace(metric, "dst_label", "$1", "src_label", "re"))`,
},
{
Expand All @@ -57,7 +57,7 @@ func TestAnalyzeQuery(t *testing.T) {
expression: `sum by (pod) (http_requests_total{code="400"}) / sum by (cluster) (http_requests_total)`,
},
{
name: "binary expression with vector matching and subquery",
name: "binary expression with vector matching and label_replace",
expression: `http_requests_total{code="400"} / on (pod) label_replace(metric, "dst_label", "$1", "src_label", "re")`,
},
{
Expand Down Expand Up @@ -127,6 +127,16 @@ sum by (container) (
expression: "histogram_quantile(0.95, sum(rate(metric[1m])) by (le, cluster))",
shardingLabels: []string{"cluster"},
},
{
name: "subquery",
expression: "sum(http_requests_total) by (pod, cluster) [1h:1m]",
shardingLabels: []string{"cluster", "pod"},
},
{
name: "subquery with function",
expression: "increase(sum(http_requests_total) by (pod, cluster) [1h:1m])",
shardingLabels: []string{"cluster", "pod"},
},
}

shardableWithoutLabels := []testCase{
Expand Down

0 comments on commit 50b4156

Please sign in to comment.