Skip to content

Commit 492ea53

Browse files
feat(pushsync): add rate limiting and metric for overdraft refresh logs (#5297)
1 parent aed9d55 commit 492ea53

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pkg/pushsync/metrics.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type metrics struct {
2828
ReceiptDepth *prometheus.CounterVec
2929
ShallowReceiptDepth *prometheus.CounterVec
3030
ShallowReceipt prometheus.Counter
31+
OverdraftRefresh prometheus.Counter
3132
}
3233

3334
func newMetrics() metrics {
@@ -146,6 +147,12 @@ func newMetrics() metrics {
146147
},
147148
[]string{"depth"},
148149
),
150+
OverdraftRefresh: prometheus.NewCounter(prometheus.CounterOpts{
151+
Namespace: m.Namespace,
152+
Subsystem: subsystem,
153+
Name: "overdraft_refresh",
154+
Help: "Total number of times peers were skipped due to overdraft, requiring a wait to refresh balance.",
155+
}),
149156
}
150157
}
151158

pkg/pushsync/pushsync.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/opentracing/opentracing-go"
3333
"github.com/opentracing/opentracing-go/ext"
3434
olog "github.com/opentracing/opentracing-go/log"
35+
"golang.org/x/time/rate"
3536
)
3637

3738
// loggerName is the tree path name of the logger for this package.
@@ -99,6 +100,7 @@ type PushSync struct {
99100
stabilizer stabilization.Subscriber
100101

101102
shallowReceiptTolerance uint8
103+
overDraftRefreshLimiter *rate.Limiter
102104
}
103105

104106
type receiptResult struct {
@@ -148,6 +150,7 @@ func New(
148150
errSkip: skippeers.NewList(time.Minute),
149151
stabilizer: stabilizer,
150152
shallowReceiptTolerance: shallowReceiptTolerance,
153+
overDraftRefreshLimiter: rate.NewLimiter(rate.Every(time.Second), 1),
151154
}
152155

153156
ps.validStamp = ps.validStampWrapper(validStamp)
@@ -424,7 +427,10 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, origin bo
424427
continue // there is still an inflight request, wait for it's result
425428
}
426429

427-
ps.logger.Debug("sleeping to refresh overdraft balance", "chunk_address", ch.Address())
430+
ps.metrics.OverdraftRefresh.Inc()
431+
if ps.overDraftRefreshLimiter.Allow() {
432+
ps.logger.Debug("sleeping to refresh overdraft balance")
433+
}
428434

429435
select {
430436
case <-time.After(overDraftRefresh):

0 commit comments

Comments
 (0)