From ce0cfc05c9338b18792f7534aac52b33bd8b9b3d Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Mon, 20 Jan 2025 09:36:55 -0500 Subject: [PATCH] frontend: Expose lookback delta in `MetricsQueryRequest` interface Extracted from https://github.com/grafana/mimir/pull/10460 --- pkg/frontend/querymiddleware/codec.go | 2 ++ pkg/frontend/querymiddleware/model_extra.go | 8 ++++++++ pkg/frontend/querymiddleware/remote_read.go | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/pkg/frontend/querymiddleware/codec.go b/pkg/frontend/querymiddleware/codec.go index 5e9dcb78496..4563a4ad23c 100644 --- a/pkg/frontend/querymiddleware/codec.go +++ b/pkg/frontend/querymiddleware/codec.go @@ -133,6 +133,8 @@ type MetricsQueryRequest interface { // GetHints returns hints that could be optionally attached to the request to pass down the stack. // These hints can be used to optimize the query execution. GetHints() *Hints + // GetLookbackDelta returns the lookback delta for the request. + GetLookbackDelta() time.Duration // WithID clones the current request with the provided ID. WithID(id int64) (MetricsQueryRequest, error) // WithStartEnd clone the current request with different start and end timestamp. diff --git a/pkg/frontend/querymiddleware/model_extra.go b/pkg/frontend/querymiddleware/model_extra.go index 9cf07648338..33a6a7d3f73 100644 --- a/pkg/frontend/querymiddleware/model_extra.go +++ b/pkg/frontend/querymiddleware/model_extra.go @@ -153,6 +153,10 @@ func (r *PrometheusRangeQueryRequest) GetHints() *Hints { return r.hints } +func (r *PrometheusRangeQueryRequest) GetLookbackDelta() time.Duration { + return r.lookbackDelta +} + // WithID clones the current `PrometheusRangeQueryRequest` with the provided ID. func (r *PrometheusRangeQueryRequest) WithID(id int64) (MetricsQueryRequest, error) { newRequest := *r @@ -345,6 +349,10 @@ func (r *PrometheusInstantQueryRequest) GetHints() *Hints { return r.hints } +func (r *PrometheusInstantQueryRequest) GetLookbackDelta() time.Duration { + return r.lookbackDelta +} + func (r *PrometheusInstantQueryRequest) WithID(id int64) (MetricsQueryRequest, error) { newRequest := *r newRequest.headers = cloneHeaders(r.headers) diff --git a/pkg/frontend/querymiddleware/remote_read.go b/pkg/frontend/querymiddleware/remote_read.go index 11070ce18d5..9c53e0ccf5d 100644 --- a/pkg/frontend/querymiddleware/remote_read.go +++ b/pkg/frontend/querymiddleware/remote_read.go @@ -11,6 +11,7 @@ import ( "net/http" "net/url" "strconv" + "time" "github.com/golang/snappy" "github.com/opentracing/opentracing-go" @@ -240,6 +241,10 @@ func (r *remoteReadQueryRequest) GetHints() *Hints { return nil } +func (r *remoteReadQueryRequest) GetLookbackDelta() time.Duration { + return 0 +} + func (r *remoteReadQueryRequest) GetStep() int64 { // Step is ignored when the remote read query is executed. return 0