From 123f7951c025bbd1b1f3002d55c11305975ca85a Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Sat, 22 Jun 2024 18:48:50 -0300 Subject: [PATCH] feat: integrate tokio traces & debug console (#275) --- Cargo.lock | 93 +++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 2 + README.md | 22 ++++++++++ src/bin/dolos/common.rs | 27 +++++++++--- src/bin/dolos/main.rs | 4 ++ 5 files changed, 140 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 635d2db3..d2901f86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -547,6 +547,44 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "console-api" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a257c22cd7e487dd4a13d413beabc512c5052f0bc048db0da6a84c3d8a6142fd" +dependencies = [ + "futures-core", + "prost", + "prost-types", + "tonic", + "tracing-core", +] + +[[package]] +name = "console-subscriber" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c4cc54bae66f7d9188996404abdf7fdfa23034ef8e43478c8810828abad758" +dependencies = [ + "console-api", + "crossbeam-channel", + "crossbeam-utils", + "futures-task", + "hdrhistogram", + "humantime", + "prost", + "prost-types", + "serde", + "serde_json", + "thread_local", + "tokio", + "tokio-stream", + "tonic", + "tracing", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -849,6 +887,7 @@ dependencies = [ "clap", "comfy-table", "config", + "console-subscriber", "futures-core", "futures-util", "gasket", @@ -1308,6 +1347,19 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hdrhistogram" +version = "7.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" +dependencies = [ + "base64 0.21.7", + "byteorder", + "flate2", + "nom", + "num-traits", +] + [[package]] name = "heck" version = "0.4.1" @@ -1406,6 +1458,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.28" @@ -1721,6 +1779,15 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "matchit" version = "0.7.3" @@ -2759,8 +2826,17 @@ checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.6", + "regex-syntax 0.8.3", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -2771,9 +2847,15 @@ checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.3", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.3" @@ -3502,6 +3584,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", + "tracing", "windows-sys 0.48.0", ] @@ -3780,10 +3863,14 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ + "matchers", "nu-ansi-term", + "once_cell", + "regex", "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", ] diff --git a/Cargo.toml b/Cargo.toml index d54649ec..e0726fb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,7 @@ trait-variant = "0.1.2" comfy-table = { version = "7.1.1", optional = true } inquire = { version = "0.7.5", optional = true } toml = { version = "0.8.13", optional = true } +console-subscriber = { version = "0.3.0", optional = true } [dev-dependencies] tempfile = "3.3.0" @@ -61,6 +62,7 @@ tempfile = "3.3.0" [features] mithril = ["mithril-client"] utils = ["comfy-table", "inquire", "toml"] +debug = ["console-subscriber", "tokio/tracing"] default = ["mithril", "utils"] # The profile that 'cargo dist' will build with diff --git a/README.md b/README.md index b43e6067..4cd6e4bd 100644 --- a/README.md +++ b/README.md @@ -67,3 +67,25 @@ sudo sh ./get-dolos.sh ``` After installation, follow this [configuration guide](book/src/configuration). Guide on running dolos [here](book/src/running). + + +# Debug + +## Running Tokio Console + +Make sure you have enable tokio traces in dolos.toml: +```toml +[logging] +max_level=trace +include_tokio=true +``` + +Start Dolos using: +``` +RUSTFLAGS="--cfg tokio_unstable" cargo --features debug run +``` + +Then start tokio console: +``` +tokio-console +``` \ No newline at end of file diff --git a/src/bin/dolos/common.rs b/src/bin/dolos/common.rs index 7b1d3a5f..9700fddf 100644 --- a/src/bin/dolos/common.rs +++ b/src/bin/dolos/common.rs @@ -54,6 +54,12 @@ pub fn setup_tracing(config: &LoggingConfig) -> miette::Result<()> { .with_target("dolos", level) .with_target("gasket", level); + if config.include_tokio { + filter = filter + .with_target("tokio", level) + .with_target("runtime", level); + } + if config.include_pallas { filter = filter.with_target("pallas", level); } @@ -62,11 +68,22 @@ pub fn setup_tracing(config: &LoggingConfig) -> miette::Result<()> { filter = filter.with_target("tonic", level); } - tracing_subscriber::FmtSubscriber::builder() - .with_max_level(level) - .finish() - .with(filter) - .init(); + #[cfg(not(feature = "debug"))] + { + tracing_subscriber::registry() + .with(tracing_subscriber::fmt::layer()) + .with(filter) + .init(); + } + + #[cfg(feature = "debug")] + { + tracing_subscriber::registry() + .with(tracing_subscriber::fmt::layer()) + .with(console_subscriber::spawn()) + .with(filter) + .init(); + } Ok(()) } diff --git a/src/bin/dolos/main.rs b/src/bin/dolos/main.rs index fed6a38b..c7b8690e 100644 --- a/src/bin/dolos/main.rs +++ b/src/bin/dolos/main.rs @@ -109,6 +109,9 @@ pub struct LoggingConfig { #[serde_as(as = "DisplayFromStr")] max_level: tracing::Level, + #[serde(default)] + include_tokio: bool, + #[serde(default)] include_pallas: bool, @@ -120,6 +123,7 @@ impl Default for LoggingConfig { fn default() -> Self { Self { max_level: tracing::Level::INFO, + include_tokio: Default::default(), include_pallas: Default::default(), include_grpc: Default::default(), }