mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-06 15:01:28 +02:00
Remove no-op metrics implementation and simplify ClientMetrics constructor
Eliminate unused `noopMetrics` and refactor `ClientMetrics` to always use the VictoriaMetrics implementation. Update associated logic to reflect these changes.
This commit is contained in:
@@ -279,12 +279,12 @@ func NewEngine(
|
||||
connSemaphore: semaphoregroup.NewSemaphoreGroup(connInitLimit),
|
||||
probeStunTurn: relay.NewStunTurnProbe(relay.DefaultCacheTTL),
|
||||
jobExecutor: jobexec.NewExecutor(),
|
||||
clientMetrics: metrics.NewClientMetrics(metrics.AgentInfo{
|
||||
DeploymentType: deploymentType,
|
||||
Version: version.NetbirdVersion(),
|
||||
}, true),
|
||||
}
|
||||
|
||||
engine.clientMetrics = metrics.NewClientMetrics(metrics.AgentInfo{
|
||||
DeploymentType: deploymentType,
|
||||
Version: version.NetbirdVersion()})
|
||||
|
||||
log.Infof("I am: %s", config.WgPrivateKey.PublicKey().String())
|
||||
return engine
|
||||
}
|
||||
|
||||
@@ -43,16 +43,8 @@ type ConnectionStageTimestamps struct {
|
||||
}
|
||||
|
||||
// NewClientMetrics creates a new ClientMetrics instance
|
||||
// If enabled is true, uses an OpenTelemetry implementation
|
||||
// If enabled is false, uses a no-op implementation
|
||||
func NewClientMetrics(agentInfo AgentInfo, enabled bool) *ClientMetrics {
|
||||
var impl metricsImplementation
|
||||
if !enabled {
|
||||
impl = &noopMetrics{}
|
||||
} else {
|
||||
impl = newVictoriaMetrics(agentInfo)
|
||||
}
|
||||
return &ClientMetrics{impl: impl}
|
||||
func NewClientMetrics(agentInfo AgentInfo) *ClientMetrics {
|
||||
return &ClientMetrics{impl: newVictoriaMetrics(agentInfo)}
|
||||
}
|
||||
|
||||
// RecordConnectionStages calculates stage durations from timestamps and records them
|
||||
@@ -62,15 +54,24 @@ func (c *ClientMetrics) RecordConnectionStages(
|
||||
isReconnection bool,
|
||||
timestamps ConnectionStageTimestamps,
|
||||
) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
c.impl.RecordConnectionStages(ctx, connectionType, isReconnection, timestamps)
|
||||
}
|
||||
|
||||
// RecordSyncDuration records the duration of sync message processing
|
||||
func (c *ClientMetrics) RecordSyncDuration(ctx context.Context, duration time.Duration) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
c.impl.RecordSyncDuration(ctx, duration)
|
||||
}
|
||||
|
||||
// Export exports metrics to the writer
|
||||
func (c *ClientMetrics) Export(w io.Writer) error {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return c.impl.Export(w)
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
// noopMetrics is a no-op implementation of metricsImplementation
|
||||
type noopMetrics struct{}
|
||||
|
||||
func (s *noopMetrics) RecordConnectionStages(
|
||||
_ context.Context,
|
||||
_ ConnectionType,
|
||||
_ bool,
|
||||
_ ConnectionStageTimestamps,
|
||||
) {
|
||||
// No-op
|
||||
}
|
||||
|
||||
func (s *noopMetrics) RecordSyncDuration(_ context.Context, _ time.Duration) {
|
||||
// No-op
|
||||
}
|
||||
|
||||
func (s *noopMetrics) Export(_ io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user