From ca3e6d93d366e0cf475365f2783f67c532435da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Wed, 11 Feb 2026 15:02:37 +0100 Subject: [PATCH] Add Netbird version tracking to client metrics Integrate Netbird version into VictoriaMetrics backend and metrics labels. Update `ClientMetrics` constructor and metric name formatting to include version information. --- client/internal/engine.go | 3 ++- client/internal/metrics/metrics.go | 4 ++-- client/internal/metrics/victoria.go | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/internal/engine.go b/client/internal/engine.go index 3c1518aa9..0fae4e616 100644 --- a/client/internal/engine.go +++ b/client/internal/engine.go @@ -66,6 +66,7 @@ import ( signal "github.com/netbirdio/netbird/shared/signal/client" sProto "github.com/netbirdio/netbird/shared/signal/proto" "github.com/netbirdio/netbird/util" + "github.com/netbirdio/netbird/version" ) // PeerConnectionTimeoutMax is a timeout of an initial connection attempt to a remote peer. @@ -278,7 +279,7 @@ func NewEngine( connSemaphore: semaphoregroup.NewSemaphoreGroup(connInitLimit), probeStunTurn: relay.NewStunTurnProbe(relay.DefaultCacheTTL), jobExecutor: jobexec.NewExecutor(), - clientMetrics: metrics.NewClientMetrics(deploymentType, true), + clientMetrics: metrics.NewClientMetrics(deploymentType, version.NetbirdVersion(), true), } log.Infof("I am: %s", config.WgPrivateKey.PublicKey().String()) diff --git a/client/internal/metrics/metrics.go b/client/internal/metrics/metrics.go index 98df1a6a3..7699f5b02 100644 --- a/client/internal/metrics/metrics.go +++ b/client/internal/metrics/metrics.go @@ -36,12 +36,12 @@ 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(deploymentType DeploymentType, enabled bool) *ClientMetrics { +func NewClientMetrics(deploymentType DeploymentType, version string, enabled bool) *ClientMetrics { var impl metricsImplementation if !enabled { impl = &noopMetrics{} } else { - impl = newVictoriaMetrics(deploymentType) + impl = newVictoriaMetrics(deploymentType, version) } return &ClientMetrics{impl: impl} } diff --git a/client/internal/metrics/victoria.go b/client/internal/metrics/victoria.go index 63fadc76a..10ee713da 100644 --- a/client/internal/metrics/victoria.go +++ b/client/internal/metrics/victoria.go @@ -13,14 +13,16 @@ import ( type victoriaMetrics struct { // Static attributes applied to all metrics deploymentType DeploymentType + version string // Metrics set for managing all metrics set *metrics.Set } -func newVictoriaMetrics(deploymentType DeploymentType) metricsImplementation { +func newVictoriaMetrics(deploymentType DeploymentType, version string) metricsImplementation { return &victoriaMetrics{ deploymentType: deploymentType, + version: version, set: metrics.NewSet(), } } @@ -92,11 +94,12 @@ func (m *victoriaMetrics) RecordConnectionStages( // getMetricName constructs a metric name with labels func (m *victoriaMetrics) getMetricName(baseName, connectionType, attemptType string) string { - return fmt.Sprintf(`%s{deployment_type=%q,connection_type=%q,attempt_type=%q}`, + return fmt.Sprintf(`%s{deployment_type=%q,connection_type=%q,attempt_type=%q,version=%q}`, baseName, m.deploymentType.String(), connectionType, attemptType, + m.version, ) }