From 39ca77976b688737fa3dd1fef311c55f2e2ef578 Mon Sep 17 00:00:00 2001 From: nugaon Date: Wed, 16 Jul 2025 18:09:08 +0200 Subject: [PATCH 01/10] feat: historycal sync time measurement 1 --- pkg/puller/metrics.go | 8 ++++++++ pkg/puller/puller.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/pkg/puller/metrics.go b/pkg/puller/metrics.go index bfa546f26e0..56ce34071e8 100644 --- a/pkg/puller/metrics.go +++ b/pkg/puller/metrics.go @@ -15,6 +15,7 @@ type metrics struct { SyncedCounter *prometheus.CounterVec // number of synced chunks SyncWorkerErrCounter prometheus.Counter // count number of errors MaxUintErrCounter prometheus.Counter // how many times we got maxuint as topmost + HistoricalSyncTime prometheus.Histogram // time from start until historical sync completes } func newMetrics() metrics { @@ -51,6 +52,13 @@ func newMetrics() metrics { Name: "max_uint_errors", Help: "Total max uint errors.", }), + HistoricalSyncTime: prometheus.NewHistogram(prometheus.HistogramOpts{ + Namespace: m.Namespace, + Subsystem: subsystem, + Name: "historical_sync_time_seconds", + Help: "Time from start until historical sync completes in seconds.", + Buckets: []float64{1, 5, 15, 30, 60, 120, 300, 600, 900, 1800, 3600, 7200}, + }), } } diff --git a/pkg/puller/puller.go b/pkg/puller/puller.go index 2fdbc24e9cf..67564c8e9ed 100644 --- a/pkg/puller/puller.go +++ b/pkg/puller/puller.go @@ -60,6 +60,11 @@ type Puller struct { metrics metrics logger log.Logger + // Historical sync tracking + syncStartTime time.Time + historicalSyncsMtx sync.Mutex + activeSyncs int + syncPeers map[string]*syncPeer // index is bin, map key is peer address syncPeersMtx sync.Mutex intervalMtx sync.Mutex @@ -115,6 +120,10 @@ func (p *Puller) Start(ctx context.Context) { cctx, cancel := context.WithCancel(ctx) p.cancel = cancel + // Initialize historical sync tracking + p.syncStartTime = time.Now() + p.activeSyncs = 0 + p.wg.Add(1) go p.manage(cctx) }) @@ -308,6 +317,27 @@ func (p *Puller) syncPeerBin(parentCtx context.Context, peer *syncPeer, bin uint sync := func(isHistorical bool, address swarm.Address, start uint64) { p.metrics.SyncWorkerCounter.Inc() + // Track historical sync start + if isHistorical { + p.historicalSyncsMtx.Lock() + p.activeSyncs++ + p.historicalSyncsMtx.Unlock() + } + + defer func() { + // Track historical sync completion and observe metrics if all syncs finished + if isHistorical { + p.historicalSyncsMtx.Lock() + p.activeSyncs-- + if p.activeSyncs == 0 { + // All historical syncs have completed, observe the total sync time + elapsed := time.Since(p.syncStartTime).Seconds() + p.metrics.HistoricalSyncTime.Observe(elapsed) + p.logger.Info("all historical syncs completed", "elapsed_seconds", elapsed) + } + p.historicalSyncsMtx.Unlock() + } + }() defer p.wg.Done() defer peer.wg.Done() defer p.metrics.SyncWorkerCounter.Dec() From e6c660d28cb0ddb2d91e32a39d9adf42b2b788bd Mon Sep 17 00:00:00 2001 From: nugaon Date: Thu, 17 Jul 2025 14:49:22 +0200 Subject: [PATCH 02/10] feat: measure warmup time --- pkg/node/node.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/node/node.go b/pkg/node/node.go index 7d14ceb1b15..c2c808cb7a5 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -206,6 +206,9 @@ func NewBee( session accesscontrol.Session, o *Options, ) (b *Bee, err error) { + // start time for node warmup duration measurement + warmupStartTime := time.Now() + tracer, tracerCloser, err := tracing.NewTracer(&tracing.Options{ Enabled: o.TracingEnabled, Endpoint: o.TracingEndpoint, @@ -595,8 +598,25 @@ func NewBee( logger.Info("node warmup check initiated. monitoring activity rate to determine readiness.", "startTime", t) } + nodeWarmupDuration := prometheus.NewHistogram( + prometheus.HistogramOpts{ + Namespace: metrics.Namespace, + Subsystem: "init", + Name: "warmup_duration_seconds", + Help: "Duration in seconds for node warmup to complete", + }, + ) + prometheus.MustRegister(nodeWarmupDuration) + detector.OnStabilized = func(t time.Time, totalCount int) { - logger.Info("node warmup complete. system is considered stable and ready.", "stabilizationTime", t, "totalMonitoredEvents", totalCount) + warmupDuration := t.Sub(warmupStartTime).Seconds() + logger.Info("node warmup complete. system is considered stable and ready.", + "stabilizationTime", t, + "totalMonitoredEvents", totalCount, + "warmupDurationSeconds", warmupDuration) + + // Record the warmup duration in the prometheus metric + nodeWarmupDuration.Observe(warmupDuration) } detector.OnPeriodComplete = func(t time.Time, periodCount int, stDev float64) { From 219cda09d0d9cc6f1939d8a1ea29db1dbde3fafc Mon Sep 17 00:00:00 2001 From: nugaon Date: Thu, 17 Jul 2025 16:45:14 +0200 Subject: [PATCH 03/10] feat: fully synced check --- pkg/node/node.go | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/pkg/node/node.go b/pkg/node/node.go index c2c808cb7a5..fff87d0af7d 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -208,6 +208,7 @@ func NewBee( ) (b *Bee, err error) { // start time for node warmup duration measurement warmupStartTime := time.Now() + var pullSyncStartTime time.Time tracer, tracerCloser, err := tracing.NewTracer(&tracing.Options{ Enabled: o.TracingEnabled, @@ -608,7 +609,7 @@ func NewBee( ) prometheus.MustRegister(nodeWarmupDuration) - detector.OnStabilized = func(t time.Time, totalCount int) { + warmupMeasurement := func(t time.Time, totalCount int) { warmupDuration := t.Sub(warmupStartTime).Seconds() logger.Info("node warmup complete. system is considered stable and ready.", "stabilizationTime", t, @@ -617,7 +618,9 @@ func NewBee( // Record the warmup duration in the prometheus metric nodeWarmupDuration.Observe(warmupDuration) + pullSyncStartTime = t } + detector.OnStabilized = warmupMeasurement detector.OnPeriodComplete = func(t time.Time, periodCount int, stDev float64) { logger.Debug("node warmup check: period complete.", "periodEndTime", t, "eventsInPeriod", periodCount, "rateStdDev", stDev) @@ -1150,6 +1153,45 @@ func NewBee( localStore.StartReserveWorker(ctx, pullerService, waitNetworkRFunc) nodeStatus.SetSync(pullerService) + // measure full sync duration + detector.OnStabilized = func(t time.Time, totalCount int) { + warmupMeasurement(t, totalCount) + fullSyncDuration := prometheus.NewHistogram( + prometheus.HistogramOpts{ + Namespace: metrics.Namespace, + Subsystem: "init", + Name: "full_sync_duration_seconds", + Help: "Duration in seconds for node warmup to complete", + }, + ) + prometheus.MustRegister(fullSyncDuration) + + reserveTreshold := reserveCapacity >> 1 + isFullySynced := func() bool { + return pullerService.SyncRate() == 0 && localStore.ReserveSize() >= reserveTreshold + } + + syncCheckTicker := time.NewTicker(time.Second) + go func() { + defer syncCheckTicker.Stop() + for { + select { + case <-ctx.Done(): + return + case <-syncCheckTicker.C: + synced := isFullySynced() + logger.Debug("sync status check", "synced", synced, "reserveSize", localStore.ReserveSize(), "threshold", reserveTreshold, "syncRate", pullerService.SyncRate()) + if synced { + fullSyncTime := pullSyncStartTime.Sub(t) + fullSyncDuration.Observe(fullSyncTime.Seconds()) + syncCheckTicker.Stop() + return + } + } + } + }() + } + if o.EnableStorageIncentives { redistributionContractAddress := chainCfg.RedistributionAddress From b96d82a1ce128df6c48e6dc3c92439221b1206fa Mon Sep 17 00:00:00 2001 From: nugaon Date: Thu, 17 Jul 2025 16:45:28 +0200 Subject: [PATCH 04/10] revert: historycal sync time measurement 1 This reverts commit 39ca77976b688737fa3dd1fef311c55f2e2ef578. --- pkg/puller/metrics.go | 8 -------- pkg/puller/puller.go | 30 ------------------------------ 2 files changed, 38 deletions(-) diff --git a/pkg/puller/metrics.go b/pkg/puller/metrics.go index 56ce34071e8..bfa546f26e0 100644 --- a/pkg/puller/metrics.go +++ b/pkg/puller/metrics.go @@ -15,7 +15,6 @@ type metrics struct { SyncedCounter *prometheus.CounterVec // number of synced chunks SyncWorkerErrCounter prometheus.Counter // count number of errors MaxUintErrCounter prometheus.Counter // how many times we got maxuint as topmost - HistoricalSyncTime prometheus.Histogram // time from start until historical sync completes } func newMetrics() metrics { @@ -52,13 +51,6 @@ func newMetrics() metrics { Name: "max_uint_errors", Help: "Total max uint errors.", }), - HistoricalSyncTime: prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: m.Namespace, - Subsystem: subsystem, - Name: "historical_sync_time_seconds", - Help: "Time from start until historical sync completes in seconds.", - Buckets: []float64{1, 5, 15, 30, 60, 120, 300, 600, 900, 1800, 3600, 7200}, - }), } } diff --git a/pkg/puller/puller.go b/pkg/puller/puller.go index 67564c8e9ed..2fdbc24e9cf 100644 --- a/pkg/puller/puller.go +++ b/pkg/puller/puller.go @@ -60,11 +60,6 @@ type Puller struct { metrics metrics logger log.Logger - // Historical sync tracking - syncStartTime time.Time - historicalSyncsMtx sync.Mutex - activeSyncs int - syncPeers map[string]*syncPeer // index is bin, map key is peer address syncPeersMtx sync.Mutex intervalMtx sync.Mutex @@ -120,10 +115,6 @@ func (p *Puller) Start(ctx context.Context) { cctx, cancel := context.WithCancel(ctx) p.cancel = cancel - // Initialize historical sync tracking - p.syncStartTime = time.Now() - p.activeSyncs = 0 - p.wg.Add(1) go p.manage(cctx) }) @@ -317,27 +308,6 @@ func (p *Puller) syncPeerBin(parentCtx context.Context, peer *syncPeer, bin uint sync := func(isHistorical bool, address swarm.Address, start uint64) { p.metrics.SyncWorkerCounter.Inc() - // Track historical sync start - if isHistorical { - p.historicalSyncsMtx.Lock() - p.activeSyncs++ - p.historicalSyncsMtx.Unlock() - } - - defer func() { - // Track historical sync completion and observe metrics if all syncs finished - if isHistorical { - p.historicalSyncsMtx.Lock() - p.activeSyncs-- - if p.activeSyncs == 0 { - // All historical syncs have completed, observe the total sync time - elapsed := time.Since(p.syncStartTime).Seconds() - p.metrics.HistoricalSyncTime.Observe(elapsed) - p.logger.Info("all historical syncs completed", "elapsed_seconds", elapsed) - } - p.historicalSyncsMtx.Unlock() - } - }() defer p.wg.Done() defer peer.wg.Done() defer p.metrics.SyncWorkerCounter.Dec() From 2ac05c9010e3d21a185819741de6b59b3a5d5238 Mon Sep 17 00:00:00 2001 From: nugaon Date: Fri, 18 Jul 2025 16:44:12 +0200 Subject: [PATCH 05/10] feat: add network storageDepth check --- pkg/node/node.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/node/node.go b/pkg/node/node.go index fff87d0af7d..a3398abb0b9 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -1168,7 +1168,7 @@ func NewBee( reserveTreshold := reserveCapacity >> 1 isFullySynced := func() bool { - return pullerService.SyncRate() == 0 && localStore.ReserveSize() >= reserveTreshold + return pullerService.SyncRate() == 0 && saludService.IsHealthy() && localStore.ReserveSize() >= reserveTreshold } syncCheckTicker := time.NewTicker(time.Second) From f5fe40388e31b77bb8d9d95749c6c2d425c95888 Mon Sep 17 00:00:00 2001 From: nugaon Date: Thu, 24 Jul 2025 15:42:49 +0200 Subject: [PATCH 06/10] refactor: decouple registering prometheus metrics --- pkg/node/metrics.go | 46 +++++++++++++++++++++++++++++++++++++++++++++ pkg/node/node.go | 26 +++++-------------------- 2 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 pkg/node/metrics.go diff --git a/pkg/node/metrics.go b/pkg/node/metrics.go new file mode 100644 index 00000000000..90005ceec7a --- /dev/null +++ b/pkg/node/metrics.go @@ -0,0 +1,46 @@ +// Copyright 2022 The Swarm Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package node + +import ( + "github.com/ethersphere/bee/v2/pkg/metrics" + "github.com/prometheus/client_golang/prometheus" +) + +type nodeMetrics struct { + // WarmupDuration measures time in seconds for the node warmup to complete + WarmupDuration prometheus.Histogram + // FullSyncDuration measures time in seconds for the full sync to complete + FullSyncDuration prometheus.Histogram +} + +func newMetrics() nodeMetrics { + subsystem := "init" + + return nodeMetrics{ + WarmupDuration: prometheus.NewHistogram( + prometheus.HistogramOpts{ + Namespace: metrics.Namespace, + Subsystem: subsystem, + Name: "warmup_duration_seconds", + Help: "Duration in seconds for node warmup to complete", + }, + ), + FullSyncDuration: prometheus.NewHistogram( + prometheus.HistogramOpts{ + Namespace: metrics.Namespace, + Subsystem: subsystem, + Name: "full_sync_duration_seconds", + Help: "Duration in seconds for node warmup to complete", + }, + ), + } +} + +// RegisterMetrics registers all metrics from the package +func (m nodeMetrics) RegisterMetrics() { + prometheus.MustRegister(m.WarmupDuration) + prometheus.MustRegister(m.FullSyncDuration) +} diff --git a/pkg/node/node.go b/pkg/node/node.go index a3398abb0b9..9d51fff05b8 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -210,6 +210,9 @@ func NewBee( warmupStartTime := time.Now() var pullSyncStartTime time.Time + nodeMetrics := newMetrics() + nodeMetrics.RegisterMetrics() + tracer, tracerCloser, err := tracing.NewTracer(&tracing.Options{ Enabled: o.TracingEnabled, Endpoint: o.TracingEndpoint, @@ -599,16 +602,6 @@ func NewBee( logger.Info("node warmup check initiated. monitoring activity rate to determine readiness.", "startTime", t) } - nodeWarmupDuration := prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: metrics.Namespace, - Subsystem: "init", - Name: "warmup_duration_seconds", - Help: "Duration in seconds for node warmup to complete", - }, - ) - prometheus.MustRegister(nodeWarmupDuration) - warmupMeasurement := func(t time.Time, totalCount int) { warmupDuration := t.Sub(warmupStartTime).Seconds() logger.Info("node warmup complete. system is considered stable and ready.", @@ -617,7 +610,7 @@ func NewBee( "warmupDurationSeconds", warmupDuration) // Record the warmup duration in the prometheus metric - nodeWarmupDuration.Observe(warmupDuration) + nodeMetrics.WarmupDuration.Observe(warmupDuration) pullSyncStartTime = t } detector.OnStabilized = warmupMeasurement @@ -1156,15 +1149,6 @@ func NewBee( // measure full sync duration detector.OnStabilized = func(t time.Time, totalCount int) { warmupMeasurement(t, totalCount) - fullSyncDuration := prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: metrics.Namespace, - Subsystem: "init", - Name: "full_sync_duration_seconds", - Help: "Duration in seconds for node warmup to complete", - }, - ) - prometheus.MustRegister(fullSyncDuration) reserveTreshold := reserveCapacity >> 1 isFullySynced := func() bool { @@ -1183,7 +1167,7 @@ func NewBee( logger.Debug("sync status check", "synced", synced, "reserveSize", localStore.ReserveSize(), "threshold", reserveTreshold, "syncRate", pullerService.SyncRate()) if synced { fullSyncTime := pullSyncStartTime.Sub(t) - fullSyncDuration.Observe(fullSyncTime.Seconds()) + nodeMetrics.FullSyncDuration.Observe(fullSyncTime.Seconds()) syncCheckTicker.Stop() return } From 3d057858b88d3ca59b2b4dd579e5d16f4de3ccd5 Mon Sep 17 00:00:00 2001 From: nugaon Date: Tue, 29 Jul 2025 16:26:14 +0200 Subject: [PATCH 07/10] feat: metric NeighborhoodAvgDur and NeighborCount --- pkg/salud/metrics.go | 17 +++++++++++++++++ pkg/salud/salud.go | 35 ++++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/pkg/salud/metrics.go b/pkg/salud/metrics.go index a99087d219b..832e75ddf31 100644 --- a/pkg/salud/metrics.go +++ b/pkg/salud/metrics.go @@ -19,6 +19,10 @@ type metrics struct { ReserveSizePercentErr prometheus.Gauge Healthy prometheus.Counter Unhealthy prometheus.Counter + + // Neighborhood-specific metrics + NeighborhoodAvgDur prometheus.Gauge + NeighborCount prometheus.Gauge } func newMetrics() metrics { @@ -79,6 +83,19 @@ func newMetrics() metrics { Name: "reserve_size_percentage_err", Help: "Percentage error of the reservesize relative to the network average.", }), + // Neighborhood-specific metrics + NeighborhoodAvgDur: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: m.Namespace, + Subsystem: subsystem, + Name: "neighborhood_dur", + Help: "Average duration for snapshot response from neighborhood peers.", + }), + NeighborCount: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: m.Namespace, + Subsystem: subsystem, + Name: "neighbors", + Help: "Number of neighborhood peers.", + }), } } diff --git a/pkg/salud/salud.go b/pkg/salud/salud.go index 8a9937adee2..7805d9b6117 100644 --- a/pkg/salud/salud.go +++ b/pkg/salud/salud.go @@ -136,11 +136,13 @@ type peer struct { // the allowed thresholds. func (s *service) salud(mode string, minPeersPerbin int, durPercentile float64, connsPercentile float64) { var ( - mtx sync.Mutex - wg sync.WaitGroup - totaldur float64 - peers []peer - bins [swarm.MaxBins]int + mtx sync.Mutex + wg sync.WaitGroup + totaldur float64 + peers []peer + bins [swarm.MaxBins]int + neighborhoodPeers []peer + neighborhoodTotalDur float64 ) err := s.topology.EachConnectedPeer(func(addr swarm.Address, bin uint8) (stop bool, jumpToNext bool, err error) { @@ -167,7 +169,12 @@ func (s *service) salud(mode string, minPeersPerbin int, durPercentile float64, mtx.Lock() bins[bin]++ totaldur += dur.Seconds() - peers = append(peers, peer{snapshot, dur, addr, bin, s.reserve.IsWithinStorageRadius(addr)}) + peer := peer{snapshot, dur, addr, bin, s.reserve.IsWithinStorageRadius(addr)} + peers = append(peers, peer) + if peer.neighbor { + neighborhoodPeers = append(neighborhoodPeers, peer) + neighborhoodTotalDur += dur.Seconds() + } mtx.Unlock() }() return false, false, nil @@ -188,6 +195,20 @@ func (s *service) salud(mode string, minPeersPerbin int, durPercentile float64, pConns := percentileConns(peers, connsPercentile) commitment := commitment(peers) + if len(neighborhoodPeers) > 0 { + neighborhoodAvgDur := neighborhoodTotalDur / float64(len(neighborhoodPeers)) + + s.metrics.NeighborhoodAvgDur.Set(neighborhoodAvgDur) + s.metrics.NeighborCount.Set(float64(len(neighborhoodPeers))) + + s.logger.Debug("neighborhood metrics", "avg_dur", neighborhoodAvgDur, "count", len(neighborhoodPeers)) + } else { + s.metrics.NeighborhoodAvgDur.Set(0) + s.metrics.NeighborCount.Set(0) + + s.logger.Debug("no neighborhood peers found for metrics") + } + s.metrics.AvgDur.Set(avgDur) s.metrics.PDur.Set(pDur) s.metrics.PConns.Set(float64(pConns)) @@ -195,7 +216,7 @@ func (s *service) salud(mode string, minPeersPerbin int, durPercentile float64, s.metrics.NeighborhoodRadius.Set(float64(nHoodRadius)) s.metrics.Commitment.Set(float64(commitment)) - s.logger.Debug("computed", "avg_dur", avgDur, "pDur", pDur, "pConns", pConns, "network_radius", networkRadius, "neighborhood_radius", nHoodRadius, "batch_commitment", commitment) + s.logger.Debug("computed", "avg_dur", avgDur, "pDur", pDur, "pConns", pConns, "network_radius", networkRadius, "neighborhood_radius", nHoodRadius, "batch_commitment", commitment, "neighborhood_peers", len(neighborhoodPeers)) // sort peers by duration, highest first to give priority to the fastest peers sort.Slice(peers, func(i, j int) bool { From 72fa9a81f670041dccfd1bd6b47d5e08680137e3 Mon Sep 17 00:00:00 2001 From: nugaon Date: Tue, 29 Jul 2025 17:22:21 +0200 Subject: [PATCH 08/10] fix: lint issue --- pkg/salud/metrics.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/salud/metrics.go b/pkg/salud/metrics.go index 832e75ddf31..8ac5abdb517 100644 --- a/pkg/salud/metrics.go +++ b/pkg/salud/metrics.go @@ -19,8 +19,6 @@ type metrics struct { ReserveSizePercentErr prometheus.Gauge Healthy prometheus.Counter Unhealthy prometheus.Counter - - // Neighborhood-specific metrics NeighborhoodAvgDur prometheus.Gauge NeighborCount prometheus.Gauge } From e26cfacd23ab5429ade560d88698f650720936b6 Mon Sep 17 00:00:00 2001 From: nugaon Date: Wed, 13 Aug 2025 09:58:52 +0200 Subject: [PATCH 09/10] refactor: check time increasing --- pkg/node/node.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/node/node.go b/pkg/node/node.go index 5caca6c2e45..f3f37b3f054 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -1158,7 +1158,7 @@ func NewBee( return pullerService.SyncRate() == 0 && saludService.IsHealthy() && localStore.ReserveSize() >= reserveTreshold } - syncCheckTicker := time.NewTicker(time.Second) + syncCheckTicker := time.NewTicker(2 * time.Second) go func() { defer syncCheckTicker.Stop() for { From 511394d22e0141ef303e5410f6c876d0b7d2f2e0 Mon Sep 17 00:00:00 2001 From: nugaon Date: Mon, 18 Aug 2025 13:04:51 +0200 Subject: [PATCH 10/10] refactor: counter instead of array of nPeers --- pkg/salud/salud.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/salud/salud.go b/pkg/salud/salud.go index 10054b3140f..28fe648d030 100644 --- a/pkg/salud/salud.go +++ b/pkg/salud/salud.go @@ -138,7 +138,7 @@ func (s *service) salud(mode string, durPercentile float64, connsPercentile floa wg sync.WaitGroup totaldur float64 peers []peer - neighborhoodPeers []peer + neighborhoodPeers uint neighborhoodTotalDur float64 ) @@ -168,7 +168,7 @@ func (s *service) salud(mode string, durPercentile float64, connsPercentile floa peer := peer{snapshot, dur, addr, bin, s.reserve.IsWithinStorageRadius(addr)} peers = append(peers, peer) if peer.neighbor { - neighborhoodPeers = append(neighborhoodPeers, peer) + neighborhoodPeers++ neighborhoodTotalDur += dur.Seconds() } mtx.Unlock() @@ -191,13 +191,13 @@ func (s *service) salud(mode string, durPercentile float64, connsPercentile floa pConns := percentileConns(peers, connsPercentile) commitment := commitment(peers) - if len(neighborhoodPeers) > 0 { - neighborhoodAvgDur := neighborhoodTotalDur / float64(len(neighborhoodPeers)) + if neighborhoodPeers > 0 { + neighborhoodAvgDur := neighborhoodTotalDur / float64(neighborhoodPeers) s.metrics.NeighborhoodAvgDur.Set(neighborhoodAvgDur) - s.metrics.NeighborCount.Set(float64(len(neighborhoodPeers))) + s.metrics.NeighborCount.Set(float64(neighborhoodPeers)) - s.logger.Debug("neighborhood metrics", "avg_dur", neighborhoodAvgDur, "count", len(neighborhoodPeers)) + s.logger.Debug("neighborhood metrics", "avg_dur", neighborhoodAvgDur, "count", neighborhoodPeers) } else { s.metrics.NeighborhoodAvgDur.Set(0) s.metrics.NeighborCount.Set(0) @@ -212,7 +212,7 @@ func (s *service) salud(mode string, durPercentile float64, connsPercentile floa s.metrics.NeighborhoodRadius.Set(float64(nHoodRadius)) s.metrics.Commitment.Set(float64(commitment)) - s.logger.Debug("computed", "avg_dur", avgDur, "pDur", pDur, "pConns", pConns, "network_radius", networkRadius, "neighborhood_radius", nHoodRadius, "batch_commitment", commitment, "neighborhood_peers", len(neighborhoodPeers)) + s.logger.Debug("computed", "avg_dur", avgDur, "pDur", pDur, "pConns", pConns, "network_radius", networkRadius, "neighborhood_radius", nHoodRadius, "batch_commitment", commitment, "neighborhood_peers", neighborhoodPeers) // sort peers by duration, highest first to give priority to the fastest peers sort.Slice(peers, func(i, j int) bool {