Skip to content

Commit

Permalink
p2p: adds debug logs for metric issue (#1791)
Browse files Browse the repository at this point in the history
Adds debug logs to identify invalid `p2p_peer_connection_types` metric values.

category: bug 
ticket: #1790
  • Loading branch information
corverroos authored Feb 10, 2023
1 parent f6e660f commit 7c0b207
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,15 @@ func RegisterConnectionLogger(ctx context.Context, tcpNode host.Host, peerIDs []
quit := make(chan struct{})
defer close(quit)

type connType struct {
Peer peer.ID
Type string
}

var (
peers = make(map[peer.ID]bool)
events = make(chan logEvent)
peers = make(map[peer.ID]bool)
events = make(chan logEvent)
typeCounts = make(map[connType]int)
)

for _, p := range peerIDs {
Expand Down Expand Up @@ -237,13 +243,26 @@ func RegisterConnectionLogger(ctx context.Context, tcpNode host.Host, peerIDs []
continue
}

typeKey := connType{Peer: e.Peer, Type: typ}

if e.Connected {
peerConnGauge.WithLabelValues(name, addrType(e.Addr)).Inc()
peerConnCounter.WithLabelValues(name).Inc()
typeCounts[typeKey]++
} else if e.Disconnect {
peerConnGauge.WithLabelValues(name, addrType(e.Addr)).Dec()
typeCounts[typeKey]--
}

// TODO(corver): Remove once gauge count issue #1790 identified and fixed.
log.Debug(ctx, "Libp2p connected count updated",
z.Str("peer", name),
z.Any("peer_address", addr),
z.Any("direction", e.Direction),
z.Str("type", typ),
z.Int("count", typeCounts[typeKey]),
)

// Ensure both connection type metrics are initiated
peerConnGauge.WithLabelValues(name, addrTypeDirect).Add(0)
peerConnGauge.WithLabelValues(name, addrTypeRelay).Add(0)
Expand Down

0 comments on commit 7c0b207

Please sign in to comment.