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: changing digest and hash log format from bytes to hex #2363

Merged
merged 2 commits into from
Jan 25, 2024

Conversation

gabrielmer
Copy link
Contributor

Description

Changing digest and messageHash formats in log from bytes to hex for readability.

Issue

closes #2362

Copy link

github-actions bot commented Jan 19, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2363

Built from 91a9f46

@apentori
Copy link
Contributor

Seems to be working:

topics="waku archive" tid=1 file=archive.nim:114 pubsubTopic=/waku/2/default-waku/proto contentTopic=/waku/1/0x14a93183/rfc26 timestamp=1706096598912354244 digest=bd345e469d59641247f31aa8e112fc9c20e3bd14e8ec6a83174634acfcc0b708 messageHash=9ce1e2f7319bab9d63f59cc113f7c4a7e4ed6b7799e13047144f84469c52f2c2

@gabrielmer gabrielmer marked this pull request as ready for review January 24, 2024 12:01
Copy link
Contributor

@SionoiS SionoiS left a comment

Choose a reason for hiding this comment

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

LGTM!

Would it make sense to truncate the hex string as well?

@gabrielmer
Copy link
Contributor Author

LGTM!

Would it make sense to truncate the hex string as well?

I agree 100% that having the hash truncated is better/most comfortable. The issue is that this was requested so messages could be easily matched with Postgres errors such as

TRC 2024-01-19 10:59:25.410+00:00 failed to insert message                   topics="waku archive" tid=1 file=archive.nim:119 err="error in runStmt: error in dbConnQueryPrepared calling waitQueryToFinish: error in query: ERROR:  duplicate key value violates unique constraint \"messageindex\"\nDETAIL:  Key (messagehash)=(48d9ba522308a1d3725b5e1d08783e91f3395e7578849b448f53b78ecd1c1916) already exists.\n

and the hash isn't truncated here. So I think it's better to remain consistent and have the hash in the same format everywhere.

@apentori what do you think?

@apentori
Copy link
Contributor

apentori commented Jan 24, 2024

I agree 100% that having the hash truncated is better/most comfortable. The issue is that this was requested so messages could be easily matched with Postgres errors such as

Actually it is requested to help status Desktop and Mobile team identify message relialbility issues.

From what @chaitanyaprem told me,the Postgres error is like to the fleet architecture : 2 nodes trying to write on 1 db.
The second node will always fail due to the uniqueness constraint in the db.

I think it's better to have the full hash, specially for a Trace log that wont be usefull for a long time.

Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

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

I hope you agree, Doing hex conversion separately makes is more robust and tempt less side effect.

@@ -111,7 +111,7 @@ proc handleMessage*(w: WakuArchive,
msgReceivedTime = if msg.timestamp > 0: msg.timestamp
else: getNanosecondTime(getTime().toUnixFloat())

trace "handling message", pubsubTopic=pubsubTopic, contentTopic=msg.contentTopic, timestamp=msg.timestamp, digest=msgDigest, messageHash=msgHash
trace "handling message", pubsubTopic=pubsubTopic, contentTopic=msg.contentTopic, timestamp=msg.timestamp, digest=toHex(msgDigest.data), messageHash=toHex(msgHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

Upon latest ligging research, can we just move any conversion/calculation away from logging line?
Until we don't know what cause double call of any proc appears in the log arguments.
It is also involves memory allocation for the hex string, I would avoid that.

Copy link
Contributor

Choose a reason for hiding this comment

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

But this leads to another problem, if trace is disabled the hash would still be calculated which would reduce performance even in normal scenario.
Unless we can access and use the logging macro and put the hash calculation statement under it.

Copy link
Contributor Author

@gabrielmer gabrielmer Jan 25, 2024

Choose a reason for hiding this comment

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

I actually just discussed this point with Zoltán :))

In such cases we can check the log level and compute depending on it. I just added this fix without doing a specific check for log level, as I'm doing an extremely cheap computation - converting a constant size hash from bytes to hex.

For bigger computations, I guess the best thing is to compute it based on the log level. Although it seems not very elegant, not sure if there's a better way to abstract it.

Most important thing might be to figure out why computation happens twice when added as a log argument. The biggest problem here is the double memory allocation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah exactly. Agreed to enter an issue for chronicles lib. That can solve this issue in an optimal way.
Within this in mind, I would agree to keep it if you think so. I would have like to claim the attention on hidden costs of such calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good approach, let's check it directly with Chronicles. In the meantime, I'll leave the computation outside the log. It's a super simple/cheap one, so if we can avoid having them inside then better

@gabrielmer gabrielmer force-pushed the chore-changing-message-hash-log-format branch from 0f39909 to e80cd8b Compare January 25, 2024 14:03
Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

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

Thanks!

@gabrielmer gabrielmer merged commit 025c6ec into master Jan 25, 2024
9 of 10 checks passed
@gabrielmer gabrielmer deleted the chore-changing-message-hash-log-format branch January 25, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: restart loop of current master
5 participants