diff --git a/tsdb/db.go b/tsdb/db.go index 8c8b049d54..2b0525ab6b 100644 --- a/tsdb/db.go +++ b/tsdb/db.go @@ -569,13 +569,6 @@ func open(dir string, l log.Logger, r prometheus.Registerer, opts *Options, rngs autoCompact: true, chunkPool: chunkenc.NewPool(), } - db.metrics = newDBMetrics(db, r) - - maxBytes := opts.MaxBytes - if maxBytes < 0 { - maxBytes = 0 - } - db.metrics.maxBytes.Set(float64(maxBytes)) if !opts.NoLockfile { absdir, err := filepath.Abs(dir) @@ -617,6 +610,14 @@ func open(dir string, l log.Logger, r prometheus.Registerer, opts *Options, rngs return nil, err } + // Register metrics after assigning the head block. + db.metrics = newDBMetrics(db, r) + maxBytes := opts.MaxBytes + if maxBytes < 0 { + maxBytes = 0 + } + db.metrics.maxBytes.Set(float64(maxBytes)) + if err := db.reload(); err != nil { return nil, err }