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,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
}

View file

@ -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.
},
},
{