From 023f43f65a0c2e9e2ee11a19e60540e5bfb1b0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Ortu=C3=B1o?= Date: Fri, 14 Jun 2024 11:07:49 +0200 Subject: [PATCH] added `WithHeaders` method to `MetricsQueryRequest` interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miguel Ángel Ortuño --- pkg/frontend/querymiddleware/codec.go | 2 ++ pkg/frontend/querymiddleware/model_extra.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/pkg/frontend/querymiddleware/codec.go b/pkg/frontend/querymiddleware/codec.go index f8a0c11da51..2f029cc33f7 100644 --- a/pkg/frontend/querymiddleware/codec.go +++ b/pkg/frontend/querymiddleware/codec.go @@ -124,6 +124,8 @@ type MetricsQueryRequest interface { // WithQuery clones the current request with a different query; returns error if query parse fails. // Implementations must ensure minT and maxT are recalculated when the query changes. WithQuery(string) (MetricsQueryRequest, error) + // WithHeaders clones the current request with different headers. + WithHeaders([]*PrometheusHeader) MetricsQueryRequest // WithExpr clones the current `PrometheusRangeQueryRequest` with a new query expression. // Implementations must ensure minT and maxT are recalculated when the query changes. WithExpr(parser.Expr) MetricsQueryRequest diff --git a/pkg/frontend/querymiddleware/model_extra.go b/pkg/frontend/querymiddleware/model_extra.go index 663879f9dce..3d0c4981153 100644 --- a/pkg/frontend/querymiddleware/model_extra.go +++ b/pkg/frontend/querymiddleware/model_extra.go @@ -184,6 +184,13 @@ func (r *PrometheusRangeQueryRequest) WithQuery(query string) (MetricsQueryReque return &newRequest, nil } +// WithHeaders clones the current `PrometheusRangeQueryRequest` with new headers. +func (r *PrometheusRangeQueryRequest) WithHeaders(headers []*PrometheusHeader) MetricsQueryRequest { + newRequest := *r + newRequest.headers = headers + return &newRequest +} + // WithExpr clones the current `PrometheusRangeQueryRequest` with a new query expression. func (r *PrometheusRangeQueryRequest) WithExpr(queryExpr parser.Expr) MetricsQueryRequest { newRequest := *r @@ -376,6 +383,13 @@ func (r *PrometheusInstantQueryRequest) WithQuery(query string) (MetricsQueryReq return &newRequest, nil } +// WithHeaders clones the current `PrometheusRangeQueryRequest` with new headers. +func (r *PrometheusInstantQueryRequest) WithHeaders(headers []*PrometheusHeader) MetricsQueryRequest { + newRequest := *r + newRequest.headers = headers + return &newRequest +} + // WithExpr clones the current `PrometheusInstantQueryRequest` with a new query expression. func (r *PrometheusInstantQueryRequest) WithExpr(queryExpr parser.Expr) MetricsQueryRequest { newRequest := *r