mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
p2p: add metrics for inbound connection errors (#31652)
Add metics detailing reasons we reject inbound connections for, and reasons these connections fail during the handshake.
This commit is contained in:
parent
3e356d69ef
commit
0d5de826da
2 changed files with 44 additions and 0 deletions
|
|
@ -66,6 +66,18 @@ var (
|
||||||
|
|
||||||
// capture the rest of errors that are not handled by the above meters
|
// capture the rest of errors that are not handled by the above meters
|
||||||
dialOtherError = metrics.NewRegisteredMeter("p2p/dials/error/other", nil)
|
dialOtherError = metrics.NewRegisteredMeter("p2p/dials/error/other", nil)
|
||||||
|
|
||||||
|
// handshake error meters for inbound connections
|
||||||
|
serveTooManyPeers = metrics.NewRegisteredMeter("p2p/serves/error/saturated", nil)
|
||||||
|
serveAlreadyConnected = metrics.NewRegisteredMeter("p2p/serves/error/known", nil)
|
||||||
|
serveSelf = metrics.NewRegisteredMeter("p2p/serves/error/self", nil)
|
||||||
|
serveUselessPeer = metrics.NewRegisteredMeter("p2p/serves/error/useless", nil)
|
||||||
|
serveUnexpectedIdentity = metrics.NewRegisteredMeter("p2p/serves/error/id/unexpected", nil)
|
||||||
|
serveEncHandshakeError = metrics.NewRegisteredMeter("p2p/serves/error/rlpx/enc", nil) //EOF; connection reset during handshake; (message too big?)
|
||||||
|
serveProtoHandshakeError = metrics.NewRegisteredMeter("p2p/serves/error/rlpx/proto", nil)
|
||||||
|
|
||||||
|
// capture the rest of errors that are not handled by the above meters
|
||||||
|
serveOtherError = metrics.NewRegisteredMeter("p2p/serves/error/other", nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
// markDialError matches errors that occur while setting up a dial connection to the
|
// markDialError matches errors that occur while setting up a dial connection to the
|
||||||
|
|
@ -99,6 +111,36 @@ func markDialError(err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// markServeError matches errors that occur while serving an inbound connection
|
||||||
|
// to the corresponding meter.
|
||||||
|
func markServeError(err error) {
|
||||||
|
if !metrics.Enabled() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var reason DiscReason
|
||||||
|
var handshakeErr *protoHandshakeError
|
||||||
|
d := errors.As(err, &reason)
|
||||||
|
switch {
|
||||||
|
case d && reason == DiscTooManyPeers:
|
||||||
|
serveTooManyPeers.Mark(1)
|
||||||
|
case d && reason == DiscAlreadyConnected:
|
||||||
|
serveAlreadyConnected.Mark(1)
|
||||||
|
case d && reason == DiscSelf:
|
||||||
|
serveSelf.Mark(1)
|
||||||
|
case d && reason == DiscUselessPeer:
|
||||||
|
serveUselessPeer.Mark(1)
|
||||||
|
case d && reason == DiscUnexpectedIdentity:
|
||||||
|
serveUnexpectedIdentity.Mark(1)
|
||||||
|
case errors.As(err, &handshakeErr):
|
||||||
|
serveProtoHandshakeError.Mark(1)
|
||||||
|
case errors.Is(err, errEncHandshakeError):
|
||||||
|
serveEncHandshakeError.Mark(1)
|
||||||
|
default:
|
||||||
|
serveOtherError.Mark(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// meteredConn is a wrapper around a net.Conn that meters both the
|
// meteredConn is a wrapper around a net.Conn that meters both the
|
||||||
// inbound and outbound network traffic.
|
// inbound and outbound network traffic.
|
||||||
type meteredConn struct {
|
type meteredConn struct {
|
||||||
|
|
|
||||||
|
|
@ -864,6 +864,8 @@ func (srv *Server) SetupConn(fd net.Conn, flags connFlag, dialDest *enode.Node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !c.is(inboundConn) {
|
if !c.is(inboundConn) {
|
||||||
markDialError(err)
|
markDialError(err)
|
||||||
|
} else {
|
||||||
|
markServeError(err)
|
||||||
}
|
}
|
||||||
c.close(err)
|
c.close(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue