Set Verbosity of Goodbye Logs to Trace (#13077)

This commit is contained in:
Nishant Das 2023-10-19 11:49:34 +08:00 committed by GitHub
parent f592bf7f07
commit bc125a95ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 18 deletions

View File

@ -8,10 +8,10 @@ import (
)
func TestBeaconEndpointFactory_AllPathsRegistered(t *testing.T) {
f := &apimiddleware.BeaconEndpointFactory{}
f := &apimiddleware.BeaconEndpointFactory{}
for _, p := range f.Paths() {
_, err := f.Create(p)
require.NoError(t, err, "failed to register %s", p)
}
for _, p := range f.Paths() {
_, err := f.Create(p)
require.NoError(t, err, "failed to register %s", p)
}
}

View File

@ -1,2 +1 @@
package beacon

View File

@ -1,2 +1 @@
package beacon

View File

@ -46,7 +46,7 @@ func (s *Service) goodbyeRPCHandler(_ context.Context, msg interface{}, stream l
}
s.rateLimiter.add(stream, 1)
log := log.WithField("Reason", goodbyeMessage(*m))
log.WithField("peer", stream.Conn().RemotePeer()).Debug("Peer has sent a goodbye message")
log.WithField("peer", stream.Conn().RemotePeer()).Trace("Peer has sent a goodbye message")
s.cfg.p2p.Peers().SetNextValidTime(stream.Conn().RemotePeer(), goodByeBackoff(*m))
// closes all streams with the peer
return s.cfg.p2p.Disconnect(stream.Conn().RemotePeer())
@ -87,7 +87,7 @@ func (s *Service) sendGoodByeAndDisconnect(ctx context.Context, code p2ptypes.RP
log.WithFields(logrus.Fields{
"error": err,
"peer": id,
}).Debug("Could not send goodbye message to peer")
}).Trace("Could not send goodbye message to peer")
}
return s.cfg.p2p.Disconnect(id)
}
@ -107,7 +107,7 @@ func (s *Service) sendGoodByeMessage(ctx context.Context, code p2ptypes.RPCGoodb
defer closeStream(stream, log)
log := log.WithField("Reason", goodbyeMessage(code))
log.WithField("peer", stream.Conn().RemotePeer()).Debug("Sending Goodbye message to peer")
log.WithField("peer", stream.Conn().RemotePeer()).Trace("Sending Goodbye message to peer")
// Wait up to the response timeout for the peer to receive the goodbye
// and close the stream (or disconnect). We usually don't bother waiting

View File

@ -68,12 +68,8 @@ func (c *client) registerRPCHandler(baseTopic string, handle rpcHandler) {
return
}
if err := c.Encoding().DecodeWithMaxLength(stream, msg); err != nil {
// Debug logs for goodbye/status errors
if strings.Contains(topic, p2p.RPCGoodByeTopicV1) || strings.Contains(topic, p2p.RPCStatusTopicV1) {
log.WithError(err).Debug("Could not decode goodbye stream message")
return
}
log.WithError(err).Debug("Could not decode stream message")
// Trace logs for goodbye errors
logStreamErrors(err, topic)
return
}
if err := handle(context.Background(), msg, stream); err != nil {
@ -89,7 +85,7 @@ func (c *client) registerRPCHandler(baseTopic string, handle rpcHandler) {
return
}
if err := c.Encoding().DecodeWithMaxLength(stream, msg); err != nil {
log.WithError(err).Debug("Could not decode stream message")
logStreamErrors(err, topic)
return
}
if err := handle(context.Background(), nTyp.Elem().Interface(), stream); err != nil {
@ -100,3 +96,11 @@ func (c *client) registerRPCHandler(baseTopic string, handle rpcHandler) {
}
})
}
func logStreamErrors(err error, topic string) {
if strings.Contains(topic, p2p.RPCGoodByeTopicV1) {
log.WithError(err).Trace("Could not decode goodbye stream message")
return
}
log.WithError(err).Debug("Could not decode stream message")
}

View File

@ -1,3 +1,4 @@
//go:build ignore
// +build ignore
package ignore
package ignore