Add Warnings to LabelValues and LabelNames (#609)
Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
This commit is contained in:
parent
4ab88e80c2
commit
3d8379da8f
|
@ -229,9 +229,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, error)
|
LabelNames(ctx context.Context) ([]string, api.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, error)
|
LabelValues(ctx context.Context, label string) (model.LabelValues, api.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, api.Warnings, error)
|
Query(ctx context.Context, query string, ts time.Time) (model.Value, api.Warnings, error)
|
||||||
// QueryRange performs a query for the given range.
|
// QueryRange performs a query for the given range.
|
||||||
|
@ -625,32 +625,32 @@ func (h *httpAPI) Flags(ctx context.Context) (FlagsResult, error) {
|
||||||
return res, json.Unmarshal(body, &res)
|
return res, json.Unmarshal(body, &res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpAPI) LabelNames(ctx context.Context) ([]string, error) {
|
func (h *httpAPI) LabelNames(ctx context.Context) ([]string, api.Warnings, error) {
|
||||||
u := h.client.URL(epLabels, nil)
|
u := h.client.URL(epLabels, nil)
|
||||||
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, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
_, body, _, err := h.client.Do(ctx, req)
|
_, body, w, err := h.client.Do(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, w, err
|
||||||
}
|
}
|
||||||
var labelNames []string
|
var labelNames []string
|
||||||
return labelNames, json.Unmarshal(body, &labelNames)
|
return labelNames, w, json.Unmarshal(body, &labelNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpAPI) LabelValues(ctx context.Context, label string) (model.LabelValues, error) {
|
func (h *httpAPI) LabelValues(ctx context.Context, label string) (model.LabelValues, api.Warnings, 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 {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
_, body, _, err := h.client.Do(ctx, req)
|
_, body, w, err := h.client.Do(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, w, err
|
||||||
}
|
}
|
||||||
var labelValues model.LabelValues
|
var labelValues model.LabelValues
|
||||||
return labelValues, json.Unmarshal(body, &labelValues)
|
return labelValues, w, json.Unmarshal(body, &labelValues)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpAPI) Query(ctx context.Context, query string, ts time.Time) (model.Value, api.Warnings, error) {
|
func (h *httpAPI) Query(ctx context.Context, query string, ts time.Time) (model.Value, api.Warnings, error) {
|
||||||
|
|
|
@ -137,15 +137,13 @@ func TestAPIs(t *testing.T) {
|
||||||
|
|
||||||
doLabelNames := func(label string) func() (interface{}, api.Warnings, error) {
|
doLabelNames := func(label string) func() (interface{}, api.Warnings, error) {
|
||||||
return func() (interface{}, api.Warnings, error) {
|
return func() (interface{}, api.Warnings, error) {
|
||||||
v, err := promAPI.LabelNames(context.Background())
|
return promAPI.LabelNames(context.Background())
|
||||||
return v, nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doLabelValues := func(label string) func() (interface{}, api.Warnings, error) {
|
doLabelValues := func(label string) func() (interface{}, api.Warnings, error) {
|
||||||
return func() (interface{}, api.Warnings, error) {
|
return func() (interface{}, api.Warnings, error) {
|
||||||
v, err := promAPI.LabelValues(context.Background(), label)
|
return promAPI.LabelValues(context.Background(), label)
|
||||||
return v, nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,6 +335,15 @@ func TestAPIs(t *testing.T) {
|
||||||
reqPath: "/api/v1/labels",
|
reqPath: "/api/v1/labels",
|
||||||
res: []string{"val1", "val2"},
|
res: []string{"val1", "val2"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
do: doLabelNames("mylabel"),
|
||||||
|
inRes: []string{"val1", "val2"},
|
||||||
|
inWarnings: []string{"a"},
|
||||||
|
reqMethod: "GET",
|
||||||
|
reqPath: "/api/v1/labels",
|
||||||
|
res: []string{"val1", "val2"},
|
||||||
|
warnings: []string{"a"},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
do: doLabelNames("mylabel"),
|
do: doLabelNames("mylabel"),
|
||||||
|
@ -345,6 +352,15 @@ func TestAPIs(t *testing.T) {
|
||||||
reqPath: "/api/v1/labels",
|
reqPath: "/api/v1/labels",
|
||||||
err: fmt.Errorf("some error"),
|
err: fmt.Errorf("some error"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
do: doLabelNames("mylabel"),
|
||||||
|
inErr: fmt.Errorf("some error"),
|
||||||
|
inWarnings: []string{"a"},
|
||||||
|
reqMethod: "GET",
|
||||||
|
reqPath: "/api/v1/labels",
|
||||||
|
err: fmt.Errorf("some error"),
|
||||||
|
warnings: []string{"a"},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
do: doLabelValues("mylabel"),
|
do: doLabelValues("mylabel"),
|
||||||
|
@ -353,6 +369,15 @@ func TestAPIs(t *testing.T) {
|
||||||
reqPath: "/api/v1/label/mylabel/values",
|
reqPath: "/api/v1/label/mylabel/values",
|
||||||
res: model.LabelValues{"val1", "val2"},
|
res: model.LabelValues{"val1", "val2"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
do: doLabelValues("mylabel"),
|
||||||
|
inRes: []string{"val1", "val2"},
|
||||||
|
inWarnings: []string{"a"},
|
||||||
|
reqMethod: "GET",
|
||||||
|
reqPath: "/api/v1/label/mylabel/values",
|
||||||
|
res: model.LabelValues{"val1", "val2"},
|
||||||
|
warnings: []string{"a"},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
do: doLabelValues("mylabel"),
|
do: doLabelValues("mylabel"),
|
||||||
|
@ -361,6 +386,15 @@ func TestAPIs(t *testing.T) {
|
||||||
reqPath: "/api/v1/label/mylabel/values",
|
reqPath: "/api/v1/label/mylabel/values",
|
||||||
err: fmt.Errorf("some error"),
|
err: fmt.Errorf("some error"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
do: doLabelValues("mylabel"),
|
||||||
|
inErr: fmt.Errorf("some error"),
|
||||||
|
inWarnings: []string{"a"},
|
||||||
|
reqMethod: "GET",
|
||||||
|
reqPath: "/api/v1/label/mylabel/values",
|
||||||
|
err: fmt.Errorf("some error"),
|
||||||
|
warnings: []string{"a"},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
do: doSeries("up", testTime.Add(-time.Minute), testTime),
|
do: doSeries("up", testTime.Add(-time.Minute), testTime),
|
||||||
|
|
Loading…
Reference in New Issue