mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-21 17:56:39 +00:00
add metrics
This commit is contained in:
@@ -3,17 +3,20 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/netbirdio/netbird/management/server/telemetry"
|
||||
)
|
||||
|
||||
type UpdateBuffer struct {
|
||||
mu sync.Mutex
|
||||
cond *sync.Cond
|
||||
update *UpdateMessage
|
||||
closed bool
|
||||
mu sync.Mutex
|
||||
cond *sync.Cond
|
||||
update *UpdateMessage
|
||||
closed bool
|
||||
metrics *telemetry.UpdateChannelMetrics
|
||||
}
|
||||
|
||||
func NewUpdateBuffer() *UpdateBuffer {
|
||||
ub := &UpdateBuffer{}
|
||||
func NewUpdateBuffer(metrics *telemetry.UpdateChannelMetrics) *UpdateBuffer {
|
||||
ub := &UpdateBuffer{metrics: metrics}
|
||||
ub.cond = sync.NewCond(&ub.mu)
|
||||
return ub
|
||||
}
|
||||
@@ -22,11 +25,22 @@ func (b *UpdateBuffer) Push(update *UpdateMessage) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
|
||||
// the equal case we need because we don't always increment the serial number
|
||||
if b.update == nil || update.NetworkMap.Network.Serial >= b.update.NetworkMap.Network.Serial {
|
||||
if b.update == nil {
|
||||
b.update = update
|
||||
b.cond.Signal()
|
||||
b.metrics.CountBufferPush()
|
||||
return
|
||||
}
|
||||
|
||||
// the equal case we need because we don't always increment the serial number
|
||||
if update.NetworkMap.Network.Serial >= b.update.NetworkMap.Network.Serial {
|
||||
b.update = update
|
||||
b.cond.Signal()
|
||||
b.metrics.CountBufferOverwrite()
|
||||
return
|
||||
}
|
||||
|
||||
b.metrics.CountBufferIgnore()
|
||||
}
|
||||
|
||||
func (b *UpdateBuffer) Pop(ctx context.Context) (*UpdateMessage, bool) {
|
||||
|
||||
Reference in New Issue
Block a user