github.com/thanos-io/thanos@v0.32.5/internal/cortex/querier/queryrange/step_align.go (about) 1 // Copyright (c) The Cortex Authors. 2 // Licensed under the Apache License 2.0. 3 4 package queryrange 5 6 import ( 7 "context" 8 ) 9 10 // StepAlignMiddleware aligns the start and end of request to the step to 11 // improved the cacheability of the query results. 12 var StepAlignMiddleware = MiddlewareFunc(func(next Handler) Handler { 13 return stepAlign{ 14 next: next, 15 } 16 }) 17 18 type stepAlign struct { 19 next Handler 20 } 21 22 func (s stepAlign) Do(ctx context.Context, r Request) (Response, error) { 23 start := (r.GetStart() / r.GetStep()) * r.GetStep() 24 end := (r.GetEnd() / r.GetStep()) * r.GetStep() 25 return s.next.Do(ctx, r.WithStartEnd(start, end)) 26 }