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

Remove hardcoded labels in store shard matcher and inject unshardable label in query analyzer #5641

Merged
merged 2 commits into from
Sep 26, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#5255](https://github.com/thanos-io/thanos/pull/5296) Query: Use k-way merging for the proxying logic. The proxying sub-system now uses much less resources (~25-80% less CPU usage, ~30-50% less RAM usage according to our benchmarks). Reduces query duration by a few percent on queries with lots of series.
- [#5690](https://github.com/thanos-io/thanos/pull/5690) Compact: update `--debug.accept-malformed-index` flag to apply to downsampling. Previously the flag only applied to compaction, and fatal errors would still occur when downsampling was attempted.
- [#5707](https://github.com/thanos-io/thanos/pull/5707) Objstore: Update objstore to latest version which includes a refactored Azure Storage Account implementation with a new SDK.
- [#5641](https://github.com/thanos-io/thanos/pull/5641) Store: Remove hardcoded labels in shard matcher.
- [#5641](https://github.com/thanos-io/thanos/pull/5641) Query: Inject unshardable le label in query analyzer.
- [#5685](https://github.com/thanos-io/thanos/pull/5685) Receive: Make active/head series limiting configuration per tenant by adding it to new limiting config.

### Removed
Expand Down
17 changes: 10 additions & 7 deletions pkg/querysharding/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func NewQueryAnalyzer() *QueryAnalyzer {
// used in grouping expressions. If non-empty, treat the query
// as shardable by those labels.
// * otherwise, treat the query as non-shardable.
// The le label is excluded from sharding.
func (a *QueryAnalyzer) Analyze(query string) (QueryAnalysis, error) {
expr, err := parser.ParseExpr(query)
if err != nil {
Expand All @@ -55,15 +56,15 @@ func (a *QueryAnalyzer) Analyze(query string) (QueryAnalysis, error) {
}
case *parser.BinaryExpr:
if n.VectorMatching != nil {
analysis = analysis.scopeToLabels(n.VectorMatching.MatchingLabels, n.VectorMatching.On)
shardingLabels := without(n.VectorMatching.MatchingLabels, []string{"le"})
analysis = analysis.scopeToLabels(shardingLabels, n.VectorMatching.On)
}
case *parser.AggregateExpr:
labels := make([]string, 0)
haanhvu marked this conversation as resolved.
Show resolved Hide resolved
shardingLabels := make([]string, 0)
if len(n.Grouping) > 0 {
labels = n.Grouping
shardingLabels = without(n.Grouping, []string{"le"})
}

analysis = analysis.scopeToLabels(labels, !n.Without)
analysis = analysis.scopeToLabels(shardingLabels, !n.Without)
}

return nil
Expand All @@ -85,7 +86,8 @@ func analyzeRootExpression(node parser.Node) QueryAnalysis {
switch n := node.(type) {
case *parser.BinaryExpr:
if n.VectorMatching != nil && n.VectorMatching.On {
return newShardableByLabels(n.VectorMatching.MatchingLabels, n.VectorMatching.On)
shardingLabels := without(n.VectorMatching.MatchingLabels, []string{"le"})
return newShardableByLabels(shardingLabels, n.VectorMatching.On)
} else {
return nonShardableQuery()
}
Expand All @@ -94,7 +96,8 @@ func analyzeRootExpression(node parser.Node) QueryAnalysis {
return nonShardableQuery()
}

return newShardableByLabels(n.Grouping, !n.Without)
shardingLabels := without(n.Grouping, []string{"le"})
return newShardableByLabels(shardingLabels, !n.Without)
}

return nonShardableQuery()
Expand Down
5 changes: 5 additions & 0 deletions pkg/querysharding/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ sum by (container) (
http_requests_total`,
shardingLabels: []string{"cluster", "pod"},
},
{
name: "histogram quantile",
expression: "histogram_quantile(0.95, sum(rate(metric[1m])) without (le, cluster))",
shardingLabels: []string{"cluster"},
},
}

for _, test := range nonShardable {
Expand Down
5 changes: 0 additions & 5 deletions pkg/store/storepb/shard_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ func (s *ShardMatcher) MatchesZLabels(zLabels []labelpb.ZLabel) bool {

*s.buf = (*s.buf)[:0]
for _, lbl := range zLabels {
// Exclude metric name and le label from sharding
if lbl.Name == "__name__" || lbl.Name == "le" {
continue
}

if shardByLabel(s.shardingLabelset, lbl, s.by) {
*s.buf = append(*s.buf, lbl.Name...)
*s.buf = append(*s.buf, sep[0])
Expand Down