Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(logs): remove duplicate msg key #1180

Merged
merged 3 commits into from
Aug 14, 2024

Conversation

AlejandroCabeza
Copy link
Collaborator

Chronicles uses msg for the string that describes the log, so this PR removes the duplicate msg usage.

closes: #1176

@AlejandroCabeza AlejandroCabeza changed the title fix(logs): remove duplicate msg key chore(logs): remove duplicate msg key Aug 13, 2024
@@ -106,7 +106,7 @@ method rpcHandler*(f: FloodSub, peer: PubSubPeer, data: seq[byte]) {.async.} =
debug "failed to decode msg from peer", peer, err = error
raise newException(CatchableError, "Peer msg couldn't be decoded")

trace "decoded msg from peer", peer, msg = rpcMsg.shortLog
trace "decoded msg from peer", peer, payload = rpcMsg.shortLog
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msgShortLog?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of the same reasoning, payload is a widely accepted word for this situations.

Copy link
Collaborator

@diegomrsantos diegomrsantos Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not logging the whole content

func shortLog*(item: openArray[byte]): string =
if item.len <= ShortDumpMax:
result = item.toHex()
else:
const
split = ShortDumpMax div 2
dumpLen = (ShortDumpMax * 2) + 3
result = newStringOfCap(dumpLen)
result &= item.toOpenArray(0, split - 1).toHex()
result &= "..."
result &= item.toOpenArray(item.len - split, item.high).toHex()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that be an issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shortLog creates a shortened representation of the data, it's not the payload. What about summary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shortLog is actually a bit of an abused name, as it vastly depends on the object being shortlogged: Some are actual short representations, some others are obfuscated representations, and others are the full object representations.

What I mean is: There's not a unique key that perfectly handles all cases; unless we go for a very generic context or the likes, which doesn't really provide meaning. Ideally it should be handled on a case by case basis, but I think that's a different task altogether.

Personally, I'd stick to payload as it's already there and we can get it merged already, and create a chore to keep track of this naming issue and spend on time whenever we feel appropriate. That is, unless you strongly oppose it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, could you please create an issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: #1181

@@ -219,7 +219,7 @@ method publish*(f: FloodSub, topic: string, data: seq[byte]): Future[int] {.asyn
trace "Error generating message id, skipping publish", error = error
return 0

trace "Created new message", msg = shortLog(msg), peers = peers.len, topic, msgId
trace "Created new message", payload = shortLog(msg), peers = peers.len, topic, msgId
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msgShortLog?

libp2p/connmanager.nim Outdated Show resolved Hide resolved
@AlejandroCabeza AlejandroCabeza merged commit 48846d6 into master Aug 14, 2024
14 checks passed
@AlejandroCabeza AlejandroCabeza deleted the fix/remove-duplicate-logs-keys branch August 14, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

Stop creating duplicate msg keys in logs
3 participants