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

Fix sharding behavior for vector matches #5799

Merged
merged 2 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions pkg/querysharding/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ 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 {
shardingLabels = append(shardingLabels, "__name__")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: let's use model.MetricNameLabel.

}
analysis = analysis.scopeToLabels(shardingLabels, n.VectorMatching.On)
}
case *parser.AggregateExpr:
Expand Down
6 changes: 3 additions & 3 deletions pkg/querysharding/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,20 @@ sum by (container) (
{
name: "binary expression with without vector matching and grouping",
expression: `sum without (cluster, pod) (http_requests_total{code="400"}) / ignoring (pod) sum without (cluster, pod) (http_requests_total)`,
shardingLabels: []string{"pod", "cluster"},
shardingLabels: []string{"pod", "cluster", "__name__"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just updated these

},
{
name: "multiple binary expressions with without grouping",
expression: `(http_requests_total{code="400"} + ignoring (pod) http_requests_total{code="500"}) / ignoring (cluster, pod) http_requests_total`,
shardingLabels: []string{"cluster", "pod"},
shardingLabels: []string{"cluster", "pod", "__name__"},
},
{
name: "multiple binary expressions with without vector matchers",
expression: `
(http_requests_total{code="400"} + ignoring (cluster, pod) http_requests_total{code="500"})
/ ignoring (pod)
http_requests_total`,
shardingLabels: []string{"cluster", "pod"},
shardingLabels: []string{"cluster", "pod", "__name__"},
},
{
name: "histogram quantile",
Expand Down