From bb4990686007ca4a8ba49fb71f3028be8bb899c7 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Mon, 9 Oct 2023 21:17:20 +0000 Subject: [PATCH] Fix state/storage counter metrics. (#8) The counters for state, storage, and code node no longer work after https://git.vdb.to/cerc-io/ipld-eth-state-snapshot/commit/00141776bf360534b917f391c0ed750aed71f4d4. The structure is sufficiently different I did not see a simple way to restore the code counters, but I did restore the state and storage counters. Reviewed-on: https://git.vdb.to/cerc-io/ipld-eth-state-snapshot/pulls/8 --- pkg/prom/prom.go | 46 ++++------------------------------------- pkg/snapshot/service.go | 2 ++ 2 files changed, 6 insertions(+), 42 deletions(-) diff --git a/pkg/prom/prom.go b/pkg/prom/prom.go index 64e108f..f6f2de5 100644 --- a/pkg/prom/prom.go +++ b/pkg/prom/prom.go @@ -33,9 +33,6 @@ var ( stateNodeCount prometheus.Counter storageNodeCount prometheus.Counter - codeNodeCount prometheus.Counter - - activeIteratorCount prometheus.Gauge ) func Init() { @@ -54,20 +51,6 @@ func Init() { Name: "storage_node_count", Help: "Number of storage nodes processed", }) - - codeNodeCount = promauto.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: statsSubsystem, - Name: "code_node_count", - Help: "Number of code nodes processed", - }) - - activeIteratorCount = promauto.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Subsystem: statsSubsystem, - Name: "active_iterator_count", - Help: "Number of active iterators", - }) } func RegisterGaugeFunc(name string, function func() float64) { @@ -94,31 +77,10 @@ func IncStateNodeCount() { } } -// IncStorageNodeCount increments the number of storage nodes processed -func IncStorageNodeCount() { - if metrics { - storageNodeCount.Inc() - } -} - -// IncCodeNodeCount increments the number of code nodes processed -func IncCodeNodeCount() { - if metrics { - codeNodeCount.Inc() - } -} - -// IncActiveIterCount increments the number of active iterators -func IncActiveIterCount() { - if metrics { - activeIteratorCount.Inc() - } -} - -// DecActiveIterCount decrements the number of active iterators -func DecActiveIterCount() { - if metrics { - activeIteratorCount.Dec() +// AddStorageNodeCount increments the number of storage nodes processed +func AddStorageNodeCount(count int) { + if metrics && count > 0 { + storageNodeCount.Add(float64(count)) } } diff --git a/pkg/snapshot/service.go b/pkg/snapshot/service.go index a1658ce..05a1977 100644 --- a/pkg/snapshot/service.go +++ b/pkg/snapshot/service.go @@ -124,6 +124,8 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error { nodeSink := func(node types.StateLeafNode) error { nodeMtx.Lock() defer nodeMtx.Unlock() + prom.IncStateNodeCount() + prom.AddStorageNodeCount(len(node.StorageDiff)) return s.indexer.PushStateNode(tx, node, headerid) } ipldSink := func(c types.IPLD) error {