From 07d2e7e3c39ed557f6efa34e23ff6493c15c3d29 Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Mon, 6 Apr 2026 11:52:06 +0400 Subject: [PATCH 1/2] Add waymark-tokio-metrics-bringup crate --- .cargo/config.toml | 3 ++ Cargo.lock | 22 +++++++++++++++ Cargo.toml | 1 + crates/lib/tokio-metrics-bringup/Cargo.toml | 10 +++++++ crates/lib/tokio-metrics-bringup/src/lib.rs | 31 +++++++++++++++++++++ 5 files changed, 67 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 crates/lib/tokio-metrics-bringup/Cargo.toml create mode 100644 crates/lib/tokio-metrics-bringup/src/lib.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..6e54197e --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +[build] +rustflags = ["--cfg", "tokio_unstable"] +rustdocflags = ["--cfg", "tokio_unstable"] diff --git a/Cargo.lock b/Cargo.lock index d14684ef..4b824184 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3418,6 +3418,19 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-metrics" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0410015c6db7b67b9c9ab2a3af4d74a942d637ff248d0d055073750deac6f9" +dependencies = [ + "futures-util", + "metrics", + "pin-project-lite", + "tokio", + "tokio-stream", +] + [[package]] name = "tokio-rustls" version = "0.26.4" @@ -4716,6 +4729,15 @@ dependencies = [ "metrics-util", ] +[[package]] +name = "waymark-tokio-metrics-bringup" +version = "0.1.0" +dependencies = [ + "metrics", + "tokio", + "tokio-metrics", +] + [[package]] name = "waymark-utils-futures" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 1b6a0fba..b4f44295 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -107,6 +107,7 @@ syn = "2" tera = "1" thiserror = "2" tokio = "1" +tokio-metrics = "0.4" tokio-stream = "0.1" tokio-util = "0.7" tonic = "0.11" diff --git a/crates/lib/tokio-metrics-bringup/Cargo.toml b/crates/lib/tokio-metrics-bringup/Cargo.toml new file mode 100644 index 00000000..4acd2461 --- /dev/null +++ b/crates/lib/tokio-metrics-bringup/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "waymark-tokio-metrics-bringup" +edition = "2024" +version.workspace = true +publish.workspace = true + +[dependencies] +metrics = { workspace = true } +tokio = { workspace = true, features = ["rt"] } +tokio-metrics = { workspace = true, features = ["metrics-rs-integration"] } diff --git a/crates/lib/tokio-metrics-bringup/src/lib.rs b/crates/lib/tokio-metrics-bringup/src/lib.rs new file mode 100644 index 00000000..781e2f70 --- /dev/null +++ b/crates/lib/tokio-metrics-bringup/src/lib.rs @@ -0,0 +1,31 @@ +fn make_metric_name_transformer( + executable_name: &'static str, +) -> impl Fn(&'static str) -> metrics::Key + Send + Sync + Copy + 'static { + move |name| { + metrics::Key::from_parts( + metrics::KeyName::from_const_str(name), + &[("application", executable_name)], + ) + } +} + +// TODO: update spawns when we have a proper +// task management / registration system. +pub fn bringup(executable_name: &'static str) -> tokio_metrics::TaskMonitor { + let metric_name_transformer = make_metric_name_transformer(executable_name); + + tokio::spawn( + tokio_metrics::RuntimeMetricsReporterBuilder::default() + .with_metrics_transformer(metric_name_transformer) + .describe_and_run(), + ); + + let task_monitor = tokio_metrics::TaskMonitor::new(); + + tokio::spawn( + tokio_metrics::TaskMetricsReporterBuilder::new(metric_name_transformer) + .describe_and_run(task_monitor.clone()), + ); + + task_monitor +} From a368eeace23aa102bb4725cba92d3bd8916f3bea Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Mon, 6 Apr 2026 11:52:25 +0400 Subject: [PATCH 2/2] Integrate tokio metrics at start-workers --- Cargo.lock | 1 + Cargo.toml | 1 + crates/bin/start-workers/Cargo.toml | 1 + crates/bin/start-workers/src/main.rs | 2 ++ 4 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 4b824184..ec145120 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4661,6 +4661,7 @@ dependencies = [ "waymark-runloop", "waymark-scheduler-loop", "waymark-scheduler-loop-core", + "waymark-tokio-metrics-bringup", "waymark-webapp-bringup", "waymark-worker-remote", "waymark-worker-status-reporter", diff --git a/Cargo.toml b/Cargo.toml index b4f44295..c91d0f29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,7 @@ waymark-tick-loop = { path = "crates/lib/tick-loop" } waymark-timed = { path = "crates/lib/timed" } waymark-timed-channel = { path = "crates/lib/timed-channel" } waymark-timed-future = { path = "crates/lib/timed-future" } +waymark-tokio-metrics-bringup = { path = "crates/lib/tokio-metrics-bringup" } waymark-utils-futures = { path = "crates/lib/utils-futures" } waymark-utils-tokio-channel = { path = "crates/lib/utils-tokio-channel" } waymark-webapp-backend = { path = "crates/lib/webapp-backend" } diff --git a/crates/bin/start-workers/Cargo.toml b/crates/bin/start-workers/Cargo.toml index 7f131536..b854bb89 100644 --- a/crates/bin/start-workers/Cargo.toml +++ b/crates/bin/start-workers/Cargo.toml @@ -18,6 +18,7 @@ waymark-proto = { workspace = true } waymark-runloop = { workspace = true } waymark-scheduler-loop = { workspace = true } waymark-scheduler-loop-core = { workspace = true } +waymark-tokio-metrics-bringup = { workspace = true } waymark-webapp-bringup = { workspace = true } waymark-worker-remote = { workspace = true } waymark-worker-status-reporter = { workspace = true } diff --git a/crates/bin/start-workers/src/main.rs b/crates/bin/start-workers/src/main.rs index 5de72654..9e672afe 100644 --- a/crates/bin/start-workers/src/main.rs +++ b/crates/bin/start-workers/src/main.rs @@ -60,6 +60,8 @@ async fn main() -> Result<()> { let metrics_addr: std::net::SocketAddr = envfury::or_parse("METRICS_ADDR", "0.0.0.0:9118")?; waymark_prometheus_exporter_bringup::spawn_and_install_recorder(metrics_addr)?; + let _task_monitor = waymark_tokio_metrics_bringup::bringup(env!("CARGO_BIN_NAME")); + // Load configuration and announce startup. let config = WorkerConfig::from_env()?;