Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make extra middleware injection more specific #8396

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions pkg/frontend/querymiddleware/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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 {
Expand Down
Loading