From 40c3ba9fd411ac82b46a0cb27869c5ae2de4ba5a Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Sun, 24 Nov 2024 08:30:20 -0800 Subject: [PATCH] fix promtool analyze block shows metric name with 0 cardinality (#15438) Signed-off-by: Ben Ye --- cmd/promtool/tsdb.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/promtool/tsdb.go b/cmd/promtool/tsdb.go index e1c6cf4298..cefacfec28 100644 --- a/cmd/promtool/tsdb.go +++ b/cmd/promtool/tsdb.go @@ -589,7 +589,10 @@ func analyzeBlock(ctx context.Context, path, blockID string, limit int, runExten if err != nil { return err } - postings = index.Intersect(postings, index.NewListPostings(refs)) + // Only intersect postings if matchers are specified. + if len(matchers) > 0 { + postings = index.Intersect(postings, index.NewListPostings(refs)) + } count := 0 for postings.Next() { count++