diff --git a/Cargo.lock b/Cargo.lock index 36c6d45..5602192 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -199,6 +199,10 @@ checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "ctl" version = "0.1.0" +dependencies = [ + "setup", + "tracing", +] [[package]] name = "either" @@ -257,12 +261,24 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + [[package]] name = "memchr" version = "2.7.1" @@ -287,6 +303,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-traits" version = "0.2.18" @@ -321,6 +347,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "paste" version = "1.0.14" @@ -425,6 +457,28 @@ dependencies = [ "serde", ] +[[package]] +name = "setup" +version = "0.1.0" +dependencies = [ + "tracing-subscriber", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + [[package]] name = "strsim" version = "0.11.1" @@ -457,6 +511,16 @@ dependencies = [ "windows", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tokio" version = "1.36.0" @@ -480,6 +544,63 @@ dependencies = [ "syn", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", +] + [[package]] name = "unicode-ident" version = "1.0.12" @@ -502,6 +623,12 @@ dependencies = [ "serde", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -622,6 +749,8 @@ dependencies = [ "clap", "eyre", "proto", + "setup", "sysinfo", "tokio", + "tracing", ] diff --git a/Cargo.toml b/Cargo.toml index 7afd6dc..2a0307d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["ctl", "proto", "worker"] +members = ["crates/*", "ctl", "proto", "worker"] resolver = "2" [workspace.package] @@ -10,6 +10,7 @@ edition = "2021" # Internal deps ctl.path = "ctl" proto.path = "proto" +setup.path = "crates/setup" worker.path = "worker" # External deps (keep alphabetically sorted) axum = "0.7" @@ -31,6 +32,8 @@ tokio = { version = "1.36", features = [ "time", "sync", ] } +tracing = "0.1" +tracing-subscriber = "0.3" uuid = { version = "1", features = ["serde", "v4"] } [workspace.lints.clippy] diff --git a/crates/setup/Cargo.toml b/crates/setup/Cargo.toml new file mode 100644 index 0000000..3d3ae7c --- /dev/null +++ b/crates/setup/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "setup" +version.workspace = true +edition.workspace = true + +[dependencies] +tracing-subscriber.workspace = true + +[lints] +workspace = true diff --git a/crates/setup/src/lib.rs b/crates/setup/src/lib.rs new file mode 100644 index 0000000..591c1bd --- /dev/null +++ b/crates/setup/src/lib.rs @@ -0,0 +1,4 @@ +/// Sets up tracing. +pub fn tracing() { + tracing_subscriber::fmt::init(); +} diff --git a/ctl/Cargo.toml b/ctl/Cargo.toml index 1011561..88f5248 100644 --- a/ctl/Cargo.toml +++ b/ctl/Cargo.toml @@ -7,3 +7,6 @@ edition.workspace = true workspace = true [dependencies] +setup.workspace = true + +tracing.workspace = true diff --git a/ctl/src/main.rs b/ctl/src/main.rs index e7a11a9..94d60d4 100644 --- a/ctl/src/main.rs +++ b/ctl/src/main.rs @@ -1,3 +1,7 @@ +use tracing::info; + fn main() { - println!("Hello, world!"); + setup::tracing(); + + info!("started controller"); } diff --git a/worker/Cargo.toml b/worker/Cargo.toml index 2753414..a68b581 100644 --- a/worker/Cargo.toml +++ b/worker/Cargo.toml @@ -7,8 +7,11 @@ edition.workspace = true workspace = true [dependencies] +setup.workspace = true +proto.workspace = true + clap.workspace = true eyre.workspace = true -proto.workspace = true sysinfo.workspace = true tokio.workspace = true +tracing.workspace = true diff --git a/worker/src/args.rs b/worker/src/args.rs index 2c01b07..038e3b6 100644 --- a/worker/src/args.rs +++ b/worker/src/args.rs @@ -2,6 +2,7 @@ use std::{net::SocketAddr, time::Duration}; use clap::{value_parser, Parser}; +#[derive(Debug)] pub struct WorkerArgs { /// Controller's address. pub controller_addr: SocketAddr, diff --git a/worker/src/main.rs b/worker/src/main.rs index e7369cd..2d67b29 100644 --- a/worker/src/main.rs +++ b/worker/src/main.rs @@ -1,5 +1,6 @@ use eyre::Result; use tokio::time::sleep; +use tracing::info; use crate::{args::WorkerArgs, monitor::collector::MetricsCollector}; @@ -8,7 +9,10 @@ mod monitor; #[tokio::main] async fn main() -> Result<()> { + setup::tracing(); + let args = WorkerArgs::parse(); + info!(?args, "started worker"); let mut metrics_report: MetricsCollector = MetricsCollector::new();