Skip to content

Commit

Permalink
Add test for binary expression with constant
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Petkovski <[email protected]>
  • Loading branch information
fpetkovski committed Jul 20, 2022
1 parent 82cd69f commit 9e4c35f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/thanos/query_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("<http-header-name>").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)
Expand Down
9 changes: 6 additions & 3 deletions docs/components/query-frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<http-header-name> ...
Request header names used to identify the
source of slow queries (repeated flag). The
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/querysharding/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/querysharding/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/e2ethanos/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9e4c35f

Please sign in to comment.