tikv / raft-rs

Raft distributed consensus algorithm implemented in Rust.
Apache License 2.0
2.86k stars 391 forks source link

Suggestion: Add `CustomDeserializer` trait for making debugging `raft-rs` logs much easier #522

Open jopemachine opened 11 months ago

jopemachine commented 11 months ago

As I mentioned in the raft-rs Slack channel before, I think it would be very useful if users could see their byte slice information like Entry's context, data.

I think it could be possible by exposing the CustomDeserializer trait in raft-rs.

In this PR, I implement this thinking roughly, and I can see they are working as expected through ratify which uses raft-rs under the hood.

You can see the logged Message includes context, data as deserialized strings, not as byte slices in the below screenshot.

1

I'm just wondering if there are some raft-rs maintainers who agree with this idea and if not, why not.

Although this PR is currently just some sample codes to show ideas and working code, if there's a chance this PR will be merged, I'm willing to work on making improvements.

(Otherwise, I think I have to keep the cloned separate repository for raftify which would be troublesome for me...)

BusyJay commented 11 months ago

Can you describe more details on what's the behavior without this patch and why it's bad?

jopemachine commented 11 months ago

Can you describe more details on what's the behavior without this patch and why it's bad?

I think nobody wants to see byte slice in their raft-rs logs like the below screenshot.

스크린샷 2023-08-17 오후 11 23 45

Instead, I think users should want to be able to pass their own deserialization method like the below screenshot.

스크린샷 2023-08-17 오후 11 25 51

And I think this PR could accomplish this by exposing the CustomDeserializer trait.

If users don't implement that trait, the byte slices will still be printed as byte slices. (same behavior)

But if users want to see deserialized strings in their raft-rs logs, they can make it through CustomDeserializer of this PR.

If you think more explanation is needed, please feel free to comment here or you can send slack direct message to me directly.

jopemachine commented 11 months ago

So, the behavior without the patch is showing raw byte slice in logs, and I think it could be very bad for debugging and figuring out what's happening inside...