From 18aa8859451d53663f998f99620ee91838a2b94e Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Thu, 4 Jul 2024 10:13:54 +0200 Subject: [PATCH 1/2] feat(loki): Do not enforce max-query-bytes-read and max-querier-bytes-read in limited tripperware --- docs/sources/shared/configuration.md | 7 ++++--- pkg/querier/queryrange/roundtrip.go | 8 ++------ pkg/validation/limits.go | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/docs/sources/shared/configuration.md b/docs/sources/shared/configuration.md index 1420e4ad373c..9d07d3cf89f8 100644 --- a/docs/sources/shared/configuration.md +++ b/docs/sources/shared/configuration.md @@ -3504,13 +3504,14 @@ The `limits_config` block configures global and per-tenant limits in Loki. The v [min_sharding_lookback: | default = 0s] # Max number of bytes a query can fetch. Enforced in log and metric queries only -# when TSDB is used. The default value of 0 disables this limit. +# when TSDB is used. This limit is not enforced on log queries without filters. +# The default value of 0 disables this limit. # CLI flag: -frontend.max-query-bytes-read [max_query_bytes_read: | default = 0B] # Max number of bytes a query can fetch after splitting and sharding. Enforced -# in log and metric queries only when TSDB is used. The default value of 0 -# disables this limit. +# in log and metric queries only when TSDB is used. This limit is not enforced +# on log queries without filters. The default value of 0 disables this limit. # CLI flag: -frontend.max-querier-bytes-read [max_querier_bytes_read: | default = 150GB] diff --git a/pkg/querier/queryrange/roundtrip.go b/pkg/querier/queryrange/roundtrip.go index 1e163927cb2e..0c3c058aa68a 100644 --- a/pkg/querier/queryrange/roundtrip.go +++ b/pkg/querier/queryrange/roundtrip.go @@ -206,7 +206,7 @@ func NewMiddleware( return nil, nil, err } - limitedTripperware, err := NewLimitedTripperware(cfg, engineOpts, log, limits, schema, metrics, indexStatsTripperware, codec, iqo, metricsNamespace) + limitedTripperware, err := NewLimitedTripperware(cfg, log, limits, schema, metrics, indexStatsTripperware, codec, iqo, metricsNamespace) if err != nil { return nil, nil, err } @@ -617,17 +617,13 @@ func NewLogFilterTripperware(cfg Config, engineOpts logql.EngineOpts, log log.Lo } // NewLimitedTripperware creates a new frontend tripperware responsible for handling log requests which are label matcher only, no filter expression. -func NewLimitedTripperware(cfg Config, engineOpts logql.EngineOpts, log log.Logger, limits Limits, schema config.SchemaConfig, metrics *Metrics, indexStatsTripperware base.Middleware, merger base.Merger, iqo util.IngesterQueryOptions, metricsNamespace string) (base.Middleware, error) { +func NewLimitedTripperware(cfg Config, log log.Logger, limits Limits, schema config.SchemaConfig, metrics *Metrics, indexStatsTripperware base.Middleware, merger base.Merger, iqo util.IngesterQueryOptions, metricsNamespace string) (base.Middleware, error) { return base.MiddlewareFunc(func(next base.Handler) base.Handler { - statsHandler := indexStatsTripperware.Wrap(next) - queryRangeMiddleware := []base.Middleware{ StatsCollectorMiddleware(), NewLimitsMiddleware(limits), - NewQuerySizeLimiterMiddleware(schema.Configs, engineOpts, log, limits, statsHandler), base.InstrumentMiddleware("split_by_interval", metrics.InstrumentMiddlewareMetrics), SplitByIntervalMiddleware(schema.Configs, WithMaxParallelism(limits, limitedQuerySplits), merger, newDefaultSplitter(limits, iqo), metrics.SplitByMetrics), - NewQuerierSizeLimiterMiddleware(schema.Configs, engineOpts, log, limits, statsHandler), } if cfg.MaxRetries > 0 { queryRangeMiddleware = append( diff --git a/pkg/validation/limits.go b/pkg/validation/limits.go index 96a0f515e16d..efeb7d2cb5ae 100644 --- a/pkg/validation/limits.go +++ b/pkg/validation/limits.go @@ -318,10 +318,10 @@ func (l *Limits) RegisterFlags(f *flag.FlagSet) { _ = l.MinShardingLookback.Set("0s") f.Var(&l.MinShardingLookback, "frontend.min-sharding-lookback", "Limit queries that can be sharded. Queries within the time range of now and now minus this sharding lookback are not sharded. The default value of 0s disables the lookback, causing sharding of all queries at all times.") - f.Var(&l.MaxQueryBytesRead, "frontend.max-query-bytes-read", "Max number of bytes a query can fetch. Enforced in log and metric queries only when TSDB is used. The default value of 0 disables this limit.") + f.Var(&l.MaxQueryBytesRead, "frontend.max-query-bytes-read", "Max number of bytes a query can fetch. Enforced in log and metric queries only when TSDB is used. This limit is not enforced on log queries without filters. The default value of 0 disables this limit.") _ = l.MaxQuerierBytesRead.Set("150GB") - f.Var(&l.MaxQuerierBytesRead, "frontend.max-querier-bytes-read", "Max number of bytes a query can fetch after splitting and sharding. Enforced in log and metric queries only when TSDB is used. The default value of 0 disables this limit.") + f.Var(&l.MaxQuerierBytesRead, "frontend.max-querier-bytes-read", "Max number of bytes a query can fetch after splitting and sharding. Enforced in log and metric queries only when TSDB is used. This limit is not enforced on log queries without filters. The default value of 0 disables this limit.") _ = l.MaxCacheFreshness.Set("10m") f.Var(&l.MaxCacheFreshness, "frontend.max-cache-freshness", "Most recent allowed cacheable result per-tenant, to prevent caching very recent results that might still be in flux.") From 194924abc108930937988e36adfeb377e22fc214 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Thu, 4 Jul 2024 10:37:42 +0200 Subject: [PATCH 2/2] fix lint --- pkg/querier/queryrange/roundtrip.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/querier/queryrange/roundtrip.go b/pkg/querier/queryrange/roundtrip.go index 0c3c058aa68a..50b6b18c96a8 100644 --- a/pkg/querier/queryrange/roundtrip.go +++ b/pkg/querier/queryrange/roundtrip.go @@ -206,7 +206,7 @@ func NewMiddleware( return nil, nil, err } - limitedTripperware, err := NewLimitedTripperware(cfg, log, limits, schema, metrics, indexStatsTripperware, codec, iqo, metricsNamespace) + limitedTripperware, err := NewLimitedTripperware(cfg, log, limits, schema, metrics, codec, iqo, metricsNamespace) if err != nil { return nil, nil, err } @@ -617,7 +617,7 @@ func NewLogFilterTripperware(cfg Config, engineOpts logql.EngineOpts, log log.Lo } // NewLimitedTripperware creates a new frontend tripperware responsible for handling log requests which are label matcher only, no filter expression. -func NewLimitedTripperware(cfg Config, log log.Logger, limits Limits, schema config.SchemaConfig, metrics *Metrics, indexStatsTripperware base.Middleware, merger base.Merger, iqo util.IngesterQueryOptions, metricsNamespace string) (base.Middleware, error) { +func NewLimitedTripperware(cfg Config, log log.Logger, limits Limits, schema config.SchemaConfig, metrics *Metrics, merger base.Merger, iqo util.IngesterQueryOptions, metricsNamespace string) (base.Middleware, error) { return base.MiddlewareFunc(func(next base.Handler) base.Handler { queryRangeMiddleware := []base.Middleware{ StatsCollectorMiddleware(),