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

Shard subqueries #5846

Merged
merged 2 commits into from
Nov 2, 2022
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
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