From 8d492d81fca3a786fbf91dbef696505f9564d461 Mon Sep 17 00:00:00 2001 From: devopsbo3 <69951731+devopsbo3@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:27:53 -0600 Subject: [PATCH] Revert "ethdb/leveldb: support more than 7 levels in metrics (#27904)" This reverts commit 4c8cdb4276af5745d73c093b655f1219b9586ed0. --- ethdb/leveldb/leveldb.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go index c0e0eb250a75..190327accb75 100644 --- a/ethdb/leveldb/leveldb.go +++ b/ethdb/leveldb/leveldb.go @@ -75,7 +75,7 @@ type Database struct { seekCompGauge metrics.Gauge // Gauge for tracking the number of table compaction caused by read opt manualMemAllocGauge metrics.Gauge // Gauge to track the amount of memory that has been manually allocated (not a part of runtime/GC) - levelsGauge []metrics.Gauge // Gauge for tracking the number of tables in levels + levelsGauge [7]metrics.Gauge // Gauge for tracking the number of tables in levels quitLock sync.Mutex // Mutex protecting the quit channel access quitChan chan chan error // Quit channel to stop the metrics collection before closing the database @@ -146,8 +146,13 @@ func NewCustom(file string, namespace string, customize func(options *opt.Option ldb.seekCompGauge = metrics.NewRegisteredGauge(namespace+"compact/seek", nil) ldb.manualMemAllocGauge = metrics.NewRegisteredGauge(namespace+"memory/manualalloc", nil) + // leveldb has only up to 7 levels + for i := range ldb.levelsGauge { + ldb.levelsGauge[i] = metrics.NewRegisteredGauge(namespace+fmt.Sprintf("tables/level%v", i), nil) + } + // Start up the metrics gathering and return - go ldb.meter(metricsGatheringInterval, namespace) + go ldb.meter(metricsGatheringInterval) return ldb, nil } @@ -266,7 +271,7 @@ func (db *Database) Path() string { // meter periodically retrieves internal leveldb counters and reports them to // the metrics subsystem. -func (db *Database) meter(refresh time.Duration, namespace string) { +func (db *Database) meter(refresh time.Duration) { // Create the counters to store current and previous compaction values compactions := make([][]int64, 2) for i := 0; i < 2; i++ { @@ -355,11 +360,8 @@ func (db *Database) meter(refresh time.Duration, namespace string) { db.nonlevel0CompGauge.Update(int64(stats.NonLevel0Comp)) db.seekCompGauge.Update(int64(stats.SeekComp)) + // update tables amount for i, tables := range stats.LevelTablesCounts { - // Append metrics for additional layers - if i >= len(db.levelsGauge) { - db.levelsGauge = append(db.levelsGauge, metrics.NewRegisteredGauge(namespace+fmt.Sprintf("tables/level%v", i), nil)) - } db.levelsGauge[i].Update(int64(tables)) }