Skip to content

Commit 770db14

Browse files
jsvisafjl
authored andcommitted
ethdb/leveldb: support more than 7 levels in metrics (#27904)
1 parent 55863ce commit 770db14

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

ethdb/leveldb/leveldb.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type Database struct {
7575
seekCompGauge metrics.Gauge // Gauge for tracking the number of table compaction caused by read opt
7676
manualMemAllocGauge metrics.Gauge // Gauge to track the amount of memory that has been manually allocated (not a part of runtime/GC)
7777

78-
levelsGauge [7]metrics.Gauge // Gauge for tracking the number of tables in levels
78+
levelsGauge []metrics.Gauge // Gauge for tracking the number of tables in levels
7979

8080
quitLock sync.Mutex // Mutex protecting the quit channel access
8181
quitChan chan chan error // Quit channel to stop the metrics collection before closing the database
@@ -146,13 +146,8 @@ func NewCustom(file string, namespace string, customize func(options *opt.Option
146146
ldb.seekCompGauge = metrics.NewRegisteredGauge(namespace+"compact/seek", nil)
147147
ldb.manualMemAllocGauge = metrics.NewRegisteredGauge(namespace+"memory/manualalloc", nil)
148148

149-
// leveldb has only up to 7 levels
150-
for i := range ldb.levelsGauge {
151-
ldb.levelsGauge[i] = metrics.NewRegisteredGauge(namespace+fmt.Sprintf("tables/level%v", i), nil)
152-
}
153-
154149
// Start up the metrics gathering and return
155-
go ldb.meter(metricsGatheringInterval)
150+
go ldb.meter(metricsGatheringInterval, namespace)
156151
return ldb, nil
157152
}
158153

@@ -271,7 +266,7 @@ func (db *Database) Path() string {
271266

272267
// meter periodically retrieves internal leveldb counters and reports them to
273268
// the metrics subsystem.
274-
func (db *Database) meter(refresh time.Duration) {
269+
func (db *Database) meter(refresh time.Duration, namespace string) {
275270
// Create the counters to store current and previous compaction values
276271
compactions := make([][]int64, 2)
277272
for i := 0; i < 2; i++ {
@@ -360,8 +355,11 @@ func (db *Database) meter(refresh time.Duration) {
360355
db.nonlevel0CompGauge.Update(int64(stats.NonLevel0Comp))
361356
db.seekCompGauge.Update(int64(stats.SeekComp))
362357

363-
// update tables amount
364358
for i, tables := range stats.LevelTablesCounts {
359+
// Append metrics for additional layers
360+
if i >= len(db.levelsGauge) {
361+
db.levelsGauge = append(db.levelsGauge, metrics.NewRegisteredGauge(namespace+fmt.Sprintf("tables/level%v", i), nil))
362+
}
365363
db.levelsGauge[i].Update(int64(tables))
366364
}
367365

0 commit comments

Comments
 (0)