Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 61 additions & 27 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ Arguments:
scheme that specifies the path to a Unix domain socket, as in
`file://localhost/path/to/socket`.

When the `vsock` feature is enabled, this may also be a URI
with the `vsock` scheme that specifies a vsock connection, as
in `vsock://2:6669` to connect to CID 2 port 6669.

[default: http://127.0.0.1:6669]

Options:
Expand Down
6 changes: 5 additions & 1 deletion console-subscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ default = ["env-filter"]
parking_lot = ["dep:parking_lot", "tracing-subscriber/parking_lot"]
env-filter = ["tracing-subscriber/env-filter"]
grpc-web = ["dep:tonic-web"]
vsock = ["dep:tokio-vsock"]

[dependencies]
crossbeam-utils = "0.8.7"
Expand All @@ -54,7 +55,10 @@ serde_json = "1"
crossbeam-channel = "0.5"

# Only for the web feature:
tonic-web = { version = "0.12", optional = true }
tonic-web = { version = "0.13", optional = true }

# Only for the vsock feature:
tokio-vsock = { version = "0.7.1", optional = true, features = ["tonic013"]}

[dev-dependencies]
tokio = { version = "1.34", features = ["full", "rt-multi-thread"] }
Expand Down
28 changes: 24 additions & 4 deletions console-subscriber/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ impl Builder {
/// before falling back on constructing a socket address from those
/// defaults.
///
/// The socket address can be either a TCP socket address or a
/// [Unix domain socket] (UDS) address. Unix domain sockets are only
/// supported on Unix-compatible operating systems, such as Linux, BSDs,
/// and macOS.
/// The socket address can be either a TCP socket address, a
/// [Unix domain socket] (UDS) address, or a [Vsock] address.
/// Unix domain sockets are only supported on Unix-compatible operating systems,
/// such as Linux, BSDs, and macOS. Vsock addresses are only available when the
/// "vsock" feature is enabled and are supported on platforms with vsock capability.
///
/// Each call to this method will overwrite the previously set value.
///
Expand All @@ -181,8 +182,17 @@ impl Builder {
/// let builder = Builder::default().server_addr(Path::new("/tmp/tokio-console"));
/// ```
///
/// Connect using a vsock connection (requires the "vsock" feature):
///
/// ```
/// # use console_subscriber::Builder;
/// # #[cfg(feature = "vsock")]
/// let builder = Builder::default().server_addr((tokio_vsock::VMADDR_CID_ANY, 6669));
/// ```
///
/// [environment variable]: `Builder::with_default_env`
/// [Unix domain socket]: https://en.wikipedia.org/wiki/Unix_domain_socket
/// [Vsock]: https://docs.rs/tokio-vsock/latest/tokio_vsock/
pub fn server_addr(self, server_addr: impl Into<ServerAddr>) -> Self {
Self {
server_addr: server_addr.into(),
Expand Down Expand Up @@ -574,6 +584,9 @@ pub enum ServerAddr {
/// A Unix socket address.
#[cfg(unix)]
Unix(PathBuf),
/// A vsock address.
#[cfg(feature = "vsock")]
Vsock(tokio_vsock::VsockAddr),
}

impl From<SocketAddr> for ServerAddr {
Expand Down Expand Up @@ -617,6 +630,13 @@ impl<'a> From<&'a Path> for ServerAddr {
}
}

#[cfg(feature = "vsock")]
impl From<tokio_vsock::VsockAddr> for ServerAddr {
fn from(addr: tokio_vsock::VsockAddr) -> ServerAddr {
ServerAddr::Vsock(addr)
}
}

/// Initializes the console [tracing `Subscriber`][sub] and starts the console
/// subscriber [`Server`] on its own background thread.
///
Expand Down
15 changes: 15 additions & 0 deletions console-subscriber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
use console_api as proto;
use proto::{instrument::instrument_server::InstrumentServer, resources::resource};
use serde::Serialize;
#[cfg(feature = "vsock")]
use tokio_vsock::VsockListener;

use std::{
cell::RefCell,
fmt,
Expand Down Expand Up @@ -955,6 +958,12 @@ impl Server {
let serve = router.serve_with_incoming(UnixListenerStream::new(incoming));
spawn_named(serve, "console::serve").await
}
#[cfg(feature = "vsock")]
ServerAddr::Vsock(addr) => {
let incoming = VsockListener::bind(addr)?.incoming();
let serve = router.serve_with_incoming(incoming);
spawn_named(serve, "console::serve").await
}
};
aggregate.abort();
res?.map_err(Into::into)
Expand Down Expand Up @@ -1082,6 +1091,12 @@ impl Server {
let serve = router.serve_with_incoming(UnixListenerStream::new(incoming));
spawn_named(serve, "console::serve").await
}
#[cfg(feature = "vsock")]
ServerAddr::Vsock(addr) => {
let incoming = VsockListener::bind(addr)?.incoming();
let serve = router.serve_with_incoming(incoming);
spawn_named(serve, "console::serve").await
}
};
aggregate.abort();
res?.map_err(Into::into)
Expand Down
6 changes: 6 additions & 0 deletions tokio-console/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ hdrhistogram = { version = "7.4.0", default-features = false, features = ["seria
h2 = "0.4.6"
regex = "1.11"
once_cell = "1.17.1"
cfg-if = "1.0.0"
humantime = "2.1.0"
serde = { version = "1.0.145", features = ["derive"] }
toml = "0.5"
dirs = "5"
hyper-util = { version = "0.1.6", features = ["tokio"] }
tokio-vsock = { version = "0.7.1", features = ["tonic013"], optional = true }

[features]
# Enable support for VSOCK address family, used in VMs
vsock = ["dep:tokio-vsock"]

[dev-dependencies]
trycmd = "0.15.4"
Expand Down
29 changes: 26 additions & 3 deletions tokio-console/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::state::tasks::Task;
use crate::view::Palette;
use crate::warnings;
use cfg_if::cfg_if;
use clap::builder::{PossibleValuesParser, TypedValueParser};
use clap::{ArgAction, ArgGroup, CommandFactory, Parser as Clap, Subcommand, ValueHint};
use clap_complete::Shell;
Expand Down Expand Up @@ -35,6 +36,9 @@ pub struct Config {
/// specifies the path to a Unix domain socket, as in
/// `file://localhost/path/to/socket`.
///
/// When the `vsock` feature is enabled, this may also be a URI with the `vsock` scheme that
/// specifies a vsock connection, as in `vsock://2:6669` to connect to CID 2 port 6669.
///
/// [default: http://127.0.0.1:6669]
#[clap(value_hint = ValueHint::Url)]
pub(crate) target_addr: Option<Uri>,
Expand Down Expand Up @@ -528,11 +532,30 @@ impl Config {
.clone();
match target_addr.scheme_str() {
Some("file" | "http" | "https") => {}
#[cfg(feature = "vsock")]
Some("vsock") => {}
#[cfg(not(feature = "vsock"))]
Some("vsock") => {
return Err(color_eyre::eyre::eyre!(
"vsock scheme detected in target address {:?}, but tokio-console was not compiled with the 'vsock' feature. \
Please recompile with '--features vsock' to enable vsock support",
target_addr
));
}
_ => {
// List of supported protocols is defined in the cfg_if block below
cfg_if! {
if #[cfg(feature = "vsock")] {
let protocols_display = "file, http, https, or vsock";
} else {
let protocols_display = "file, http, or https";
}
}
return Err(color_eyre::eyre::eyre!(
"invalid scheme for target address {:?}, must be one of 'file', 'http', or 'https'",
target_addr
))
"invalid scheme for target address {:?}, must be one of {}",
target_addr,
protocols_display
));
}
}
Ok(target_addr)
Expand Down
Loading
Loading