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
6 changed files with 21 additions and 18 deletions

View File

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

View File

@@ -1,2 +1 @@
package beacon package beacon

View File

@@ -1,2 +1 @@
package beacon package beacon

View File

@@ -46,7 +46,7 @@ func (s *Service) goodbyeRPCHandler(_ context.Context, msg interface{}, stream l
} }
s.rateLimiter.add(stream, 1) s.rateLimiter.add(stream, 1)
log := log.WithField("Reason", goodbyeMessage(*m)) 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)) s.cfg.p2p.Peers().SetNextValidTime(stream.Conn().RemotePeer(), goodByeBackoff(*m))
// closes all streams with the peer // closes all streams with the peer
return s.cfg.p2p.Disconnect(stream.Conn().RemotePeer()) 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{ log.WithFields(logrus.Fields{
"error": err, "error": err,
"peer": id, "peer": id,
}).Debug("Could not send goodbye message to peer") }).Trace("Could not send goodbye message to peer")
} }
return s.cfg.p2p.Disconnect(id) return s.cfg.p2p.Disconnect(id)
} }
@@ -107,7 +107,7 @@ func (s *Service) sendGoodByeMessage(ctx context.Context, code p2ptypes.RPCGoodb
defer closeStream(stream, log) defer closeStream(stream, log)
log := log.WithField("Reason", goodbyeMessage(code)) 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 // 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 // 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 return
} }
if err := c.Encoding().DecodeWithMaxLength(stream, msg); err != nil { if err := c.Encoding().DecodeWithMaxLength(stream, msg); err != nil {
// Debug logs for goodbye/status errors // Trace logs for goodbye errors
if strings.Contains(topic, p2p.RPCGoodByeTopicV1) || strings.Contains(topic, p2p.RPCStatusTopicV1) { logStreamErrors(err, topic)
log.WithError(err).Debug("Could not decode goodbye stream message")
return
}
log.WithError(err).Debug("Could not decode stream message")
return return
} }
if err := handle(context.Background(), msg, stream); err != nil { if err := handle(context.Background(), msg, stream); err != nil {
@@ -89,7 +85,7 @@ func (c *client) registerRPCHandler(baseTopic string, handle rpcHandler) {
return return
} }
if err := c.Encoding().DecodeWithMaxLength(stream, msg); err != nil { if err := c.Encoding().DecodeWithMaxLength(stream, msg); err != nil {
log.WithError(err).Debug("Could not decode stream message") logStreamErrors(err, topic)
return return
} }
if err := handle(context.Background(), nTyp.Elem().Interface(), stream); err != nil { 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 // +build ignore
package ignore package ignore