Skip to content

Commit

Permalink
api/v1: return an empty array iff no results (#1327)
Browse files Browse the repository at this point in the history
Prometheus' /series end-point returns an empty array no matter what: if
there were results or not. We need to follow the same principle in
Thanos as well because our users depend on it.

The same fix has been applied like here:
https://github.com/prometheus/prometheus/blob/fef150f1b5e48652ec6779e2129ae9a0cf13db8a/web/api/v1/api.go#L506

Tests have been updated to account for this difference and plus one test
has been added just for this case.

Closes #1325.
  • Loading branch information
GiedriusS authored and brancz committed Jul 15, 2019
1 parent 7b36de5 commit 2dadd9c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/query/api/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func (api *API) series(r *http.Request) (interface{}, []error, *ApiError) {

set := storage.NewMergeSeriesSet(sets, nil)

var metrics []labels.Labels
metrics := []labels.Labels{}
for set.Next() {
metrics = append(metrics, set.At().Labels())
}
Expand Down
16 changes: 12 additions & 4 deletions pkg/query/api/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ func TestEndpoints(t *testing.T) {
labels.FromStrings("__name__", "test_metric2", "foo", "boo"),
},
},
// Series that does not exist should return an empty array.
{
endpoint: api.series,
query: url.Values{
"match[]": []string{`foobar`},
},
response: []labels.Labels{},
},
{
endpoint: api.series,
query: url.Values{
Expand Down Expand Up @@ -337,7 +345,7 @@ func TestEndpoints(t *testing.T) {
"start": []string{"-2"},
"end": []string{"-1"},
},
response: []labels.Labels(nil),
response: []labels.Labels{},
},
// Start and end after series ends.
{
Expand All @@ -347,7 +355,7 @@ func TestEndpoints(t *testing.T) {
"start": []string{"100000"},
"end": []string{"100001"},
},
response: []labels.Labels(nil),
response: []labels.Labels{},
},
// Start before series starts, end after series ends.
{
Expand Down Expand Up @@ -458,7 +466,7 @@ func TestEndpoints(t *testing.T) {
"start": []string{"-2"},
"end": []string{"-1"},
},
response: []labels.Labels(nil),
response: []labels.Labels{},
},
// Start and end after series ends.
{
Expand All @@ -468,7 +476,7 @@ func TestEndpoints(t *testing.T) {
"start": []string{"100000"},
"end": []string{"100001"},
},
response: []labels.Labels(nil),
response: []labels.Labels{},
},
// Start before series starts, end after series ends.
{
Expand Down

0 comments on commit 2dadd9c

Please sign in to comment.