From 4438bb36fef0835a24f1bc0ea59c1647de2acb02 Mon Sep 17 00:00:00 2001 From: Filip Petkovski Date: Wed, 20 Jul 2022 12:58:43 +0200 Subject: [PATCH] Add test for binary expression with constant Signed-off-by: Filip Petkovski --- cmd/thanos/query_frontend.go | 2 +- docs/components/query-frontend.md | 9 ++++++--- pkg/querysharding/analyzer.go | 4 +++- pkg/querysharding/analyzer_test.go | 4 ++++ test/e2e/e2ethanos/services.go | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cmd/thanos/query_frontend.go b/cmd/thanos/query_frontend.go index 5857a4a3d03..e9eee5966a0 100644 --- a/cmd/thanos/query_frontend.go +++ b/cmd/thanos/query_frontend.go @@ -135,7 +135,7 @@ func registerQueryFrontend(app *extkingpin.App) { cmd.Flag("query-frontend.forward-header", "List of headers forwarded by the query-frontend to downstream queriers, default is empty").PlaceHolder("").StringsVar(&cfg.ForwardHeaders) - cmd.Flag("query-frontend.num-shards", "Number of queriers to use when sharding PromQL queries").IntVar(&cfg.NumShards) + cmd.Flag("query-frontend.vertical-shards", "Number of shards to use when distributing shardable PromQL queries. For more details, you can refer to the Vertical query sharding proposal: https://thanos.io/tip/proposals-accepted/202205-vertical-query-sharding.md").IntVar(&cfg.NumShards) cmd.Flag("log.request.decision", "Deprecation Warning - This flag would be soon deprecated, and replaced with `request.logging-config`. Request Logging for logging the start and end of requests. By default this flag is disabled. LogFinishCall : Logs the finish call of the requests. LogStartAndFinishCall : Logs the start and finish call of the requests. NoLogCall : Disable request logging.").Default("").EnumVar(&cfg.RequestLoggingDecision, "NoLogCall", "LogFinishCall", "LogStartAndFinishCall", "") reqLogConfig := extkingpin.RegisterRequestLoggingFlags(cmd) diff --git a/docs/components/query-frontend.md b/docs/components/query-frontend.md index fd66e708379..044f87ce761 100644 --- a/docs/components/query-frontend.md +++ b/docs/components/query-frontend.md @@ -261,9 +261,6 @@ Flags: Log queries that are slower than the specified duration. Set to 0 to disable. Set to < 0 to enable on all queries. - --query-frontend.num-shards=QUERY-FRONTEND.NUM-SHARDS - Number of queriers to use when sharding PromQL - queries --query-frontend.org-id-header= ... Request header names used to identify the source of slow queries (repeated flag). The @@ -272,6 +269,12 @@ Flags: headers match the request, the first matching arg specified will take precedence. If no headers match 'anonymous' will be used. + --query-frontend.vertical-shards=QUERY-FRONTEND.VERTICAL-SHARDS + Number of shards to use when distributing + shardable PromQL queries. For more details, you + can refer to the Vertical query sharding + proposal: + https://thanos.io/tip/proposals-accepted/202205-vertical-query-sharding.md --query-range.align-range-with-step Mutate incoming queries to align their start and end with their step for better diff --git a/pkg/querysharding/analyzer.go b/pkg/querysharding/analyzer.go index b0e5538efae..233f3b74c51 100644 --- a/pkg/querysharding/analyzer.go +++ b/pkg/querysharding/analyzer.go @@ -54,7 +54,9 @@ func (a *QueryAnalyzer) Analyze(query string) (QueryAnalysis, error) { return fmt.Errorf("expressions with %s are not shardable", n.Func.Name) } case *parser.BinaryExpr: - analysis = analysis.scopeToLabels(n.VectorMatching.MatchingLabels, n.VectorMatching.On) + if n.VectorMatching != nil { + analysis = analysis.scopeToLabels(n.VectorMatching.MatchingLabels, n.VectorMatching.On) + } case *parser.AggregateExpr: labels := make([]string, 0) if len(n.Grouping) > 0 { diff --git a/pkg/querysharding/analyzer_test.go b/pkg/querysharding/analyzer_test.go index 9dbb9c948db..d34e7b29e43 100644 --- a/pkg/querysharding/analyzer_test.go +++ b/pkg/querysharding/analyzer_test.go @@ -42,6 +42,10 @@ func TestAnalyzeQuery(t *testing.T) { name: "binary expression", expression: `http_requests_total{code="400"} / http_requests_total`, }, + { + name: "binary expression with constant", + expression: `http_requests_total{code="400"} / 4`, + }, { name: "binary expression with empty vector matching", expression: `http_requests_total{code="400"} / on () http_requests_total`, diff --git a/test/e2e/e2ethanos/services.go b/test/e2e/e2ethanos/services.go index c8051d38787..d39055ee516 100644 --- a/test/e2e/e2ethanos/services.go +++ b/test/e2e/e2ethanos/services.go @@ -738,7 +738,7 @@ func NewQueryFrontend(e e2e.Environment, name, downstreamURL string, config quer } if config.NumShards > 0 { - flags["--query-frontend.num-shards"] = strconv.Itoa(config.NumShards) + flags["--query-frontend.vertical-shards"] = strconv.Itoa(config.NumShards) } return e2e.NewInstrumentedRunnable(