From 6dcbd653e9a62304db603d2aaa7a0d317231ca7b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 25 Sep 2023 13:57:08 -0700 Subject: [PATCH] tsdb: register metrics after Head is initialized (#12876) This avoids situations where metrics are scraped before the data they are trying to look at is initialized. Signed-off-by: Bryan Boreham --- tsdb/head.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsdb/head.go b/tsdb/head.go index f66a686e6..ea71b2718 100644 --- a/tsdb/head.go +++ b/tsdb/head.go @@ -258,7 +258,6 @@ func NewHead(r prometheus.Registerer, l log.Logger, wal, wbl *wlog.WL, opts *Hea if err := h.resetInMemoryState(); err != nil { return nil, err } - h.metrics = newHeadMetrics(h, r) if opts.ChunkPool == nil { opts.ChunkPool = chunkenc.NewPool() @@ -278,6 +277,7 @@ func NewHead(r prometheus.Registerer, l log.Logger, wal, wbl *wlog.WL, opts *Hea if err != nil { return nil, err } + h.metrics = newHeadMetrics(h, r) return h, nil }