chore_: use peerId instead of random hostId

This commit is contained in:
Václav Pavlín 2024-10-03 15:29:45 +02:00
parent d794e43347
commit 9f29a09e01
No known key found for this signature in database
GPG Key ID: B378FB31BB6D89A5
3 changed files with 6 additions and 7 deletions

View File

@ -7,7 +7,6 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/google/uuid"
"github.com/libp2p/go-libp2p/core/metrics" "github.com/libp2p/go-libp2p/core/metrics"
"github.com/libp2p/go-libp2p/core/protocol" "github.com/libp2p/go-libp2p/core/protocol"
"go.uber.org/zap" "go.uber.org/zap"
@ -21,15 +20,15 @@ import (
type BandwidthTelemetryClient struct { type BandwidthTelemetryClient struct {
serverURL string serverURL string
httpClient *http.Client httpClient *http.Client
hostID string peerId string
logger *zap.Logger logger *zap.Logger
} }
func NewBandwidthTelemetryClient(logger *zap.Logger, serverURL string) *BandwidthTelemetryClient { func NewBandwidthTelemetryClient(logger *zap.Logger, serverURL string, peerId string) *BandwidthTelemetryClient {
return &BandwidthTelemetryClient{ return &BandwidthTelemetryClient{
serverURL: serverURL, serverURL: serverURL,
httpClient: &http.Client{Timeout: time.Minute}, httpClient: &http.Client{Timeout: time.Minute},
hostID: uuid.NewString(), peerId: peerId,
logger: logger.Named("bandwidth-telemetry"), 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{} { func (c *BandwidthTelemetryClient) getTelemetryRequestBody(stats map[protocol.ID]metrics.Stats) map[string]interface{} {
return map[string]interface{}{ return map[string]interface{}{
"hostID": c.hostID, "hostID": c.peerId,
"relay": getStatsPerProtocol(relay.WakuRelayID_v200, stats), "relay": getStatsPerProtocol(relay.WakuRelayID_v200, stats),
"store": getStatsPerProtocol(legacy_store.StoreID_v20beta4, stats), "store": getStatsPerProtocol(legacy_store.StoreID_v20beta4, stats),
"filter-push": getStatsPerProtocol(filter.FilterPushID_v20beta1, stats), "filter-push": getStatsPerProtocol(filter.FilterPushID_v20beta1, stats),

View File

@ -510,7 +510,7 @@ func (w *Waku) telemetryBandwidthStats(telemetryServerURL string) {
return return
} }
telemetry := NewBandwidthTelemetryClient(w.logger, telemetryServerURL) telemetry := NewBandwidthTelemetryClient(w.logger, telemetryServerURL, w.PeerID().String())
ticker := time.NewTicker(time.Second * 20) ticker := time.NewTicker(time.Second * 20)
defer ticker.Stop() defer ticker.Stop()

View File

@ -787,7 +787,7 @@ func TestTelemetryFormat(t *testing.T) {
logger, err := zap.NewDevelopment() logger, err := zap.NewDevelopment()
require.NoError(t, err) require.NoError(t, err)
tc := NewBandwidthTelemetryClient(logger, "#") tc := NewBandwidthTelemetryClient(logger, "#", "peerId")
s := metrics.Stats{ s := metrics.Stats{
TotalIn: 10, TotalIn: 10,