add start/end parameter for LabelNames

Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
This commit is contained in:
Augustin Husson 2020-06-11 13:02:32 +02:00
parent 03575cad4e
commit 6ce5f2ca8a
2 changed files with 7 additions and 3 deletions

View File

@ -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

View File

@ -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())
}
}