fix(telemetry)_: do not send peer count more than once per second (#5698)

This commit is contained in:
Arseniy Klempner 2024-08-30 09:49:31 -07:00 committed by GitHub
parent 27d02d5fc8
commit 250a7d2f15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -59,8 +59,10 @@ func (c *Client) PushErrorSendingEnvelope(ctx context.Context, errorSendingEnvel
}
func (c *Client) PushPeerCount(ctx context.Context, peerCount int) {
if peerCount != c.lastPeerCount {
now := time.Now()
if peerCount != c.lastPeerCount && now.Sub(c.lastPeerCountTime) > 1*time.Second {
c.lastPeerCount = peerCount
c.lastPeerCountTime = now
c.processAndPushTelemetry(ctx, PeerCount{PeerCount: peerCount})
}
}
@ -108,6 +110,7 @@ type Client struct {
nextId int
sendPeriod time.Duration
lastPeerCount int
lastPeerCountTime time.Time
lastPeerConnFailures map[string]int
deviceType string
}
@ -143,6 +146,7 @@ func NewClient(logger *zap.Logger, serverURL string, keyUID string, nodeName str
nextIdLock: sync.Mutex{},
sendPeriod: 10 * time.Second, // default value
lastPeerCount: 0,
lastPeerCountTime: time.Time{},
lastPeerConnFailures: make(map[string]int),
}