diff --git a/CHANGELOG.md b/CHANGELOG.md index b249dd62ab..a307d42bf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ## Unreleased - [#3261](https://github.com/thanos-io/thanos/pull/3261) Thanos Store: Use segment files specified in meta.json file, if present. If not present, Store does the LIST operation as before. +- [#3276](https://github.com/thanos-io/thanos/pull/3276) Query Frontend: Support query splitting and retry for labels and series requests. ## [v0.16.0](https://github.com/thanos-io/thanos/releases) - Release in progress diff --git a/cmd/thanos/query_frontend.go b/cmd/thanos/query_frontend.go index dffbe21899..09f09aa165 100644 --- a/cmd/thanos/query_frontend.go +++ b/cmd/thanos/query_frontend.go @@ -56,39 +56,46 @@ func registerQueryFrontend(app *extkingpin.App) { cfg.http.registerFlag(cmd) + // Query range tripperware flags. cmd.Flag("query-range.split-interval", "Split query range requests by an interval and execute in parallel, it should be greater than 0 when query-range.response-cache-config is configured."). Default("24h").DurationVar(&cfg.QueryRangeConfig.SplitQueriesByInterval) - cmd.Flag("labels.split-interval", "Split labels requests by an interval and execute in parallel, it should be greater than 0 when labels.response-cache-config is configured."). - Default("24h").DurationVar(&cfg.LabelsConfig.SplitQueriesByInterval) cmd.Flag("query-range.max-retries-per-request", "Maximum number of retries for a single query range request; beyond this, the downstream error is returned."). Default("5").IntVar(&cfg.QueryRangeConfig.MaxRetries) - cmd.Flag("labels.max-retries-per-request", "Maximum number of retries for a single label/series API request; beyond this, the downstream error is returned."). - Default("5").IntVar(&cfg.LabelsConfig.MaxRetries) cmd.Flag("query-range.max-query-length", "Limit the query time range (end - start time) in the query-frontend, 0 disables it."). Default("0").DurationVar(&cfg.QueryRangeConfig.Limits.MaxQueryLength) cmd.Flag("query-range.max-query-parallelism", "Maximum number of query range requests will be scheduled in parallel by the Frontend."). Default("14").IntVar(&cfg.QueryRangeConfig.Limits.MaxQueryParallelism) - cmd.Flag("labels.max-query-parallelism", "Maximum number of labels requests will be scheduled in parallel by the Frontend."). - Default("14").IntVar(&cfg.LabelsConfig.Limits.MaxQueryParallelism) cmd.Flag("query-range.response-cache-max-freshness", "Most recent allowed cacheable result for query range requests, to prevent caching very recent results that might still be in flux."). Default("1m").DurationVar(&cfg.QueryRangeConfig.Limits.MaxCacheFreshness) - cmd.Flag("labels.response-cache-max-freshness", "Most recent allowed cacheable result for labels requests, to prevent caching very recent results that might still be in flux."). - Default("1m").DurationVar(&cfg.LabelsConfig.Limits.MaxCacheFreshness) cmd.Flag("query-range.partial-response", "Enable partial response for query range requests if no partial_response param is specified. --no-query-range.partial-response for disabling."). Default("true").BoolVar(&cfg.QueryRangeConfig.PartialResponseStrategy) + + cfg.QueryRangeConfig.CachePathOrContent = *extflag.RegisterPathOrContent(cmd, "query-range.response-cache-config", "YAML file that contains response cache configuration.", false) + + // Labels tripperware flags. + cmd.Flag("labels.split-interval", "Split labels requests by an interval and execute in parallel, it should be greater than 0 when labels.response-cache-config is configured."). + Default("24h").DurationVar(&cfg.LabelsConfig.SplitQueriesByInterval) + + cmd.Flag("labels.max-retries-per-request", "Maximum number of retries for a single label/series API request; beyond this, the downstream error is returned."). + Default("5").IntVar(&cfg.LabelsConfig.MaxRetries) + + cmd.Flag("labels.max-query-parallelism", "Maximum number of labels requests will be scheduled in parallel by the Frontend."). + Default("14").IntVar(&cfg.LabelsConfig.Limits.MaxQueryParallelism) + + cmd.Flag("labels.response-cache-max-freshness", "Most recent allowed cacheable result for labels requests, to prevent caching very recent results that might still be in flux."). + Default("1m").DurationVar(&cfg.LabelsConfig.Limits.MaxCacheFreshness) + cmd.Flag("labels.partial-response", "Enable partial response for labels requests if no partial_response param is specified. --no-labels.partial-response for disabling."). Default("true").BoolVar(&cfg.LabelsConfig.PartialResponseStrategy) cmd.Flag("labels.default-time-range", "The default metadata time range duration for retrieving labels through Labels and Series API when the range parameters are not specified."). Default("24h").DurationVar(&cfg.DefaultTimeRange) - cfg.QueryRangeConfig.CachePathOrContent = *extflag.RegisterPathOrContent(cmd, "query-range.response-cache-config", "YAML file that contains response cache configuration.", false) - cmd.Flag("cache-compression-type", "Use compression in results cache. Supported values are: 'snappy' and '' (disable compression)."). Default("").StringVar(&cfg.CacheCompression) diff --git a/docs/components/query-frontend.md b/docs/components/query-frontend.md index 0d36aad61f..18a0e37416 100644 --- a/docs/components/query-frontend.md +++ b/docs/components/query-frontend.md @@ -126,48 +126,25 @@ Flags: execute in parallel, it should be greater than 0 when query-range.response-cache-config is configured. - --labels.split-interval=24h - Split labels requests by an interval and - execute in parallel, it should be greater than - 0 when labels.response-cache-config is - configured. --query-range.max-retries-per-request=5 Maximum number of retries for a single query range request; beyond this, the downstream error is returned. - --labels.max-retries-per-request=5 - Maximum number of retries for a single - label/series API request; beyond this, the - downstream error is returned. --query-range.max-query-length=0 Limit the query time range (end - start time) in the query-frontend, 0 disables it. --query-range.max-query-parallelism=14 Maximum number of query range requests will be scheduled in parallel by the Frontend. - --labels.max-query-parallelism=14 - Maximum number of labels requests will be - scheduled in parallel by the Frontend. --query-range.response-cache-max-freshness=1m Most recent allowed cacheable result for query range requests, to prevent caching very recent results that might still be in flux. - --labels.response-cache-max-freshness=1m - Most recent allowed cacheable result for labels - requests, to prevent caching very recent - results that might still be in flux. --query-range.partial-response Enable partial response for query range requests if no partial_response param is specified. --no-query-range.partial-response for disabling. - --labels.partial-response Enable partial response for labels requests if - no partial_response param is specified. - --no-labels.partial-response for disabling. - --labels.default-time-range=24h - The default metadata time range duration for - retrieving labels through Labels and Series API - when the range parameters are not specified. --query-range.response-cache-config-file= Path to YAML file that contains response cache configuration. @@ -176,6 +153,29 @@ Flags: 'query-range.response-cache-config-file' flag (lower priority). Content of YAML file that contains response cache configuration. + --labels.split-interval=24h + Split labels requests by an interval and + execute in parallel, it should be greater than + 0 when labels.response-cache-config is + configured. + --labels.max-retries-per-request=5 + Maximum number of retries for a single + label/series API request; beyond this, the + downstream error is returned. + --labels.max-query-parallelism=14 + Maximum number of labels requests will be + scheduled in parallel by the Frontend. + --labels.response-cache-max-freshness=1m + Most recent allowed cacheable result for labels + requests, to prevent caching very recent + results that might still be in flux. + --labels.partial-response Enable partial response for labels requests if + no partial_response param is specified. + --no-labels.partial-response for disabling. + --labels.default-time-range=24h + The default metadata time range duration for + retrieving labels through Labels and Series API + when the range parameters are not specified. --cache-compression-type="" Use compression in results cache. Supported values are: 'snappy' and ” (disable diff --git a/pkg/queryfrontend/request.go b/pkg/queryfrontend/request.go index 915c2756cd..2074815ac6 100644 --- a/pkg/queryfrontend/request.go +++ b/pkg/queryfrontend/request.go @@ -13,6 +13,8 @@ import ( "github.com/prometheus/prometheus/pkg/timestamp" ) +// TODO(yeya24): add partial result when needed. +// ThanosRequest is a common interface defined for specific thanos requests. type ThanosRequest interface { GetStoreMatchers() [][]*labels.Matcher } diff --git a/pkg/queryfrontend/roundtrip.go b/pkg/queryfrontend/roundtrip.go index 92b2dbf4a0..1ca3f857bc 100644 --- a/pkg/queryfrontend/roundtrip.go +++ b/pkg/queryfrontend/roundtrip.go @@ -66,7 +66,7 @@ func NewTripperware(config Config, reg prometheus.Registerer, logger log.Logger) } type roundTripper struct { - next, queryRange, metadata http.RoundTripper + next, queryRange, labels http.RoundTripper queriesCount *prometheus.CounterVec } @@ -75,7 +75,7 @@ func newRoundTripper(next, queryRange, metadata http.RoundTripper, reg prometheu r := roundTripper{ next: next, queryRange: queryRange, - metadata: metadata, + labels: metadata, queriesCount: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{ Name: "thanos_query_frontend_queries_total", Help: "Total queries passing through query frontend", @@ -99,7 +99,7 @@ func (r roundTripper) RoundTrip(req *http.Request) (*http.Response, error) { return r.queryRange.RoundTrip(req) case labelNamesOp, labelValuesOp, seriesOp: r.queriesCount.WithLabelValues(op).Inc() - return r.metadata.RoundTrip(req) + return r.labels.RoundTrip(req) default: }