Skip to content

Commit c304bb0

Browse files
authored
Merge pull request #767 from Nexucis/feature/labelNames-parameter
add start/end parameter for LabelNames
2 parents 03575ca + 3defbd9 commit c304bb0

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

api/prometheus/v1/api.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ type API interface {
232232
// Flags returns the flag values that Prometheus was launched with.
233233
Flags(ctx context.Context) (FlagsResult, error)
234234
// LabelNames returns all the unique label names present in the block in sorted order.
235-
LabelNames(ctx context.Context) ([]string, Warnings, error)
235+
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.
@@ -676,8 +676,12 @@ func (h *httpAPI) Runtimeinfo(ctx context.Context) (RuntimeinfoResult, error) {
676676
return res, json.Unmarshal(body, &res)
677677
}
678678

679-
func (h *httpAPI) LabelNames(ctx context.Context) ([]string, Warnings, error) {
679+
func (h *httpAPI) LabelNames(ctx context.Context, startTime time.Time, endTime time.Time) ([]string, Warnings, error) {
680680
u := h.client.URL(epLabels, nil)
681+
q := u.Query()
682+
q.Set("start", formatTime(startTime))
683+
q.Set("end", formatTime(endTime))
684+
681685
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
682686
if err != nil {
683687
return nil, nil, err
@@ -690,8 +694,12 @@ func (h *httpAPI) LabelNames(ctx context.Context) ([]string, Warnings, error) {
690694
return labelNames, w, json.Unmarshal(body, &labelNames)
691695
}
692696

693-
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) {
694698
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+
695703
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
696704
if err != nil {
697705
return nil, nil, err

api/prometheus/v1/api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ func TestAPIs(t *testing.T) {
153153

154154
doLabelNames := func(label string) func() (interface{}, Warnings, error) {
155155
return func() (interface{}, Warnings, error) {
156-
return promAPI.LabelNames(context.Background())
156+
return promAPI.LabelNames(context.Background(), time.Now().Add(-100*time.Hour), time.Now())
157157
}
158158
}
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)