diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 146265613..06e6cc1dc 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -337,21 +337,25 @@ func (api *API) series(r *http.Request) (interface{}, *apiError) { } defer q.Close() - // TODO(fabxc): expose merge functionality in storage interface. - // We just concatenate results for all sets of matchers, which may produce - // duplicated results. - metrics := []labels.Labels{} + var set storage.SeriesSet for _, mset := range matcherSets { - series := q.Select(mset...) - for series.Next() { - metrics = append(metrics, series.At().Labels()) - } - if series.Err() != nil { - return nil, &apiError{errorExec, series.Err()} + if set == nil { + set = q.Select(mset...) + } else { + set = storage.DeduplicateSeriesSet(set, q.Select(mset...)) } } + metrics := []labels.Labels{} + + for set.Next() { + metrics = append(metrics, set.At().Labels()) + } + if set.Err() != nil { + return nil, &apiError{errorExec, set.Err()} + } + return metrics, nil } diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index b9590dd6f..19aa9ca02 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -310,7 +310,6 @@ func TestEndpoints(t *testing.T) { }, response: []labels.Labels{ labels.FromStrings("__name__", "test_metric1", "foo", "boo"), - labels.FromStrings("__name__", "test_metric1", "foo", "boo"), // TODO(fabxc): see comment in implementation. }, }, {