DEVELOPMENT ENVIRONMENT

~liljamo/emerwen

65605bad860c83e58dd60e480a067c4c3d88ed5a — Jonni Liljamo 12 days ago 150282d
feat(worker): trace feature for tokio-console
6 files changed, 165 insertions(+), 21 deletions(-)

M .cargo/config.toml
M Cargo.lock
M emerwen-worker/Cargo.toml
M emerwen-worker/src/main.rs
M flake.nix
M justfile
M .cargo/config.toml => .cargo/config.toml +1 -1
@@ 1,3 1,3 @@
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
rustflags = ["--cfg", "tokio_unstable", "-C", "link-arg=-fuse-ld=mold"]

M Cargo.lock => Cargo.lock +127 -2
@@ 190,6 190,12 @@ dependencies = [

[[package]]
name = "base64"
version = "0.21.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"

[[package]]
name = "base64"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"


@@ 280,6 286,45 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"

[[package]]
name = "console-api"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8030735ecb0d128428b64cd379809817e620a40e5001c54465b99ec5feec2857"
dependencies = [
 "futures-core",
 "prost",
 "prost-types",
 "tonic",
 "tracing-core",
]

[[package]]
name = "console-subscriber"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6539aa9c6a4cd31f4b1c040f860a1eac9aa80e7df6b05d506a6e7179936d6a01"
dependencies = [
 "console-api",
 "crossbeam-channel",
 "crossbeam-utils",
 "futures-task",
 "hdrhistogram",
 "humantime",
 "hyper-util",
 "prost",
 "prost-types",
 "serde",
 "serde_json",
 "thread_local",
 "tokio",
 "tokio-stream",
 "tonic",
 "tracing",
 "tracing-core",
 "tracing-subscriber",
]

[[package]]
name = "core-foundation"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 296,6 341,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"

[[package]]
name = "crc32fast"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
dependencies = [
 "cfg-if",
]

[[package]]
name = "crossbeam-channel"
version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2"
dependencies = [
 "crossbeam-utils",
]

[[package]]
name = "crossbeam-utils"
version = "0.8.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"

[[package]]
name = "displaydoc"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 338,6 407,7 @@ name = "emerwen-worker"
version = "0.1.0"
dependencies = [
 "clap",
 "console-subscriber",
 "emerwen-protocol",
 "reqwest",
 "surge-ping",


@@ 385,6 455,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"

[[package]]
name = "flate2"
version = "1.0.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0"
dependencies = [
 "crc32fast",
 "miniz_oxide",
]

[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 508,6 588,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3"

[[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.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 572,6 665,12 @@ 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 = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 920,6 1019,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"

[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"

[[package]]
name = "miniz_oxide"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 970,6 1075,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43794a0ace135be66a25d3ae77d41b91615fb68ae937f904090203e81f755b65"

[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
 "memchr",
 "minimal-lexical",
]

[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 980,6 1095,15 @@ dependencies = [
]

[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
 "autocfg",
]

[[package]]
name = "object"
version = "0.36.5"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 1342,7 1466,7 @@ version = "0.12.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f"
dependencies = [
 "base64",
 "base64 0.22.1",
 "bytes",
 "encoding_rs",
 "futures-core",


@@ 1761,6 1885,7 @@ dependencies = [
 "signal-hook-registry",
 "socket2",
 "tokio-macros",
 "tracing",
 "windows-sys 0.52.0",
]



@@ 1829,7 1954,7 @@ dependencies = [
 "async-stream",
 "async-trait",
 "axum",
 "base64",
 "base64 0.22.1",
 "bytes",
 "h2",
 "http",

M emerwen-worker/Cargo.toml => emerwen-worker/Cargo.toml +4 -0
@@ 12,9 12,13 @@ repository.workspace = true
emerwen-protocol = { path = "../emerwen-protocol" }

clap = { version = "4", features = ["derive"] }
console-subscriber = { version = "0.4", optional = true }
reqwest = "0.12"
surge-ping = "0.8.1"
tokio = { version = "1", features = ["full"] }
tonic = "0.12"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[features]
trace = ["tokio/tracing", "dep:console-subscriber"]

M emerwen-worker/src/main.rs => emerwen-worker/src/main.rs +29 -18
@@ 8,7 8,7 @@
use clap::Parser;
use emerwen_protocol::emerwen_protocol_client::EmerwenProtocolClient;
use tonic::{metadata::MetadataValue, service::Interceptor, transport::Channel};
use tracing::{debug, info, level_filters::LevelFilter};
use tracing::{debug, info};
use tracing_subscriber::{prelude::*, EnvFilter};

mod monitor;


@@ 33,23 33,34 @@ struct Args {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let args = Args::parse();

    tracing_subscriber::registry()
        .with(
            tracing_subscriber::fmt::layer()
                .with_file(args.debug)
                .with_line_number(args.debug)
                .with_level(true),
        )
        .with(
            EnvFilter::builder()
                .with_default_directive(if args.debug {
                    LevelFilter::DEBUG.into()
                } else {
                    LevelFilter::INFO.into()
                })
                .from_env_lossy(),
        )
        .init();
    #[cfg(feature = "trace")]
    {
        let console_layer = console_subscriber::spawn();
        tracing_subscriber::registry()
            .with(console_layer)
            .with(
                tracing_subscriber::fmt::layer()
                    .with_file(true)
                    .with_line_number(true)
                    .with_level(true),
            )
            .with(EnvFilter::from_default_env().add_directive("trace".parse()?))
            .init();
    }
    #[cfg(not(feature = "trace"))]
    {
        let mut filter = EnvFilter::from_default_env();
        if args.debug {
            filter = filter.add_directive("emerwen_worker=debug".parse()?);
        } else {
            filter = filter.add_directive("emerwen_worker=info".parse()?);
        }

        tracing_subscriber::registry()
            .with(tracing_subscriber::fmt::layer().with_level(true))
            .with(filter)
            .init();
    }

    info!("Starting emerwen worker...");
    debug!("Hello, debug!");

M flake.nix => flake.nix +1 -0
@@ 88,6 88,7 @@
              protobuf

              just
              tokio-console

              #cargo-leptos


M justfile => justfile +3 -0
@@ 7,5 7,8 @@ master *ARGS:
worker *ARGS:
    cargo run --bin emerwen-worker -- {{ARGS}}

worker-trace *ARGS:
    cargo run --bin emerwen-worker --features trace -- {{ARGS}}

test-protocol:
    cargo test --package emerwen-protocol