From 3e7139f3b93ca33a4a0d2983efebcedac8f69c05 Mon Sep 17 00:00:00 2001 From: Scott Quinlan Date: Wed, 13 Nov 2024 16:46:57 +1300 Subject: [PATCH] feat: add nocache url parameter option Signed-off-by: Scott Quinlan --- api/prometheus/v1/api.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/api/prometheus/v1/api.go b/api/prometheus/v1/api.go index cddf027..aa49d42 100644 --- a/api/prometheus/v1/api.go +++ b/api/prometheus/v1/api.go @@ -1079,6 +1079,7 @@ func (h *httpAPI) LabelValues(ctx context.Context, label string, matches []strin type apiOptions struct { timeout time.Duration limit uint64 + nocache bool } type Option func(c *apiOptions) @@ -1099,6 +1100,13 @@ func WithLimit(limit uint64) Option { } } +// WithNoCache can be used to provide an optional nocache parameter for Query and QueryRange. +func WithNoCache() Option { + return func(o *apiOptions) { + o.nocache = true + } +} + func addOptionalURLParams(q url.Values, opts []Option) url.Values { opt := &apiOptions{} for _, o := range opts { @@ -1113,6 +1121,10 @@ func addOptionalURLParams(q url.Values, opts []Option) url.Values { q.Set("limit", strconv.FormatUint(opt.limit, 10)) } + if opt.nocache { + q.Set("nocache", "1") + } + return q }