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

Enforce -validation.create-grace-period in the query-frontend when the configured value is 0 #5829

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
22 changes: 10 additions & 12 deletions pkg/frontend/querymiddleware/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/frontend/querymiddleware/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading