From 9747f531fd3772d8a65b4ff6aaec38ec9e9581bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Mon, 17 Jun 2024 12:36:15 +0200 Subject: [PATCH] Make extra middleware injection more specific MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make it more explicit that injection is only applied to instance and range queries. Follows #8342 Related to https://github.com/grafana/mimir-squad/issues/2148 Signed-off-by: György Krajcsovits --- pkg/frontend/querymiddleware/roundtrip.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/frontend/querymiddleware/roundtrip.go b/pkg/frontend/querymiddleware/roundtrip.go index bff3630dd6f..b377ba3fd7a 100644 --- a/pkg/frontend/querymiddleware/roundtrip.go +++ b/pkg/frontend/querymiddleware/roundtrip.go @@ -73,10 +73,13 @@ type Config struct { // If nil, the querymiddleware package uses a DefaultCacheKeyGenerator with SplitQueriesByInterval. CacheKeyGenerator CacheKeyGenerator `yaml:"-"` - // ExtraMiddlewares allows to inject custom middlewares into the middleware chain. - // These middlewares will be placed right after default middlewares and before the query sharding middleware, - // in order to avoid interfering with core functionality. - ExtraMiddlewares []MetricsQueryMiddleware `yaml:"-"` + // ExtraInstantQueryMiddlewares and ExtraRangeQueryMiddlewares allows to + // inject custom middlewares into the middleware chain of instant and + // range queries. These middlewares will be placed right after default + // middlewares and before the query sharding middleware, in order to avoid + // interfering with core functionality. + ExtraInstantQueryMiddlewares []MetricsQueryMiddleware `yaml:"-"` + ExtraRangeQueryMiddlewares []MetricsQueryMiddleware `yaml:"-"` QueryResultResponseFormat string `yaml:"query_result_response_format"` } @@ -348,9 +351,13 @@ func newQueryMiddlewares( queryBlockerMiddleware, ) - if len(cfg.ExtraMiddlewares) > 0 { - queryRangeMiddleware = append(queryRangeMiddleware, cfg.ExtraMiddlewares...) - queryInstantMiddleware = append(queryInstantMiddleware, cfg.ExtraMiddlewares...) + // Inject the extra middlewares provided by the user before the query sharding middleware. + if len(cfg.ExtraInstantQueryMiddlewares) > 0 { + queryInstantMiddleware = append(queryInstantMiddleware, cfg.ExtraInstantQueryMiddlewares...) + } + // Inject the extra middlewares provided by the user before the query sharding middleware. + if len(cfg.ExtraRangeQueryMiddlewares) > 0 { + queryRangeMiddleware = append(queryRangeMiddleware, cfg.ExtraRangeQueryMiddlewares...) } if cfg.ShardedQueries {