Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Oct 24, 2023
1 parent 28ee760 commit 4e9f106
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions p2p/exchange_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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"),
)
Expand Down Expand Up @@ -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)),
)
})
Expand Down
16 changes: 8 additions & 8 deletions p2p/peer_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}

0 comments on commit 4e9f106

Please sign in to comment.