mini-redis icon indicating copy to clipboard operation
mini-redis copied to clipboard

Add additional `tracing` instrumentation.

Open jswrenn opened this issue 2 years ago • 5 comments

This commit lays the ground-work for making mini-redis a better example of an instrumented tokio application. While it does not go so far to turn mini-redis into a fully-featured guide for using tracing, it ensures that people who use mini-redis as a basis for experimenting with different subscribers get a more complete experience out-of-the-box.

E.g., with tracing-tree a tracing-tree subscriber and level=Debug:

 INFO mini_redis::server accepting inbound connections
┐mini_redis::db::purge_expired_tasks 
├─┐mini_redis::db::Shared::purge_expired_keys 
├─┘
┐mini_redis::server::Handler::run peer_addr=127.0.0.1:56574
├─┐mini_redis::server::Handler::process_frame 
│ ├─0ms DEBUG mini_redis::server cmd=Unknown(Unknown { command_name: "config" })
│ ├─0ms DEBUG mini_redis::cmd::unknown response=Error("ERR unknown command 'config'")
├─┘
├─┐mini_redis::server::Handler::process_frame 
│ ├─0ms DEBUG mini_redis::server cmd=Unknown(Unknown { command_name: "config" })
│ ├─0ms DEBUG mini_redis::cmd::unknown response=Error("ERR unknown command 'config'")
├─┘
├─┐mini_redis::server::Handler::process_frame 
│ ├─0ms  WARN mini_redis::connection connection closed abruptly by peer
├─┘
┘
┐mini_redis::server::Handler::run peer_addr=127.0.0.1:56576
├─┐mini_redis::server::Handler::process_frame 
│ ├─0ms DEBUG mini_redis::server cmd=Set(Set { key: "key:000000000027", value: b"VXK", expire: None })
├─┘
├─┐mini_redis::server::Handler::process_frame 
│ ├─0ms DEBUG mini_redis::server cmd=Set(Set { key: "key:000000000001", value: b"VXK", expire: None })
├─┘
├─┐mini_redis::server::Handler::process_frame 
├─┘
┘

This PR also reduces ConnectionReset 'errors' to warnings, as they do not reflect errors in mini-redis, but rather client misbehavior. (And you get them frequently when using redis-benchmark.)

jswrenn avatar Apr 29 '22 22:04 jswrenn

Looks pretty good to me

bryangarza avatar May 03 '22 15:05 bryangarza

@hawkw I've added a few such comments; e.g.:

  • https://github.com/tokio-rs/mini-redis/blob/49ef356960f4b3cfcf7af2ed4c06028f455d2de9/src/cmd/mod.rs#L50-L54
  • https://github.com/tokio-rs/mini-redis/blob/49ef356960f4b3cfcf7af2ed4c06028f455d2de9/src/cmd/mod.rs#L109-L113
  • https://github.com/tokio-rs/mini-redis/blob/49ef356960f4b3cfcf7af2ed4c06028f455d2de9/src/server.rs#L378-L393

jswrenn avatar May 06 '22 20:05 jswrenn

So... LGTM? @jswrenn

bryangarza avatar Jun 08 '22 23:06 bryangarza

@hawkw I've applied most of the suggestions (will need to think more about the last two), and rebased (to fix a merge conflict).

jswrenn avatar Jul 28 '22 18:07 jswrenn

too bad this never got merged, it would have been useful

bryangarza avatar Feb 14 '23 00:02 bryangarza