From 7e276a40d9f97acb6f8b1442f8245af72cc54751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Wed, 11 Feb 2026 15:41:32 +0100 Subject: [PATCH] Add total duration tracking for connection attempts Calculate total duration for both initial connections and reconnections, accounting for different timestamp scenarios. Update `Export` method to include Prometheus HELP comments. --- client/internal/metrics/victoria.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/internal/metrics/victoria.go b/client/internal/metrics/victoria.go index 32706a1f9..18889856d 100644 --- a/client/internal/metrics/victoria.go +++ b/client/internal/metrics/victoria.go @@ -52,8 +52,13 @@ func (m *victoriaMetrics) RecordConnectionStages( connectionToHandshake = timestamps.WgHandshakeSuccess.Sub(timestamps.ConnectionReady).Seconds() } + // Calculate total duration: + // For initial connections: Created → WgHandshakeSuccess + // For reconnections: Signaling → WgHandshakeSuccess (since Created is not tracked) if !timestamps.Created.IsZero() && !timestamps.WgHandshakeSuccess.IsZero() { totalDuration = timestamps.WgHandshakeSuccess.Sub(timestamps.Created).Seconds() + } else if !timestamps.Signaling.IsZero() && !timestamps.WgHandshakeSuccess.IsZero() { + totalDuration = timestamps.WgHandshakeSuccess.Sub(timestamps.Signaling).Seconds() } // Determine attempt type @@ -112,7 +117,7 @@ func (m *victoriaMetrics) RecordSyncDuration(ctx context.Context, duration time. m.set.GetOrCreateHistogram(metricName).Update(duration.Seconds()) } -// Export writes metrics in Prometheus text format +// Export writes metrics in Prometheus text format with HELP comments func (m *victoriaMetrics) Export(w io.Writer) error { if m.set == nil { return fmt.Errorf("metrics set not initialized")