-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Network logging bugfixes and improvements #5591
Conversation
5d3e8a4
to
f3273fb
Compare
Codecov Report
@@ Coverage Diff @@
## master #5591 +/- ##
==========================================
- Coverage 62.25% 62.21% -0.04%
==========================================
Files 347 347
Lines 29229 29280 +51
Branches 3306 3309 +3
==========================================
+ Hits 18197 18218 +21
- Misses 9844 9873 +29
- Partials 1188 1189 +1 |
f3273fb
to
6c3f537
Compare
6c3f537
to
7fa81da
Compare
Rebased + added changelog update |
7fa81da
to
d6d377f
Compare
Squashed some commits |
Add helper functions to log the string values for incoming capability packets to make debugging network problems easier. For reference, Session::readPacket dispatches incoming capability packets to the appropriate capability instance, or if they're p2p capability packets (e.g. ping/pong) processes them itself. Also remove redundant "Packet" from PacketType strings and rename PacketType -> P2pPacketType.
Log "pong" instead of "ping" when sending pong in Session. Log "unsolicited neighbours packet" error to discov channel rather than net channel (since all other discovery messages are logged to the discov channel) Make other miscellaneous log tweaks e.g. log node ID + endpoint in certain messages.
p2pcap messages are messages logged during preparation of outgoing p2pcap packets or processing of incoming p2pcap packets (when we realize that we are processing p2pcap packets)
d6d377f
to
e8aa9ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to add p2pcap
to the list of channels in aleth/main.cpp
{ | ||
m_lastReceived = chrono::steady_clock::now(); | ||
clog(VerbosityTrace, "net") << "-> " << _packetType << " " << _r; | ||
clog(VerbosityTrace, "net") << "Received " << capabilityPacketTypeToString(_packetType) << "(" | ||
<< _packetType << ") from " << m_info.id << "@" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about logging everywhere in Session class << m_info.id << "@" << m_socket->remoteEndpoint();
Here LOG_SCOPED_CONTEXT
is supposed to add a prefix of id+clientVersion for each log message inside network handlers. Isn't at least m_info.id
duplicated in logs this way?
I suspect that sometimes IDs could be different, like when BlockChainSync
code is called inside the handler of the message from one peer, and this code sends a message to another peer.
In this case, maybe it's better to remove LOG_SCOPED_CONTEXT
stuff now? Though then clientVersion of the peers won't as visible in logs as now, it seems useful, too... What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gumb0 : I like having the client information in the log messages, though I don't have a concrete example of when it has helped me debug something yet. I think that prefixing each log message with the node id + client information makes the log messages a little counter-intuitive, for example, the following message could be logged when we receive a Pong p2p capability message from a node but the message reads as if 865a6325 received the pong:
p2p p2pcap 865a6325…|Parity-Ethereum/v2.2.9-stable-5d5b372-20190203/x86_64-linux-gnu/rustc1.31.1 Receiving Pong
An option is to remove the LOG_SCOPED_CONTEXT and to instead log the client information at the end of each message e.g.
TRACE 05-07 21:03:32 p2p p2pcap Pong to ##865a6325…@52.176.100.77:30303 (Parity-Ethereum/v2.2.9-stable-5d5b372-20190203/x86_64-linux-gnu/rustc1.31.1)
I think this is more readable, though it makes the log statements themselves more cumbersome (as you called out in my RLPXHandshake logging changes). Perhaps we could also create a logging wrapper function such as:
inline void logMessage(char const* _message, char const* _channel, Verbosity _verbosity)
{
clog(_verbosity, _channel) << _message << " (" << m_info.clientVersion << "|" << m_info.id << "|" << m_socket->remoteEndpoint() << ")";
}
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I dislike repeating clientVersion many times, it bloats the log. If we output it once, say for Hello message, it should be easy enough to find it in the log for particular NodeID, when we need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing: if we repeat this << m_info.id << "@" << m_socket->remoteEndpoint();
in every message and these values are constant, can we create a logger for this, that adds them as a Context attribute, similar to what you did in RLPXHandshake
?
This and removing LOG_SCOPED_CONTEXT
can be done as a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The downside to removing LOG_SCOPED_CONTEXT
would be that we won't see this context for the messages coming from BlockChainSync
, not sure how useful it is. Maybe it's fine to remove, as all network handling happens sequentially in one thread and we should be able to find this context earlier in the log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I dislike repeating clientVersion many times, it bloats the log. If we output it once, say for Hello message, it should be easy enough to find it in the log for particular NodeID, when we need it.
Yes, but the Hello might be long in the past so it might not be accessible in the console log output anymore. This might be okay though since we also periodically log connected peers, though only at trace level:
Line 868 in 7ecf42b
LOG(m_detailsLogger) << "Peers: " << peerSessionInfos(); |
Host::m_detailLogger
is defined here:
Line 382 in 7ecf42b
Logger m_detailsLogger{createLogger(VerbosityTrace, "net")}; |
Maybe we should change the verbosity level of this log message to debug level so that it's more readily available for debugging purposes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e repeat this
<< m_info.id << "@" << m_socket->remoteEndpoint();
in every message and these values are constant, can we create a logger for this, that adds them as a Context attribute...
@gumb0 Is there a way to add the context to the end of a log message? I think including remote endpoint information at the beginning of a log message makes the log a little counter-intuitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to add the context to the end of a log message?
Not right now, but I think it's simple enough to add this. We could rename Context
attribute to Prefix
, then add another Suffix
one, and your logger would fill the Suffix
The changes will be need only here
Line 51 in 4e63cf2
BOOST_LOG_ATTRIBUTE_KEYWORD(context, "Context", std::string) |
and when we output it in formatter here
Lines 99 to 100 in 4e63cf2
if (boost::log::expressions::has_attr(context)(_rec)) | |
_strm << EthNavy << _rec[context] << EthReset " "; |
Include mention of new p2pcap log channel in changelog update and add new p2pcap log channel to Aleth help output.
Also move logging of incoming p2p capability packets out of switch statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if it's difficult to create a logger in Session
with Context that automatically adds NodeID and IP to the messages, I think it's still better to create a member variable logger(s) instead of using clog(VerbosityTrace, "p2pcap")
But this can be done in another PR.
@gumb0 : Agreed. For reference, clog(VerbosityTrace, "p2pcap") and LOG(m_logger) where m_logger is defined as Logger m_logger{createLogger(VerbosityTrace, "p2pcap")} are functionally equivalent? |
@halfalicious Not exactly, Actually now I think that the reason global loggers like |
Various network logging bugfixes and changes. Bugfixes:
Other logging changes: