Skip to content

Commit

Permalink
frontend: Expose query lookback delta (#10489)
Browse files Browse the repository at this point in the history
Extracted from #10460. Trying to make the PR more presentable
  • Loading branch information
julienduchesne authored Jan 23, 2025
1 parent ae544b3 commit 098ed84
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/frontend/querymiddleware/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions pkg/frontend/querymiddleware/model_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions pkg/frontend/querymiddleware/remote_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"strconv"
"time"

"github.com/golang/snappy"
"github.com/opentracing/opentracing-go"
Expand Down Expand Up @@ -285,6 +286,10 @@ func (r *remoteReadQueryRequest) GetHeaders() []*PrometheusHeader {
return nil
}

func (r *remoteReadQueryRequest) GetLookbackDelta() time.Duration {
return 0
}

func (r *remoteReadQueryRequest) WithID(_ int64) (MetricsQueryRequest, error) {
return nil, apierror.New(apierror.TypeInternal, "remoteReadQueryRequest.WithID not implemented")
}
Expand Down

0 comments on commit 098ed84

Please sign in to comment.