Skip to content

Commit

Permalink
add start/end parameter for LabelNames
Browse files Browse the repository at this point in the history
Signed-off-by: Augustin Husson <[email protected]>
  • Loading branch information
Nexucis committed Jun 11, 2020
1 parent 03575ca commit 6ce5f2c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions api/prometheus/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ type API interface {
// Flags returns the flag values that Prometheus was launched with.
Flags(ctx context.Context) (FlagsResult, error)
// LabelNames returns all the unique label names present in the block in sorted order.
LabelNames(ctx context.Context) ([]string, Warnings, error)
LabelNames(ctx context.Context, startTime time.Time, endTime time.Time) ([]string, Warnings, error)
// LabelValues performs a query for the values of the given label.
LabelValues(ctx context.Context, label string) (model.LabelValues, Warnings, error)
// Query performs a query for the given time.
Expand Down Expand Up @@ -676,8 +676,12 @@ func (h *httpAPI) Runtimeinfo(ctx context.Context) (RuntimeinfoResult, error) {
return res, json.Unmarshal(body, &res)
}

func (h *httpAPI) LabelNames(ctx context.Context) ([]string, Warnings, error) {
func (h *httpAPI) LabelNames(ctx context.Context, startTime time.Time, endTime time.Time) ([]string, Warnings, error) {
u := h.client.URL(epLabels, nil)
q := u.Query()
q.Set("start", formatTime(startTime))
q.Set("end", formatTime(endTime))

req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, nil, err
Expand Down
2 changes: 1 addition & 1 deletion api/prometheus/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestAPIs(t *testing.T) {

doLabelNames := func(label string) func() (interface{}, Warnings, error) {
return func() (interface{}, Warnings, error) {
return promAPI.LabelNames(context.Background())
return promAPI.LabelNames(context.Background(), time.Now().Add(-100*time.Hour), time.Now())
}
}

Expand Down

0 comments on commit 6ce5f2c

Please sign in to comment.