From f6e660f9a9a90aabf6bd5d87a97d92dda89c3205 Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Fri, 23 Oct 2020 09:14:07 -0400 Subject: [PATCH 1/4] add a flag to disable step alignment middleware Signed-off-by: Ben Ye --- cmd/thanos/query_frontend.go | 3 +++ docs/components/query-frontend.md | 3 +++ pkg/queryfrontend/config.go | 1 + 3 files changed, 7 insertions(+) diff --git a/cmd/thanos/query_frontend.go b/cmd/thanos/query_frontend.go index 9286035b6e..2ee95e4fc5 100644 --- a/cmd/thanos/query_frontend.go +++ b/cmd/thanos/query_frontend.go @@ -57,6 +57,9 @@ func registerQueryFrontend(app *extkingpin.App) { cfg.http.registerFlag(cmd) // Query range tripperware flags. + cmd.Flag("query-range.align-querier-with-step", "Mutate incoming queries to align their start and end with their step."). + Default("true").BoolVar(&cfg.QueryRangeConfig.AlignQueriesWithStep) + 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) diff --git a/docs/components/query-frontend.md b/docs/components/query-frontend.md index f8bd6d0a81..812ec980df 100644 --- a/docs/components/query-frontend.md +++ b/docs/components/query-frontend.md @@ -126,6 +126,9 @@ Flags: Listen host:port for HTTP endpoints. --http-grace-period=2m Time to wait after an interrupt received for HTTP Server. + --query-range.align-querier-with-step + Mutate incoming queries to align their start + and end with their step. --query-range.split-interval=24h Split query range requests by an interval and execute in parallel, it should be greater than diff --git a/pkg/queryfrontend/config.go b/pkg/queryfrontend/config.go index 1f5cdd3264..a10134c6db 100644 --- a/pkg/queryfrontend/config.go +++ b/pkg/queryfrontend/config.go @@ -139,6 +139,7 @@ type QueryRangeConfig struct { ResultsCacheConfig *queryrange.ResultsCacheConfig CachePathOrContent extflag.PathOrContent + AlignQueriesWithStep bool SplitQueriesByInterval time.Duration MaxRetries int Limits *cortexvalidation.Limits From 0d0ae4f0ef92435654fdad76c84b5b0baeee5f7b Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Fri, 23 Oct 2020 09:18:43 -0400 Subject: [PATCH 2/4] add changelog Signed-off-by: Ben Ye --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45a2c90e53..d082e98efc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#3346](https://github.com/thanos-io/thanos/pull/3346) Ruler UI: Fix a bug preventing the /rules endpoint from loading. - [#3115](https://github.com/thanos-io/thanos/pull/3115) compact: now deletes partially uploaded and blocks with deletion marks concurrently. It does that at the beginning and then every `--compact.cleanup-interval` time period. By default it is 5 minutes. - [#3312](https://github.com/thanos-io/thanos/pull/3312) s3: add list_objects_version config option for compatibility. +- [#3356](https://github.com/thanos-io/thanos/pull/3356) Query Frontend: Add a flag to disable step alignment middleware for query range. ### Fixed - [#3257](https://github.com/thanos-io/thanos/pull/3257) Ruler: Prevent Ruler from crashing when using default DNS to lookup hosts that results in "No such hosts" errors. From 463f523abd351fae9215930015a059dc1fa7e12a Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Fri, 23 Oct 2020 10:03:44 -0400 Subject: [PATCH 3/4] add logic Signed-off-by: Ben Ye --- cmd/thanos/query_frontend.go | 4 ++-- docs/components/query-frontend.md | 6 ++++-- pkg/queryfrontend/config.go | 2 +- pkg/queryfrontend/roundtrip.go | 12 +++++++----- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cmd/thanos/query_frontend.go b/cmd/thanos/query_frontend.go index 2ee95e4fc5..8a97236969 100644 --- a/cmd/thanos/query_frontend.go +++ b/cmd/thanos/query_frontend.go @@ -57,8 +57,8 @@ func registerQueryFrontend(app *extkingpin.App) { cfg.http.registerFlag(cmd) // Query range tripperware flags. - cmd.Flag("query-range.align-querier-with-step", "Mutate incoming queries to align their start and end with their step."). - Default("true").BoolVar(&cfg.QueryRangeConfig.AlignQueriesWithStep) + cmd.Flag("query-range.align-range-with-step", "Mutate incoming queries to align their start and end with their step for better cache-ability. Note: Grafana dashboards do that by default."). + Default("true").BoolVar(&cfg.QueryRangeConfig.AlignRangeWithStep) 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) diff --git a/docs/components/query-frontend.md b/docs/components/query-frontend.md index 812ec980df..83451fcd03 100644 --- a/docs/components/query-frontend.md +++ b/docs/components/query-frontend.md @@ -126,9 +126,11 @@ Flags: Listen host:port for HTTP endpoints. --http-grace-period=2m Time to wait after an interrupt received for HTTP Server. - --query-range.align-querier-with-step + --query-range.align-range-with-step Mutate incoming queries to align their start - and end with their step. + and end with their step for better + cache-ability. Note: Grafana dashboards do that + by default. --query-range.split-interval=24h Split query range requests by an interval and execute in parallel, it should be greater than diff --git a/pkg/queryfrontend/config.go b/pkg/queryfrontend/config.go index a10134c6db..7c97c2f570 100644 --- a/pkg/queryfrontend/config.go +++ b/pkg/queryfrontend/config.go @@ -139,7 +139,7 @@ type QueryRangeConfig struct { ResultsCacheConfig *queryrange.ResultsCacheConfig CachePathOrContent extflag.PathOrContent - AlignQueriesWithStep bool + AlignRangeWithStep bool SplitQueriesByInterval time.Duration MaxRetries int Limits *cortexvalidation.Limits diff --git a/pkg/queryfrontend/roundtrip.go b/pkg/queryfrontend/roundtrip.go index 5190ae8db3..e31ae98846 100644 --- a/pkg/queryfrontend/roundtrip.go +++ b/pkg/queryfrontend/roundtrip.go @@ -144,11 +144,13 @@ func newQueryRangeTripperware( m := queryrange.NewInstrumentMiddlewareMetrics(reg) // step align middleware. - queryRangeMiddleware = append( - queryRangeMiddleware, - queryrange.InstrumentMiddleware("step_align", m), - queryrange.StepAlignMiddleware, - ) + if config.AlignRangeWithStep { + queryRangeMiddleware = append( + queryRangeMiddleware, + queryrange.InstrumentMiddleware("step_align", m), + queryrange.StepAlignMiddleware, + ) + } queryIntervalFn := func(_ queryrange.Request) time.Duration { return config.SplitQueriesByInterval From d65b7bf121a598addaeb55bd72c75ea60324219c Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Mon, 26 Oct 2020 09:22:59 -0400 Subject: [PATCH 4/4] fix lint Signed-off-by: Ben Ye --- pkg/queryfrontend/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/queryfrontend/config.go b/pkg/queryfrontend/config.go index 7c97c2f570..6f0550b46d 100644 --- a/pkg/queryfrontend/config.go +++ b/pkg/queryfrontend/config.go @@ -139,7 +139,7 @@ type QueryRangeConfig struct { ResultsCacheConfig *queryrange.ResultsCacheConfig CachePathOrContent extflag.PathOrContent - AlignRangeWithStep bool + AlignRangeWithStep bool SplitQueriesByInterval time.Duration MaxRetries int Limits *cortexvalidation.Limits