Skip to content

Commit 063470a

Browse files
jacksontjkrasi-georgiev
authored andcommitted
Add warnings to series (#603)
Signed-off-by: Thomas Jackson <[email protected]>
1 parent 6636dde commit 063470a

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

api/prometheus/v1/api.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ type API interface {
237237
// QueryRange performs a query for the given range.
238238
QueryRange(ctx context.Context, query string, r Range) (model.Value, api.Warnings, error)
239239
// Series finds series by label matchers.
240-
Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, error)
240+
Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, api.Warnings, error)
241241
// Snapshot creates a snapshot of all current data into snapshots/<datetime>-<rand>
242242
// under the TSDB's data directory and returns the directory as response.
243243
Snapshot(ctx context.Context, skipHead bool) (SnapshotResult, error)
@@ -696,7 +696,7 @@ func (h *httpAPI) QueryRange(ctx context.Context, query string, r Range) (model.
696696
return model.Value(qres.v), warnings, json.Unmarshal(body, &qres)
697697
}
698698

699-
func (h *httpAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, error) {
699+
func (h *httpAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, api.Warnings, error) {
700700
u := h.client.URL(epSeries, nil)
701701
q := u.Query()
702702

@@ -711,16 +711,16 @@ func (h *httpAPI) Series(ctx context.Context, matches []string, startTime time.T
711711

712712
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
713713
if err != nil {
714-
return nil, err
714+
return nil, nil, err
715715
}
716716

717-
_, body, _, err := h.client.Do(ctx, req)
717+
_, body, warnings, err := h.client.Do(ctx, req)
718718
if err != nil {
719-
return nil, err
719+
return nil, warnings, err
720720
}
721721

722722
var mset []model.LabelSet
723-
return mset, json.Unmarshal(body, &mset)
723+
return mset, warnings, json.Unmarshal(body, &mset)
724724
}
725725

726726
func (h *httpAPI) Snapshot(ctx context.Context, skipHead bool) (SnapshotResult, error) {

api/prometheus/v1/api_test.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ func TestAPIs(t *testing.T) {
163163

164164
doSeries := func(matcher string, startTime time.Time, endTime time.Time) func() (interface{}, api.Warnings, error) {
165165
return func() (interface{}, api.Warnings, error) {
166-
v, err := promAPI.Series(context.Background(), []string{matcher}, startTime, endTime)
167-
return v, nil, err
166+
return promAPI.Series(context.Background(), []string{matcher}, startTime, endTime)
168167
}
169168
}
170169

@@ -386,6 +385,32 @@ func TestAPIs(t *testing.T) {
386385
},
387386
},
388387
},
388+
// Series with data + warning.
389+
{
390+
do: doSeries("up", testTime.Add(-time.Minute), testTime),
391+
inRes: []map[string]string{
392+
{
393+
"__name__": "up",
394+
"job": "prometheus",
395+
"instance": "localhost:9090"},
396+
},
397+
inWarnings: []string{"a"},
398+
reqMethod: "GET",
399+
reqPath: "/api/v1/series",
400+
reqParam: url.Values{
401+
"match": []string{"up"},
402+
"start": []string{testTime.Add(-time.Minute).Format(time.RFC3339Nano)},
403+
"end": []string{testTime.Format(time.RFC3339Nano)},
404+
},
405+
res: []model.LabelSet{
406+
{
407+
"__name__": "up",
408+
"job": "prometheus",
409+
"instance": "localhost:9090",
410+
},
411+
},
412+
warnings: []string{"a"},
413+
},
389414

390415
{
391416
do: doSeries("up", testTime.Add(-time.Minute), testTime),
@@ -399,6 +424,21 @@ func TestAPIs(t *testing.T) {
399424
},
400425
err: fmt.Errorf("some error"),
401426
},
427+
// Series with error and warning.
428+
{
429+
do: doSeries("up", testTime.Add(-time.Minute), testTime),
430+
inErr: fmt.Errorf("some error"),
431+
inWarnings: []string{"a"},
432+
reqMethod: "GET",
433+
reqPath: "/api/v1/series",
434+
reqParam: url.Values{
435+
"match": []string{"up"},
436+
"start": []string{testTime.Add(-time.Minute).Format(time.RFC3339Nano)},
437+
"end": []string{testTime.Format(time.RFC3339Nano)},
438+
},
439+
err: fmt.Errorf("some error"),
440+
warnings: []string{"a"},
441+
},
402442

403443
{
404444
do: doSnapshot(true),

0 commit comments

Comments
 (0)