From 81116d3ace7f3000122b47421bcf0e33bab791ec Mon Sep 17 00:00:00 2001 From: Jan Teske Date: Fri, 9 Dec 2022 12:41:17 +0100 Subject: [PATCH] Support UDS listen address for tokio-console This commit fixes local tokio-console support, which was broken in ac1028d because tokio-console does not support Unix domain sockets (yet). The fix involves adding that support by switching to Nikhil's fork of concole-subscriber and using the `mz_ore::netio::SocketAddr` type for the tokio-console listen address. --- Cargo.lock | 6 ++---- src/orchestrator-tracing/src/lib.rs | 12 ++++++------ src/ore/Cargo.toml | 2 +- src/ore/src/tracing/mod.rs | 29 ++++++++++++++++++----------- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53896a844ccc7..03dfae74e7b7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1175,8 +1175,7 @@ dependencies = [ [[package]] name = "console-api" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e57ff02e8ad8e06ab9731d5dc72dc23bef9200778eae1a89d555d8c42e5d4a86" +source = "git+https://github.com/benesch/tokio-console.git?branch=uds#b409aa1a262f9196630c21406c8d11e61277cdcd" dependencies = [ "prost", "prost-types", @@ -1187,8 +1186,7 @@ dependencies = [ [[package]] name = "console-subscriber" version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a3a81dfaf6b66bce5d159eddae701e3a002f194d378cbf7be5f053c281d9be" +source = "git+https://github.com/benesch/tokio-console.git?branch=uds#b409aa1a262f9196630c21406c8d11e61277cdcd" dependencies = [ "console-api", "crossbeam-channel", diff --git a/src/orchestrator-tracing/src/lib.rs b/src/orchestrator-tracing/src/lib.rs index 2631e25b8fce5..6c027a85722ea 100644 --- a/src/orchestrator-tracing/src/lib.rs +++ b/src/orchestrator-tracing/src/lib.rs @@ -12,8 +12,6 @@ use std::collections::HashMap; use std::ffi::OsString; use std::fmt; -#[cfg(feature = "tokio-console")] -use std::net::SocketAddr; use std::str::FromStr; use std::sync::Arc; #[cfg(feature = "tokio-console")] @@ -35,6 +33,8 @@ use mz_orchestrator::{ }; use mz_ore::cli::{DefaultTrue, KeyValueArg}; #[cfg(feature = "tokio-console")] +use mz_ore::netio::SocketAddr; +#[cfg(feature = "tokio-console")] use mz_ore::tracing::TokioConsoleConfig; use mz_ore::tracing::{ OpenTelemetryConfig, SentryConfig, StderrLogConfig, StderrLogFormat, TracingConfig, @@ -227,13 +227,13 @@ impl From<&TracingCliArgs> for TracingConfig { } }), #[cfg(feature = "tokio-console")] - tokio_console: args - .tokio_console_listen_addr - .map(|listen_addr| TokioConsoleConfig { + tokio_console: args.tokio_console_listen_addr.clone().map(|listen_addr| { + TokioConsoleConfig { listen_addr, publish_interval: args.tokio_console_publish_interval, retention: args.tokio_console_retention, - }), + } + }), sentry: args.sentry_dsn.clone().map(|dsn| SentryConfig { dsn, tags: args diff --git a/src/ore/Cargo.toml b/src/ore/Cargo.toml index 6790eba9116e1..335f43679019e 100644 --- a/src/ore/Cargo.toml +++ b/src/ore/Cargo.toml @@ -56,7 +56,7 @@ hyper = { version = "0.14.23", features = ["http1", "server"], optional = true } hyper-tls = { version = "0.5.0", optional = true } opentelemetry = { git = "https://github.com/MaterializeInc/opentelemetry-rust.git", features = ["rt-tokio", "trace"], optional = true } opentelemetry-otlp = { git = "https://github.com/MaterializeInc/opentelemetry-rust.git", optional = true } -console-subscriber = { version = "0.1.8", optional = true } +console-subscriber = { git = "https://github.com/benesch/tokio-console.git", branch = "uds", optional = true } sentry-tracing = { version = "0.29.0", optional = true } [dev-dependencies] diff --git a/src/ore/src/tracing/mod.rs b/src/ore/src/tracing/mod.rs index f0844f1b68543..5e8f861369740 100644 --- a/src/ore/src/tracing/mod.rs +++ b/src/ore/src/tracing/mod.rs @@ -22,8 +22,6 @@ use std::borrow::Cow; use std::collections::HashMap; use std::io; -#[cfg(feature = "tokio-console")] -use std::net::SocketAddr; use std::sync::Arc; use std::time::Duration; @@ -50,6 +48,9 @@ use tracing_subscriber::registry::LookupSpan; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::{reload, Registry}; +#[cfg(feature = "tokio-console")] +use crate::netio::SocketAddr; + /// Application tracing configuration. /// /// See the [`configure`] function for details. @@ -330,12 +331,17 @@ where #[cfg(feature = "tokio-console")] let tokio_console_layer = if let Some(console_config) = config.tokio_console.clone() { - let layer = ConsoleLayer::builder() - .server_addr(console_config.listen_addr) + let builder = ConsoleLayer::builder() .publish_interval(console_config.publish_interval) - .retention(console_config.retention) - .spawn(); - Some(layer) + .retention(console_config.retention); + let builder = match console_config.listen_addr { + SocketAddr::Inet(addr) => builder.server_addr(addr), + SocketAddr::Unix(addr) => { + let path = addr.as_pathname().unwrap().as_ref(); + builder.server_addr(path) + } + }; + Some(builder.spawn()) } else { None }; @@ -373,10 +379,11 @@ where #[cfg(feature = "tokio-console")] if let Some(console_config) = config.tokio_console { - tracing::info!( - "starting tokio console on http://{}", - console_config.listen_addr - ); + let endpoint = match console_config.listen_addr { + SocketAddr::Inet(addr) => format!("http://{addr}"), + SocketAddr::Unix(addr) => addr.to_string(), + }; + tracing::info!("starting tokio console on {endpoint}"); } Ok((