From 4e9f10600eb8a9432aab1ee65a7c9e7571f8e2be Mon Sep 17 00:00:00 2001 From: Wondertan Date: Tue, 24 Oct 2023 16:32:45 +0200 Subject: [PATCH] review comments --- p2p/exchange_metrics.go | 12 ++++++------ p2p/peer_tracker.go | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/p2p/exchange_metrics.go b/p2p/exchange_metrics.go index 9eef1814..b63d4e65 100644 --- a/p2p/exchange_metrics.go +++ b/p2p/exchange_metrics.go @@ -16,9 +16,9 @@ var meter = otel.Meter("header/p2p") const ( failedKey = "failed" headerReceivedKey = "num_headers_received" - headTypeKey = "type" - headTypeTrusted = "trusted" - headTypeUntrusted = "untrusted" + headTypeKey = "request_type" + headTypeTrusted = "trusted_request" + headTypeUntrusted = "untrusted_request" headStatusKey = "status" headStatusOk = "ok" headStatusTimeout = "timeout" @@ -29,7 +29,7 @@ const ( type exchangeMetrics struct { headRequestTimeInst metric.Int64Histogram responseSizeInst metric.Int64Histogram - responseTimeInst metric.Int64Histogram + responseTimeInst metric.Float64Histogram blockedPeersNum metric.Int64Counter trackerPeersNum atomic.Int64 @@ -57,7 +57,7 @@ func newExchangeMetrics() (m *exchangeMetrics, err error) { if err != nil { return nil, err } - m.responseTimeInst, err = meter.Int64Histogram( + m.responseTimeInst, err = meter.Float64Histogram( "hdr_p2p_exch_clnt_resp_time_hist", metric.WithDescription("exchange client response time in milliseconds"), ) @@ -109,7 +109,7 @@ func (m *exchangeMetrics) response(ctx context.Context, size uint64, duration ti metric.WithAttributes(attribute.Bool(failedKey, err != nil)), ) m.responseTimeInst.Record(ctx, - duration.Milliseconds(), + duration.Seconds(), metric.WithAttributes(attribute.Bool(failedKey, err != nil)), ) }) diff --git a/p2p/peer_tracker.go b/p2p/peer_tracker.go index 8e61ed44..4ca53576 100644 --- a/p2p/peer_tracker.go +++ b/p2p/peer_tracker.go @@ -30,7 +30,7 @@ var ( type peerTracker struct { host host.Host connGater *conngater.BasicConnectionGater - metric *exchangeMetrics + metrics *exchangeMetrics peerLk sync.RWMutex // trackedPeers contains active peers that we can request to. @@ -62,7 +62,7 @@ func newPeerTracker( return &peerTracker{ host: h, connGater: connGater, - metric: metrics, + metrics: metrics, trackedPeers: make(map[libpeer.ID]*peerStat), disconnectedPeers: make(map[libpeer.ID]*peerStat), pidstore: pidstore, @@ -200,7 +200,7 @@ func (p *peerTracker) connected(pID libpeer.ID) { } p.trackedPeers[pID] = stats - p.metric.peersTracked(1) + p.metrics.peersTracked(1) } func (p *peerTracker) disconnected(pID libpeer.ID) { @@ -214,8 +214,8 @@ func (p *peerTracker) disconnected(pID libpeer.ID) { p.disconnectedPeers[pID] = stats delete(p.trackedPeers, pID) - p.metric.peersTracked(-1) - p.metric.peersDisconnected(1) + p.metrics.peersTracked(-1) + p.metrics.peersDisconnected(1) } func (p *peerTracker) peers() []*peerStat { @@ -260,8 +260,8 @@ func (p *peerTracker) gc() { } p.peerLk.Unlock() - p.metric.peersDisconnected(-deletedDisconnectedNum) - p.metric.peersTracked(-deletedTrackedNum) + p.metrics.peersDisconnected(-deletedDisconnectedNum) + p.metrics.peersTracked(-deletedTrackedNum) p.dumpPeers(p.ctx) } } @@ -324,5 +324,5 @@ func (p *peerTracker) blockPeer(pID libpeer.ID, reason error) { } log.Warnw("header/p2p: blocked peer", "pID", pID, "reason", reason) - p.metric.peerBlocked(p.ctx) + p.metrics.peerBlocked(p.ctx) }