api/v1: deduplicate selected series

This commit is contained in:
Fabian Reinartz 2017-04-04 11:09:11 +02:00
parent 4e41987bcb
commit f56644e3ae
2 changed files with 14 additions and 11 deletions

View file

@ -337,19 +337,23 @@ func (api *API) series(r *http.Request) (interface{}, *apiError) {
} }
defer q.Close() defer q.Close()
// TODO(fabxc): expose merge functionality in storage interface. var set storage.SeriesSet
// We just concatenate results for all sets of matchers, which may produce
// duplicated results.
metrics := []labels.Labels{}
for _, mset := range matcherSets { for _, mset := range matcherSets {
series := q.Select(mset...) if set == nil {
for series.Next() { set = q.Select(mset...)
metrics = append(metrics, series.At().Labels()) } else {
set = storage.DeduplicateSeriesSet(set, q.Select(mset...))
} }
if series.Err() != nil {
return nil, &apiError{errorExec, series.Err()}
} }
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 return metrics, nil

View file

@ -310,7 +310,6 @@ func TestEndpoints(t *testing.T) {
}, },
response: []labels.Labels{ response: []labels.Labels{
labels.FromStrings("__name__", "test_metric1", "foo", "boo"), labels.FromStrings("__name__", "test_metric1", "foo", "boo"),
labels.FromStrings("__name__", "test_metric1", "foo", "boo"), // TODO(fabxc): see comment in implementation.
}, },
}, },
{ {