Skip to content

Commit c7183d6

Browse files
refactor: Address PR comments and feedback
* Use a custom `StatsValue` type to provide as query parameter for `stats` option. Signed-off-by: Mahendra Paipuri <mahendra.paipuri@gmail.com>
1 parent df12d40 commit c7183d6

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

api/prometheus/v1/api.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,11 +1076,19 @@ func (h *httpAPI) LabelValues(ctx context.Context, label string, matches []strin
10761076
return labelValues, w, err
10771077
}
10781078

1079+
// StatsValue is a type for `stats` query parameter.
1080+
type StatsValue string
1081+
1082+
// AllStatsValue is the query parameter value to return all the query statistics.
1083+
const (
1084+
AllStatsValue StatsValue = "all"
1085+
)
1086+
10791087
type apiOptions struct {
1080-
timeout time.Duration
1081-
lookbackDelta time.Duration
1082-
enablePerStepStats bool
1083-
limit uint64
1088+
timeout time.Duration
1089+
lookbackDelta time.Duration
1090+
stats StatsValue
1091+
limit uint64
10841092
}
10851093

10861094
type Option func(c *apiOptions)
@@ -1102,14 +1110,9 @@ func WithLookbackDelta(lookbackDelta time.Duration) Option {
11021110
}
11031111
}
11041112

1105-
// WithPerStepStats can be used to provide an optional per step stats for Query and QueryRange.
1113+
// WithStats can be used to provide an optional per step stats for Query and QueryRange.
11061114
// This URL variable is not documented on Prometheus HTTP API.
11071115
// https://github.com/prometheus/prometheus/blob/e04913aea2792a5c8bc7b3130c389ca1b027dd9b/promql/engine.go#L162-L167
1108-
type StatsValue string
1109-
1110-
const (
1111-
AllStatsValue StatsValue = "all"
1112-
)
11131116
func WithStats(stats StatsValue) Option {
11141117
return func(o *apiOptions) {
11151118
o.stats = stats
@@ -1138,8 +1141,8 @@ func addOptionalURLParams(q url.Values, opts []Option) url.Values {
11381141
q.Set("lookback_delta", opt.lookbackDelta.String())
11391142
}
11401143

1141-
if opt.enablePerStepStats {
1142-
q.Set("stats", "all")
1144+
if opt.stats != "" {
1145+
q.Set("stats", string(opt.stats))
11431146
}
11441147

11451148
if opt.limit > 0 {

0 commit comments

Comments
 (0)