From b43a07248f1c9100e074435ab7535be3e0440157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Pazos?= Date: Tue, 17 Sep 2024 13:56:36 -0300 Subject: [PATCH] tsdb tests: fix `mockIndex` implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Pazos --- tsdb/querier_test.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tsdb/querier_test.go b/tsdb/querier_test.go index cd3b15abc4..a8f36bd713 100644 --- a/tsdb/querier_test.go +++ b/tsdb/querier_test.go @@ -20,6 +20,7 @@ import ( "math" "math/rand" "path/filepath" + "slices" "sort" "strconv" "sync" @@ -2274,15 +2275,19 @@ func (m mockIndex) LabelValues(_ context.Context, name string, hints *storage.La } for _, series := range m.series { + matches := true for _, matcher := range matchers { - if matcher.Matches(series.l.Get(matcher.Name)) { - // TODO(colega): shouldn't we check all the matchers before adding this to the values? - values = append(values, series.l.Get(name)) - if hints != nil && hints.Limit > 0 && len(values) >= hints.Limit { - break - } + matches = matches && matcher.Matches(series.l.Get(matcher.Name)) + if !matches { + break } } + if matches && !slices.Contains(values, series.l.Get(name)) { + values = append(values, series.l.Get(name)) + } + if hints != nil && hints.Limit > 0 && len(values) >= hints.Limit { + break + } } return values, nil @@ -2392,7 +2397,7 @@ func (m mockIndex) LabelNames(_ context.Context, matchers ...*labels.Matcher) ([ for _, series := range m.series { matches := true for _, matcher := range matchers { - matches = matches || matcher.Matches(series.l.Get(matcher.Name)) + matches = matches && matcher.Matches(series.l.Get(matcher.Name)) if !matches { break }