Skip to content

Commit

Permalink
diagnostics: Peername (#12184)
Browse files Browse the repository at this point in the history
Added peer name collection by diagnostics
  • Loading branch information
dvovk authored Oct 2, 2024
1 parent bcee5fb commit b013526
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions cl/sentinel/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ func trackPeerStatistics(peerID string, inbound bool, msgType string, msgCap str
isDiagEnabled := diagnostics.TypeOf(diagnostics.PeerStatisticMsgUpdate{}).Enabled()
if isDiagEnabled {
diagnostics.Send(diagnostics.PeerStatisticMsgUpdate{
PeerName: "TODO",
PeerType: "Sentinel",
PeerID: peerID,
Inbound: inbound,
Expand Down
2 changes: 1 addition & 1 deletion diagnostics/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func peers(diag *diaglib.DiagnosticClient) []*PeerResponse {
ENR: "", //TODO: find a way how to get missing data
Enode: "",
ID: key,
Name: "",
Name: value.PeerName,
Type: value.PeerType,
Caps: []string{},
Network: PeerNetworkInfo{
Expand Down
5 changes: 4 additions & 1 deletion erigon-lib/diagnostics/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

type PeerStatistics struct {
PeerName string
PeerType string
BytesIn uint64
BytesOut uint64
Expand All @@ -48,7 +49,8 @@ func (p PeerStatistics) Equal(p2 PeerStatistics) bool {
maps.Equal(p.CapBytesIn, p2.CapBytesIn) &&
maps.Equal(p.CapBytesOut, p2.CapBytesOut) &&
maps.Equal(p.TypeBytesIn, p2.TypeBytesIn) &&
maps.Equal(p.TypeBytesOut, p2.TypeBytesOut)
maps.Equal(p.TypeBytesOut, p2.TypeBytesOut) &&
p.PeerName == p2.PeerName
}

type PeerDataUpdate struct {
Expand All @@ -62,6 +64,7 @@ type PeerDataUpdate struct {
}

type PeerStatisticMsgUpdate struct {
PeerName string
PeerType string
PeerID string
Inbound bool
Expand Down
1 change: 1 addition & 0 deletions erigon-lib/diagnostics/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func PeerStatisticsFromMsgUpdate(msg PeerStatisticMsgUpdate, prevValue any) Peer

func peerStatisticsFromMsgUpdate(msg PeerStatisticMsgUpdate, prevValue any) PeerStatistics {
ps := PeerStatistics{
PeerName: msg.PeerName,
PeerType: msg.PeerType,
BytesIn: 0,
BytesOut: 0,
Expand Down
2 changes: 2 additions & 0 deletions erigon-lib/diagnostics/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var mockOutboundPeerStats = diagnostics.PeerStatistics{
}

var mockInboundUpdMsg = diagnostics.PeerStatisticMsgUpdate{
PeerName: "",
PeerType: "Sentinel",
PeerID: "test1",
Inbound: true,
Expand All @@ -54,6 +55,7 @@ var mockInboundUpdMsg = diagnostics.PeerStatisticMsgUpdate{
}

var mockOutboundUpdMsg = diagnostics.PeerStatisticMsgUpdate{
PeerName: "",
PeerType: "Sentinel",
PeerID: "test1",
Inbound: false,
Expand Down
7 changes: 4 additions & 3 deletions p2p/sentry/sentry_grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,17 +558,18 @@ func runPeer(
msgType := eth.ToProto[protocol][msg.Code]
msgCap := cap.String()

trackPeerStatistics(peerInfo.peer.Info().ID, true, msgType.String(), msgCap, int(msg.Size))
trackPeerStatistics(peerInfo.peer.Info().Name, peerInfo.peer.Info().ID, true, msgType.String(), msgCap, int(msg.Size))

msg.Discard()
peerInfo.ClearDeadlines(time.Now(), givePermit)
}
}

func trackPeerStatistics(peerID string, inbound bool, msgType string, msgCap string, bytes int) {
func trackPeerStatistics(peerName string, peerID string, inbound bool, msgType string, msgCap string, bytes int) {
isDiagEnabled := diagnostics.TypeOf(diagnostics.PeerStatisticMsgUpdate{}).Enabled()
if isDiagEnabled {
stats := diagnostics.PeerStatisticMsgUpdate{
PeerName: peerName,
PeerID: peerID,
Inbound: inbound,
MsgType: msgType,
Expand Down Expand Up @@ -778,7 +779,7 @@ func (ss *GrpcServer) writePeer(logPrefix string, peerInfo *PeerInfo, msgcode ui

cap := p2p.Cap{Name: eth.ProtocolName, Version: peerInfo.protocol}
msgType := eth.ToProto[cap.Version][msgcode]
trackPeerStatistics(peerInfo.peer.Info().ID, false, msgType.String(), cap.String(), len(data))
trackPeerStatistics(peerInfo.peer.Info().Name, peerInfo.peer.Info().ID, false, msgType.String(), cap.String(), len(data))

err := peerInfo.rw.WriteMsg(p2p.Msg{Code: msgcode, Size: uint32(len(data)), Payload: bytes.NewReader(data)})
if err != nil {
Expand Down

0 comments on commit b013526

Please sign in to comment.