Add warnings to series (#603)
Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
This commit is contained in:
parent
6636dde4bc
commit
063470a3c9
|
@ -237,7 +237,7 @@ type API 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, api.Warnings, error)
|
QueryRange(ctx context.Context, query string, r Range) (model.Value, api.Warnings, error)
|
||||||
// Series finds series by label matchers.
|
// Series finds series by label matchers.
|
||||||
Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, error)
|
Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, api.Warnings, error)
|
||||||
// Snapshot creates a snapshot of all current data into snapshots/<datetime>-<rand>
|
// Snapshot creates a snapshot of all current data into snapshots/<datetime>-<rand>
|
||||||
// under the TSDB's data directory and returns the directory as response.
|
// under the TSDB's data directory and returns the directory as response.
|
||||||
Snapshot(ctx context.Context, skipHead bool) (SnapshotResult, error)
|
Snapshot(ctx context.Context, skipHead bool) (SnapshotResult, error)
|
||||||
|
@ -696,7 +696,7 @@ func (h *httpAPI) QueryRange(ctx context.Context, query string, r Range) (model.
|
||||||
return model.Value(qres.v), warnings, json.Unmarshal(body, &qres)
|
return model.Value(qres.v), warnings, json.Unmarshal(body, &qres)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, error) {
|
func (h *httpAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, api.Warnings, error) {
|
||||||
u := h.client.URL(epSeries, nil)
|
u := h.client.URL(epSeries, nil)
|
||||||
q := u.Query()
|
q := u.Query()
|
||||||
|
|
||||||
|
@ -711,16 +711,16 @@ func (h *httpAPI) Series(ctx context.Context, matches []string, startTime time.T
|
||||||
|
|
||||||
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, warnings, err := h.client.Do(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, warnings, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var mset []model.LabelSet
|
var mset []model.LabelSet
|
||||||
return mset, json.Unmarshal(body, &mset)
|
return mset, warnings, json.Unmarshal(body, &mset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpAPI) Snapshot(ctx context.Context, skipHead bool) (SnapshotResult, error) {
|
func (h *httpAPI) Snapshot(ctx context.Context, skipHead bool) (SnapshotResult, error) {
|
||||||
|
|
|
@ -163,8 +163,7 @@ func TestAPIs(t *testing.T) {
|
||||||
|
|
||||||
doSeries := func(matcher string, startTime time.Time, endTime time.Time) func() (interface{}, api.Warnings, error) {
|
doSeries := func(matcher string, startTime time.Time, endTime time.Time) func() (interface{}, api.Warnings, error) {
|
||||||
return func() (interface{}, api.Warnings, error) {
|
return func() (interface{}, api.Warnings, error) {
|
||||||
v, err := promAPI.Series(context.Background(), []string{matcher}, startTime, endTime)
|
return promAPI.Series(context.Background(), []string{matcher}, startTime, endTime)
|
||||||
return v, nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,6 +385,32 @@ func TestAPIs(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// Series with data + warning.
|
||||||
|
{
|
||||||
|
do: doSeries("up", testTime.Add(-time.Minute), testTime),
|
||||||
|
inRes: []map[string]string{
|
||||||
|
{
|
||||||
|
"__name__": "up",
|
||||||
|
"job": "prometheus",
|
||||||
|
"instance": "localhost:9090"},
|
||||||
|
},
|
||||||
|
inWarnings: []string{"a"},
|
||||||
|
reqMethod: "GET",
|
||||||
|
reqPath: "/api/v1/series",
|
||||||
|
reqParam: url.Values{
|
||||||
|
"match": []string{"up"},
|
||||||
|
"start": []string{testTime.Add(-time.Minute).Format(time.RFC3339Nano)},
|
||||||
|
"end": []string{testTime.Format(time.RFC3339Nano)},
|
||||||
|
},
|
||||||
|
res: []model.LabelSet{
|
||||||
|
{
|
||||||
|
"__name__": "up",
|
||||||
|
"job": "prometheus",
|
||||||
|
"instance": "localhost:9090",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
warnings: []string{"a"},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
do: doSeries("up", testTime.Add(-time.Minute), testTime),
|
do: doSeries("up", testTime.Add(-time.Minute), testTime),
|
||||||
|
@ -399,6 +424,21 @@ func TestAPIs(t *testing.T) {
|
||||||
},
|
},
|
||||||
err: fmt.Errorf("some error"),
|
err: fmt.Errorf("some error"),
|
||||||
},
|
},
|
||||||
|
// Series with error and warning.
|
||||||
|
{
|
||||||
|
do: doSeries("up", testTime.Add(-time.Minute), testTime),
|
||||||
|
inErr: fmt.Errorf("some error"),
|
||||||
|
inWarnings: []string{"a"},
|
||||||
|
reqMethod: "GET",
|
||||||
|
reqPath: "/api/v1/series",
|
||||||
|
reqParam: url.Values{
|
||||||
|
"match": []string{"up"},
|
||||||
|
"start": []string{testTime.Add(-time.Minute).Format(time.RFC3339Nano)},
|
||||||
|
"end": []string{testTime.Format(time.RFC3339Nano)},
|
||||||
|
},
|
||||||
|
err: fmt.Errorf("some error"),
|
||||||
|
warnings: []string{"a"},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
do: doSnapshot(true),
|
do: doSnapshot(true),
|
||||||
|
|
Loading…
Reference in New Issue