From 9f29a09e011f0b14cb11b39565546cd629322609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Pavl=C3=ADn?= Date: Thu, 3 Oct 2024 15:29:45 +0200 Subject: [PATCH] chore_: use peerId instead of random hostId --- wakuv2/telemetry.go | 9 ++++----- wakuv2/waku.go | 2 +- wakuv2/waku_test.go | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/wakuv2/telemetry.go b/wakuv2/telemetry.go index 581225d52..57f2d555d 100644 --- a/wakuv2/telemetry.go +++ b/wakuv2/telemetry.go @@ -7,7 +7,6 @@ import ( "net/http" "time" - "github.com/google/uuid" "github.com/libp2p/go-libp2p/core/metrics" "github.com/libp2p/go-libp2p/core/protocol" "go.uber.org/zap" @@ -21,15 +20,15 @@ import ( type BandwidthTelemetryClient struct { serverURL string httpClient *http.Client - hostID string + peerId string logger *zap.Logger } -func NewBandwidthTelemetryClient(logger *zap.Logger, serverURL string) *BandwidthTelemetryClient { +func NewBandwidthTelemetryClient(logger *zap.Logger, serverURL string, peerId string) *BandwidthTelemetryClient { return &BandwidthTelemetryClient{ serverURL: serverURL, httpClient: &http.Client{Timeout: time.Minute}, - hostID: uuid.NewString(), + peerId: peerId, logger: logger.Named("bandwidth-telemetry"), } } @@ -45,7 +44,7 @@ func getStatsPerProtocol(protocolID protocol.ID, stats map[protocol.ID]metrics.S func (c *BandwidthTelemetryClient) getTelemetryRequestBody(stats map[protocol.ID]metrics.Stats) map[string]interface{} { return map[string]interface{}{ - "hostID": c.hostID, + "hostID": c.peerId, "relay": getStatsPerProtocol(relay.WakuRelayID_v200, stats), "store": getStatsPerProtocol(legacy_store.StoreID_v20beta4, stats), "filter-push": getStatsPerProtocol(filter.FilterPushID_v20beta1, stats), diff --git a/wakuv2/waku.go b/wakuv2/waku.go index 63a0f0830..cbb3e43e0 100644 --- a/wakuv2/waku.go +++ b/wakuv2/waku.go @@ -510,7 +510,7 @@ func (w *Waku) telemetryBandwidthStats(telemetryServerURL string) { return } - telemetry := NewBandwidthTelemetryClient(w.logger, telemetryServerURL) + telemetry := NewBandwidthTelemetryClient(w.logger, telemetryServerURL, w.PeerID().String()) ticker := time.NewTicker(time.Second * 20) defer ticker.Stop() diff --git a/wakuv2/waku_test.go b/wakuv2/waku_test.go index 9792e5082..b5e564400 100644 --- a/wakuv2/waku_test.go +++ b/wakuv2/waku_test.go @@ -787,7 +787,7 @@ func TestTelemetryFormat(t *testing.T) { logger, err := zap.NewDevelopment() require.NoError(t, err) - tc := NewBandwidthTelemetryClient(logger, "#") + tc := NewBandwidthTelemetryClient(logger, "#", "peerId") s := metrics.Stats{ TotalIn: 10,