From 6ce5f2ca8ad23ffb3ed2389acc285bc04bdb0089 Mon Sep 17 00:00:00 2001 From: Augustin Husson Date: Thu, 11 Jun 2020 13:02:32 +0200 Subject: [PATCH 1/2] add start/end parameter for LabelNames Signed-off-by: Augustin Husson --- api/prometheus/v1/api.go | 8 ++++++-- api/prometheus/v1/api_test.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/api/prometheus/v1/api.go b/api/prometheus/v1/api.go index a18d2c7b8..42ccf4212 100644 --- a/api/prometheus/v1/api.go +++ b/api/prometheus/v1/api.go @@ -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. @@ -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 diff --git a/api/prometheus/v1/api_test.go b/api/prometheus/v1/api_test.go index cb6eaa586..24800ba61 100644 --- a/api/prometheus/v1/api_test.go +++ b/api/prometheus/v1/api_test.go @@ -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()) } } From 3defbd9c7c086d0b0d24b0e0f3db541cea084964 Mon Sep 17 00:00:00 2001 From: Augustin Husson Date: Thu, 11 Jun 2020 15:45:46 +0200 Subject: [PATCH 2/2] add start/end parameter for LabelValues Signed-off-by: Augustin Husson --- api/prometheus/v1/api.go | 8 ++++++-- api/prometheus/v1/api_test.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/api/prometheus/v1/api.go b/api/prometheus/v1/api.go index 42ccf4212..b77294778 100644 --- a/api/prometheus/v1/api.go +++ b/api/prometheus/v1/api.go @@ -234,7 +234,7 @@ type API interface { // LabelNames returns all the unique label names present in the block in sorted order. 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) + LabelValues(ctx context.Context, label string, startTime time.Time, endTime time.Time) (model.LabelValues, Warnings, error) // Query performs a query for the given time. Query(ctx context.Context, query string, ts time.Time) (model.Value, Warnings, error) // QueryRange performs a query for the given range. @@ -694,8 +694,12 @@ func (h *httpAPI) LabelNames(ctx context.Context, startTime time.Time, endTime t return labelNames, w, json.Unmarshal(body, &labelNames) } -func (h *httpAPI) LabelValues(ctx context.Context, label string) (model.LabelValues, Warnings, error) { +func (h *httpAPI) LabelValues(ctx context.Context, label string, startTime time.Time, endTime time.Time) (model.LabelValues, Warnings, error) { u := h.client.URL(epLabelValues, map[string]string{"name": label}) + 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 diff --git a/api/prometheus/v1/api_test.go b/api/prometheus/v1/api_test.go index 24800ba61..4bc4d53f5 100644 --- a/api/prometheus/v1/api_test.go +++ b/api/prometheus/v1/api_test.go @@ -159,7 +159,7 @@ func TestAPIs(t *testing.T) { doLabelValues := func(label string) func() (interface{}, Warnings, error) { return func() (interface{}, Warnings, error) { - return promAPI.LabelValues(context.Background(), label) + return promAPI.LabelValues(context.Background(), label, time.Now().Add(-100*time.Hour), time.Now()) } }