From b7c44147f0adfdee9ebfac56dc087beebbe171b4 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Sat, 4 Apr 2020 13:07:12 +0100 Subject: [PATCH] Add hint that the series endpoint is being used to the tsdb. Currently the series endpoint is paging in all chunks for matched series, which can be rather slow. Signed-off-by: Brian Brazil --- tsdb/querier.go | 7 +++++++ web/api/v1/api.go | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tsdb/querier.go b/tsdb/querier.go index 05221127c..9b6219b2c 100644 --- a/tsdb/querier.go +++ b/tsdb/querier.go @@ -207,6 +207,13 @@ func (q *blockQuerier) Select(sortSeries bool, hints *storage.SelectHints, ms .. if hints != nil { mint = hints.Start maxt = hints.End + if hints.Func == "series" { // The series API does not need any chunks loaded. + return &blockSeriesSet{ + set: base, + mint: mint, + maxt: maxt, + }, nil, nil + } } return &blockSeriesSet{ set: &populatedChunkSeries{ diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 7188e08ff..5c2dac2eb 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -528,10 +528,16 @@ func (api *API) series(r *http.Request) apiFuncResult { } defer q.Close() + hints := &storage.SelectHints{ + Start: timestamp.FromTime(start), + End: timestamp.FromTime(end), + Func: "series", // There is no series function. + } + var sets []storage.SeriesSet var warnings storage.Warnings for _, mset := range matcherSets { - s, wrn, err := q.Select(false, nil, mset...) + s, wrn, err := q.Select(false, hints, mset...) warnings = append(warnings, wrn...) if err != nil { return apiFuncResult{nil, &apiError{errorExec, err}, warnings, nil}