Merge pull request #767 from Nexucis/feature/labelNames-parameter

add start/end parameter for LabelNames
This commit is contained in:
Björn Rabenstein 2020-06-11 16:38:50 +02:00 committed by GitHub
commit c304bb07a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -232,9 +232,9 @@ type API interface {
// Flags returns the flag values that Prometheus was launched with. // Flags returns the flag values that Prometheus was launched with.
Flags(ctx context.Context) (FlagsResult, error) Flags(ctx context.Context) (FlagsResult, error)
// LabelNames returns all the unique label names present in the block in sorted order. // 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 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 performs a query for the given time.
Query(ctx context.Context, query string, ts time.Time) (model.Value, Warnings, error) Query(ctx context.Context, query string, ts time.Time) (model.Value, Warnings, error)
// QueryRange performs a query for the given range. // QueryRange performs a query for the given range.
@ -676,8 +676,12 @@ func (h *httpAPI) Runtimeinfo(ctx context.Context) (RuntimeinfoResult, error) {
return res, json.Unmarshal(body, &res) 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) 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) req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -690,8 +694,12 @@ func (h *httpAPI) LabelNames(ctx context.Context) ([]string, Warnings, error) {
return labelNames, w, json.Unmarshal(body, &labelNames) 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}) 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) req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err

View File

@ -153,13 +153,13 @@ func TestAPIs(t *testing.T) {
doLabelNames := func(label string) func() (interface{}, Warnings, error) { doLabelNames := func(label string) func() (interface{}, Warnings, error) {
return 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())
} }
} }
doLabelValues := func(label string) func() (interface{}, Warnings, error) { doLabelValues := func(label string) func() (interface{}, Warnings, error) {
return 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())
} }
} }