Skip to content

Commit

Permalink
Fix panic from db metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
  • Loading branch information
codesome committed Jul 2, 2020
1 parent aa452d8 commit 0e6b8c1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tsdb/db.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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 else it causes panics is the gauge function.
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
}
Expand Down

0 comments on commit 0e6b8c1

Please sign in to comment.