From 92d15169fc0c19391ddced74d7e30178e7f12f74 Mon Sep 17 00:00:00 2001 From: Chris Marchbanks Date: Fri, 21 Jun 2019 02:07:50 -0600 Subject: [PATCH] Print label names with highest cumulative label value length during tsdb analyze (#626) Signed-off-by: Ryan Scott Co-authored-by: Chris Marchbanks --- cmd/tsdb/main.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/tsdb/main.go b/cmd/tsdb/main.go index e7b33c855..74dfed4c5 100644 --- a/cmd/tsdb/main.go +++ b/cmd/tsdb/main.go @@ -506,6 +506,30 @@ func analyzeBlock(b *tsdb.Block, limit int) { fmt.Printf("\nMost common label pairs:\n") printInfo(postingInfos) + postingInfos = postingInfos[:0] + for _, n := range allLabelNames { + values, err := ir.LabelValues(n) + if err != nil { + exitWithError(err) + } + var cumulativeLength uint64 + + for i := 0; i < values.Len(); i++ { + value, _ := values.At(i) + if err != nil { + exitWithError(err) + } + for _, str := range value { + cumulativeLength += uint64(len(str)) + } + } + + postingInfos = append(postingInfos, postingInfo{n, cumulativeLength}) + } + + fmt.Printf("\nLabel names with highest cumulative label value length:\n") + printInfo(postingInfos) + postingInfos = postingInfos[:0] for _, n := range allLabelNames { lv, err := ir.LabelValues(n)