api: returns specific type for label values
This commit is contained in:
parent
123637b5ca
commit
57f23d303f
|
@ -283,7 +283,7 @@ type QueryAPI interface {
|
||||||
// QueryRange performs a query for the given range.
|
// QueryRange performs a query for the given range.
|
||||||
QueryRange(ctx context.Context, query string, r Range) (model.Value, error)
|
QueryRange(ctx context.Context, query string, r Range) (model.Value, error)
|
||||||
// QueryLabelValues performs a query for the values of the given label.
|
// QueryLabelValues performs a query for the values of the given label.
|
||||||
LabelValues(ctx context.Context, label string) ([]string, error)
|
LabelValues(ctx context.Context, label string) (model.LabelValues, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewQueryAPI returns a new QueryAPI for the client.
|
// NewQueryAPI returns a new QueryAPI for the client.
|
||||||
|
@ -355,7 +355,7 @@ func (h *httpQueryAPI) QueryRange(ctx context.Context, query string, r Range) (m
|
||||||
return model.Value(qres.v), err
|
return model.Value(qres.v), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpQueryAPI) LabelValues(ctx context.Context, label string) ([]string, error) {
|
func (h *httpQueryAPI) LabelValues(ctx context.Context, label string) (model.LabelValues, error) {
|
||||||
u := h.client.url(epLabelValues, map[string]string{"name": label})
|
u := h.client.url(epLabelValues, map[string]string{"name": label})
|
||||||
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
|
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -365,7 +365,7 @@ func (h *httpQueryAPI) LabelValues(ctx context.Context, label string) ([]string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var values []string
|
var labelValues model.LabelValues
|
||||||
err = json.Unmarshal(body, &values)
|
err = json.Unmarshal(body, &labelValues)
|
||||||
return values, err
|
return labelValues, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -438,7 +438,7 @@ func TestAPIs(t *testing.T) {
|
||||||
inRes: []string{"val1", "val2"},
|
inRes: []string{"val1", "val2"},
|
||||||
reqMethod: "GET",
|
reqMethod: "GET",
|
||||||
reqPath: "/api/v1/label/mylabel/values",
|
reqPath: "/api/v1/label/mylabel/values",
|
||||||
res: []string{"val1", "val2"},
|
res: model.LabelValues{"val1", "val2"},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue