Skip to content

Commit

Permalink
feat(diagnostics): Add tokio-console support to zebrad (ZcashFoundati…
Browse files Browse the repository at this point in the history
…on#4519)

* Always activate tokio/tracing feature

And always build tests with all tokio features.

* Refactor tracing-subscriber init to simplify it

* Add the tokio-console feature and dependencies

* Add optional tokio-console support, and log the installed tracing layers at info level

Uses a tracing Registry for tokio-console, and a fmt::Subscriber otherwise.

* Add some TODOs based on tracing-subscriber features

* Fix up some spans

* Add a TODO for fixing a log filter bug in tokio-console mode
  • Loading branch information
teor2345 authored Jun 15, 2022
1 parent cc75c3f commit 83b4e6f
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Zebra cargo configuration

# Flags that apply to all Zebra crates and configurations
[target.'cfg(all())']
rustflags = [
# Zebra standard lints for Rust 1.58+
Expand Down
41 changes: 39 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tower-batch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ tracing-futures = "0.2.5"
color-eyre = "0.6.1"
ed25519-zebra = "3.0.0"
rand = { version = "0.8.5", package = "rand" }
tokio = { version = "1.19.2", features = ["full"] }

tokio = { version = "1.19.2", features = ["full", "tracing", "test-util"] }
tokio-test = "0.4.2"
tower-fallback = { path = "../tower-fallback/" }
tower-test = "0.4.0"
tracing = "0.1.31"

zebra-test = { path = "../zebra-test/" }
3 changes: 2 additions & 1 deletion tower-fallback/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ futures-core = "0.3.21"
tracing = "0.1.31"

[dev-dependencies]
tokio = { version = "1.19.2", features = ["full", "tracing", "test-util"] }

zebra-test = { path = "../zebra-test/" }
tokio = { version = "1.19.2", features = ["full"] }
6 changes: 4 additions & 2 deletions zebra-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ proptest-derive = { version = "0.3.0", optional = true }

rand = { version = "0.8.5", optional = true, package = "rand" }
rand_chacha = { version = "0.3.1", optional = true }
tokio = { version = "1.19.2", optional = true }

tokio = { version = "1.19.2", features = ["tracing"], optional = true }

# ZF deps
ed25519-zebra = "3.0.0"
Expand All @@ -79,10 +80,11 @@ tracing = "0.1.31"

proptest = "0.10.1"
proptest-derive = "0.3.0"

rand = { version = "0.8.5", package = "rand" }
rand_chacha = "0.3.1"

tokio = "1.19.2"
tokio = { version = "1.19.2", features = ["full", "tracing", "test-util"] }

zebra-test = { path = "../zebra-test/" }

Expand Down
3 changes: 2 additions & 1 deletion zebra-consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ proptest = "0.10.1"
proptest-derive = "0.3.0"
rand07 = { package = "rand", version = "0.7" }
spandoc = "0.2.2"
tokio = { version = "1.19.2", features = ["full"] }

tokio = { version = "1.19.2", features = ["full", "tracing", "test-util"] }
tracing-error = "0.2.0"
tracing-subscriber = "0.3.11"

Expand Down
2 changes: 1 addition & 1 deletion zebra-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ proptest = "0.10.1"
proptest-derive = "0.3.0"

static_assertions = "1.1.0"
tokio = { version = "1.19.2", features = ["test-util"] }
tokio = { version = "1.19.2", features = ["full", "tracing", "test-util"] }
toml = "0.5.9"

zebra-chain = { path = "../zebra-chain", features = ["proptest-impl"] }
Expand Down
33 changes: 19 additions & 14 deletions zebra-network/src/peer_set/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use tokio_stream::wrappers::IntervalStream;
use tower::{
buffer::Buffer, discover::Change, layer::Layer, util::BoxService, Service, ServiceExt,
};
use tracing::Span;
use tracing_futures::Instrument;

use zebra_chain::{chain_tip::ChainTip, parameters::Network};
Expand Down Expand Up @@ -179,7 +178,7 @@ where
listen_handshaker,
peerset_tx.clone(),
);
let listen_guard = tokio::spawn(listen_fut.instrument(Span::current()));
let listen_guard = tokio::spawn(listen_fut.in_current_span());

// 2. Initial peers, specified in the config.
let initial_peers_fut = add_initial_peers(
Expand All @@ -188,7 +187,7 @@ where
peerset_tx.clone(),
address_book_updater,
);
let initial_peers_join = tokio::spawn(initial_peers_fut.instrument(Span::current()));
let initial_peers_join = tokio::spawn(initial_peers_fut.in_current_span());

// 3. Outgoing peers we connect to in response to load.
let mut candidates = CandidateSet::new(address_book.clone(), peer_set.clone());
Expand Down Expand Up @@ -228,7 +227,7 @@ where
peerset_tx,
active_outbound_connections,
);
let crawl_guard = tokio::spawn(crawl_fut.instrument(Span::current()));
let crawl_guard = tokio::spawn(crawl_fut.in_current_span());

handle_tx
.send(vec![listen_guard, crawl_guard, address_book_updater_guard])
Expand Down Expand Up @@ -646,15 +645,20 @@ enum CrawlerAction {
///
/// Uses `active_outbound_connections` to limit the number of active outbound connections
/// across both the initial peers and crawler. The limit is based on `config`.
#[instrument(skip(
config,
demand_tx,
demand_rx,
candidates,
outbound_connector,
peerset_tx,
active_outbound_connections,
))]
#[instrument(
skip(
config,
demand_tx,
demand_rx,
candidates,
outbound_connector,
peerset_tx,
active_outbound_connections,
),
fields(
new_peer_interval = ?config.crawl_new_peer_interval,
)
)]
async fn crawl_and_dial<C, S>(
config: Config,
mut demand_tx: futures::channel::mpsc::Sender<MorePeers>,
Expand Down Expand Up @@ -761,7 +765,8 @@ where
panic!("panic during handshaking with {:?}: {:?} ", candidate, e);
}
})
.instrument(Span::current());
.in_current_span();

handshakes.push(Box::pin(hs_join));
}
DemandCrawl => {
Expand Down
3 changes: 2 additions & 1 deletion zebra-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ proptest = "0.10.1"
proptest-derive = "0.3.0"
serde_json = "1.0.81"
thiserror = "1.0.31"
tokio = { version = "1.19.2", features = ["full", "test-util"] }

tokio = { version = "1.19.2", features = ["full", "tracing", "test-util"] }

zebra-chain = { path = "../zebra-chain", features = ["proptest-impl"] }
zebra-state = { path = "../zebra-state", features = ["proptest-impl"] }
Expand Down
5 changes: 3 additions & 2 deletions zebra-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ rocksdb = { version = "0.18.0", default_features = false, features = ["lz4"] }
serde = { version = "1.0.137", features = ["serde_derive"] }
tempfile = "3.3.0"
thiserror = "1.0.31"
tokio = { version = "1.19.2", features = ["sync"] }

tokio = { version = "1.19.2", features = ["sync", "tracing"] }
tower = { version = "0.4.12", features = ["buffer", "util"] }
tracing = "0.1.31"

Expand All @@ -48,7 +49,7 @@ proptest-derive = "0.3.0"
halo2 = { package = "halo2_proofs", version = "0.1.0" }
jubjub = "0.9.0"

tokio = { version = "1.19.2", features = ["full"] }
tokio = { version = "1.19.2", features = ["full", "tracing", "test-util"] }

zebra-chain = { path = "../zebra-chain", features = ["proptest-impl"] }
zebra-test = { path = "../zebra-test/" }
2 changes: 1 addition & 1 deletion zebra-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ once_cell = "1.12.0"
rand = { version = "0.8.5", package = "rand" }
regex = "1.5.6"

tokio = { version = "1.19.2", features = ["full"] }
tokio = { version = "1.19.2", features = ["full", "tracing", "test-util"] }
tower = { version = "0.4.12", features = ["util"] }
futures = "0.3.21"

Expand Down
19 changes: 18 additions & 1 deletion zebrad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ proptest-impl = ["proptest", "proptest-derive", "zebra-chain/proptest-impl", "ze
# The gRPC tests also need an installed lightwalletd binary
lightwalletd-grpc-tests = ["tonic-build"]

# tokio-console support
#
# To activate this feature, run:
# ```sh
# RUSTFLAGS="--cfg tokio_unstable" cargo build --no-default-features --features="tokio-console" --bin zebrad
# ```
#
# The console-subscriber is incompatible with the tracing/max_level_* features.
#
# For more details, see:
# https://github.com/tokio-rs/console/blob/main/console-subscriber/README.md#enabling-tokio-instrumentation
tokio-console = ["console-subscriber"]

# TODO: replace with environmental variables that skip the tests when not set (part of #2995)
test_sync_to_mandatory_checkpoint_mainnet = []
test_sync_to_mandatory_checkpoint_testnet = []
Expand Down Expand Up @@ -105,6 +118,9 @@ log = "0.4.17"
proptest = { version = "0.10.1", optional = true }
proptest-derive = { version = "0.3.0", optional = true }

# test feature tokio-console
console-subscriber = { version = "0.1.6", optional = true }

[build-dependencies]
vergen = { version = "7.2.1", default-features = false, features = ["cargo", "git"] }

Expand All @@ -121,7 +137,8 @@ semver = "1.0.10"
# zebra-rpc needs the preserve_order feature, it also makes test results more stable
serde_json = { version = "1.0.81", features = ["preserve_order"] }
tempfile = "3.3.0"
tokio = { version = "1.19.2", features = ["full", "test-util"] }

tokio = { version = "1.19.2", features = ["full", "tracing", "test-util"] }
tokio-stream = "0.1.9"

# test feature lightwalletd-grpc-tests
Expand Down
Loading

0 comments on commit 83b4e6f

Please sign in to comment.