From bd1878700b01d1823cacce56da32375029228b0d Mon Sep 17 00:00:00 2001 From: Will Hegedus Date: Tue, 23 Apr 2024 21:35:34 -0400 Subject: [PATCH] promtool: Fix panic on extended tsdb analyze (#13976) Currently, running promtool tsdb analyze with the --extended flag will cause an 'index out of range' error if running it against a block that does not have any native histogram chunks. This change ensures that promtool won't try to display data that doesn't exist. Signed-off-by: Will Hegedus --- cmd/promtool/tsdb.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/promtool/tsdb.go b/cmd/promtool/tsdb.go index b786c9297..2ad969438 100644 --- a/cmd/promtool/tsdb.go +++ b/cmd/promtool/tsdb.go @@ -838,6 +838,10 @@ func backfillOpenMetrics(path, outputDir string, humanReadable, quiet bool, maxB } func displayHistogram(dataType string, datas []int, total int) { + if len(datas) == 0 { + fmt.Printf("%s: N/A\n\n", dataType) + return + } slices.Sort(datas) start, end, step := generateBucket(datas[0], datas[len(datas)-1]) sum := 0