From 9cef442ece9b7b4ec648d85ca7b7c9b001481afc Mon Sep 17 00:00:00 2001 From: Martin Disibio Date: Fri, 15 Nov 2024 10:47:15 -0500 Subject: [PATCH] Fix to assert metrics query range before alignment because alignment may increase it, which is not the responsibility of the caller to account for (#4331) --- modules/frontend/metrics_query_range_sharder.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/frontend/metrics_query_range_sharder.go b/modules/frontend/metrics_query_range_sharder.go index bfffbf21bf7..570764f2f32 100644 --- a/modules/frontend/metrics_query_range_sharder.go +++ b/modules/frontend/metrics_query_range_sharder.go @@ -88,16 +88,17 @@ func (s queryRangeSharder) RoundTrip(pipelineRequest pipeline.Request) (pipeline return pipeline.NewBadRequest(errors.New("step must be greater than 0")), nil } - traceql.AlignRequest(req) - // calculate and enforce max search duration - // Note: this is checked after alignment for consistency. + // This is checked before alignment because we may need to read a larger + // range internally to satisfy the query. maxDuration := s.maxDuration(tenantID) if maxDuration != 0 && time.Duration(req.End-req.Start)*time.Nanosecond > maxDuration { err = fmt.Errorf("range specified by start and end (%s) exceeds %s. received start=%d end=%d", time.Duration(req.End-req.Start), maxDuration, req.Start, req.End) return pipeline.NewBadRequest(err), nil } + traceql.AlignRequest(req) + var maxExemplars uint32 // Instant queries must not compute exemplars if !s.instantMode && s.cfg.MaxExemplars > 0 {