From 1dfd8ea42217d74b9a98304fc397efe7d1b8c5a2 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Thu, 24 Aug 2023 10:32:36 +0200 Subject: [PATCH] Enforce -validation.create-grace-period in the query-frontend when the configured value is 0 Signed-off-by: Marco Pracucci --- CHANGELOG.md | 1 + pkg/frontend/querymiddleware/limits.go | 22 ++++++++++----------- pkg/frontend/querymiddleware/limits_test.go | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28698dc4fd9..6201f4a5ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * [CHANGE] The `-shutdown-delay` flag is no longer experimental. #5701 * [CHANGE] The `-validation.create-grace-period` is now enforced in the ingester too, other than distributor and query-frontend. If you've configured `-validation.create-grace-period` then make sure the configuration is applied to ingesters too. #5712 * [CHANGE] The `-validation.create-grace-period` is now enforced for examplars too in the distributor. If an examplar has timestamp greater than "now + grace_period", then the exemplar will be dropped and the metric `cortex_discarded_exemplars_total{reason="exemplar_too_far_in_future",user="..."}` increased. #5761 +* [CHANGE] The `-validation.create-grace-period` is now enforced in the query-frontend even when the configured value is 0. When the value is 0, the query end time range is truncated to the current real-world time. #5829 * [CHANGE] Store-gateway: deprecate configuration parameters for index header under `blocks-storage.bucket-store` and use a new configurations in `blocks-storage.bucket-store.index-header`, deprecated configuration will be removed in Mimir 2.12. Configuration changes: #5726 * `-blocks-storage.bucket-store.index-header-lazy-loading-enabled` is deprecated, use the new configuration `-blocks-storage.bucket-store.index-header.lazy-loading-enabled` * `-blocks-storage.bucket-store.index-header-lazy-loading-idle-timeout` is deprecated, use the new configuration `-blocks-storage.bucket-store.index-header.lazy-loading-idle-timeout` diff --git a/pkg/frontend/querymiddleware/limits.go b/pkg/frontend/querymiddleware/limits.go index 21de249bb4f..9f22114a51a 100644 --- a/pkg/frontend/querymiddleware/limits.go +++ b/pkg/frontend/querymiddleware/limits.go @@ -156,18 +156,16 @@ func (l limitsMiddleware) Do(ctx context.Context, r Request) (Response, error) { // Enforce the max end time. creationGracePeriod := validation.LargestPositiveNonZeroDurationPerTenant(tenantIDs, l.CreationGracePeriod) - if creationGracePeriod > 0 { - maxEndTime := util.TimeToMillis(time.Now().Add(creationGracePeriod)) - if r.GetEnd() > maxEndTime { - // Replace the end time in the request. - level.Debug(log).Log( - "msg", "the end time of the query has been manipulated because of the 'creation grace period' setting", - "original", util.FormatTimeMillis(r.GetEnd()), - "updated", util.FormatTimeMillis(maxEndTime), - "creationGracePeriod", creationGracePeriod) - - r = r.WithStartEnd(r.GetStart(), maxEndTime) - } + maxEndTime := util.TimeToMillis(time.Now().Add(creationGracePeriod)) + if r.GetEnd() > maxEndTime { + // Replace the end time in the request. + level.Debug(log).Log( + "msg", "the end time of the query has been manipulated because of the 'creation grace period' setting", + "original", util.FormatTimeMillis(r.GetEnd()), + "updated", util.FormatTimeMillis(maxEndTime), + "creationGracePeriod", creationGracePeriod) + + r = r.WithStartEnd(r.GetStart(), maxEndTime) } // Enforce max query size, in bytes. diff --git a/pkg/frontend/querymiddleware/limits_test.go b/pkg/frontend/querymiddleware/limits_test.go index c2fba3f929e..23cf4f7011d 100644 --- a/pkg/frontend/querymiddleware/limits_test.go +++ b/pkg/frontend/querymiddleware/limits_test.go @@ -300,11 +300,11 @@ func TestLimitsMiddleware_CreationGracePeriod(t *testing.T) { creationGracePeriod time.Duration expectedEndTime time.Time }{ - "should not manipulate time range if creation grace period is disabled": { + "should manipulate time range if creation grace period is set to 0": { reqStartTime: now.Add(-time.Hour), reqEndTime: now.Add(2 * time.Hour), creationGracePeriod: 0, - expectedEndTime: now.Add(2 * time.Hour), + expectedEndTime: now, }, "should not manipulate time range for a query in now + creation_grace_period": { reqStartTime: now.Add(-time.Hour),