Skip to content

Commit

Permalink
feat: add nocache url parameter option
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Quinlan committed Nov 13, 2024
1 parent 13851e9 commit 5d73871
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/prometheus/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit 5d73871

Please sign in to comment.