add metrics

This commit is contained in:
Pascal Fischer
2025-06-25 12:09:06 +02:00
parent 905a3481ec
commit ed6ed4a597
3 changed files with 65 additions and 9 deletions

View File

@@ -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) {