From d23df53ba28bd80bd17508586d01847c6d34dbda Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 28 Feb 2020 23:35:47 +0200 Subject: [PATCH] app/vmselect/prometheus: do not add `__name__!=` filter when searching for all the matching metric names via `/api/v1/label/__name__/values` with non-empty label filter This should reduce query time. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/343 --- app/vmselect/prometheus/prometheus.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/vmselect/prometheus/prometheus.go b/app/vmselect/prometheus/prometheus.go index 9448bf3543..f7ec7b203a 100644 --- a/app/vmselect/prometheus/prometheus.go +++ b/app/vmselect/prometheus/prometheus.go @@ -340,16 +340,18 @@ func labelValuesWithMatches(at *auth.Token, labelName string, matches []string, if err != nil { return nil, false, err } + // Add `labelName!=''` tag filter in order to filter out series without the labelName. - key := []byte(labelName) - if string(key) == "__name__" { - key = nil - } - for i, tfs := range tagFilterss { - tagFilterss[i] = append(tfs, storage.TagFilter{ - Key: key, - IsNegative: true, - }) + // There is no need in adding `__name__!=''` filter, since all the time series should + // already have non-empty name. + if labelName != "__name__" { + key := []byte(labelName) + for i, tfs := range tagFilterss { + tagFilterss[i] = append(tfs, storage.TagFilter{ + Key: key, + IsNegative: true, + }) + } } if start >= end { end = start + defaultStep