Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions wakuv2/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,20 +519,14 @@ func (w *Waku) telemetryBandwidthStats(telemetryServerURL string) {
ticker := time.NewTicker(time.Second * 20)
defer ticker.Stop()

today := time.Now()

for {
select {
case <-w.ctx.Done():
return
case now := <-ticker.C:
// Reset totals when day changes
if now.Day() != today.Day() {
today = now
w.bandwidthCounter.Reset()
}

go telemetry.PushProtocolStats(w.bandwidthCounter.GetBandwidthByProtocol())
case <-ticker.C:
bandwidthPerProtocol := w.bandwidthCounter.GetBandwidthByProtocol()
w.bandwidthCounter.Reset()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean if we want to use GetBandwidthByPeer or some other metric which uses same underlying counter, it will not work right..we will have to get all the metrics in same place and reset the counter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly yes, it is not possible to have multiple bandwidth counters

go telemetry.PushProtocolStats(bandwidthPerProtocol)
}
}
}
Expand Down