Skip to content

Commit 3defbd9

Browse files
committed
add start/end parameter for LabelValues
Signed-off-by: Augustin Husson <[email protected]>
1 parent 6ce5f2c commit 3defbd9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

api/prometheus/v1/api.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ type API interface {
234234
// LabelNames returns all the unique label names present in the block in sorted order.
235235
LabelNames(ctx context.Context, startTime time.Time, endTime time.Time) ([]string, Warnings, error)
236236
// LabelValues performs a query for the values of the given label.
237-
LabelValues(ctx context.Context, label string) (model.LabelValues, Warnings, error)
237+
LabelValues(ctx context.Context, label string, startTime time.Time, endTime time.Time) (model.LabelValues, Warnings, error)
238238
// Query performs a query for the given time.
239239
Query(ctx context.Context, query string, ts time.Time) (model.Value, Warnings, error)
240240
// QueryRange performs a query for the given range.
@@ -694,8 +694,12 @@ func (h *httpAPI) LabelNames(ctx context.Context, startTime time.Time, endTime t
694694
return labelNames, w, json.Unmarshal(body, &labelNames)
695695
}
696696

697-
func (h *httpAPI) LabelValues(ctx context.Context, label string) (model.LabelValues, Warnings, error) {
697+
func (h *httpAPI) LabelValues(ctx context.Context, label string, startTime time.Time, endTime time.Time) (model.LabelValues, Warnings, error) {
698698
u := h.client.URL(epLabelValues, map[string]string{"name": label})
699+
q := u.Query()
700+
q.Set("start", formatTime(startTime))
701+
q.Set("end", formatTime(endTime))
702+
699703
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
700704
if err != nil {
701705
return nil, nil, err

api/prometheus/v1/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestAPIs(t *testing.T) {
159159

160160
doLabelValues := func(label string) func() (interface{}, Warnings, error) {
161161
return func() (interface{}, Warnings, error) {
162-
return promAPI.LabelValues(context.Background(), label)
162+
return promAPI.LabelValues(context.Background(), label, time.Now().Add(-100*time.Hour), time.Now())
163163
}
164164
}
165165

0 commit comments

Comments
 (0)