fix_: bandwidthCounter should be reset each time it is retrieved otherwise it behaves like an accumulator (#5898)

This commit is contained in:
richΛrd 2024-10-02 09:26:58 -04:00 committed by GitHub
parent 66ee53175e
commit 7a737433d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 10 deletions

View File

@ -519,20 +519,14 @@ func (w *Waku) telemetryBandwidthStats(telemetryServerURL string) {
ticker := time.NewTicker(time.Second * 20) ticker := time.NewTicker(time.Second * 20)
defer ticker.Stop() defer ticker.Stop()
today := time.Now()
for { for {
select { select {
case <-w.ctx.Done(): case <-w.ctx.Done():
return return
case now := <-ticker.C: case <-ticker.C:
// Reset totals when day changes bandwidthPerProtocol := w.bandwidthCounter.GetBandwidthByProtocol()
if now.Day() != today.Day() {
today = now
w.bandwidthCounter.Reset() w.bandwidthCounter.Reset()
} go telemetry.PushProtocolStats(bandwidthPerProtocol)
go telemetry.PushProtocolStats(w.bandwidthCounter.GetBandwidthByProtocol())
} }
} }
} }