diff --git a/src/bin/tcp_collector.rs b/src/bin/tcp_collector.rs index bc7eda4..529a78f 100644 --- a/src/bin/tcp_collector.rs +++ b/src/bin/tcp_collector.rs @@ -8,6 +8,7 @@ use std::io::{BufReader, Write}; use std::net::{SocketAddr, TcpStream}; use std::time::{Duration, Instant}; use tracing::debug; +use url::Url; /// Collect trace recorder streaming protocol data from a TCP connection #[derive(Parser, Debug, Clone)] @@ -47,11 +48,11 @@ pub struct Opts { )] pub connect_timeout: Option, - /// The remote address and port to connect to. + /// The remote TCP server URL or address:port to connect to. /// /// The default is `127.0.0.1:8888`. #[clap(long, name = "remote", help_heading = "STREAMING PORT CONFIGURATION")] - pub remote: Option, + pub remote: Option, } #[tokio::main] @@ -112,10 +113,24 @@ async fn do_main() -> Result<(), Box> { cfg.plugin.tcp_collector.remote = Some(remote); } - let remote = if let Some(remote) = cfg.plugin.tcp_collector.remote { - remote + let remote_string = if let Some(remote) = cfg.plugin.tcp_collector.remote.as_ref() { + remote.clone() } else { - "127.0.0.1:8888".parse()? + "127.0.0.1:8888".to_string() + }; + + let remote = if let Ok(socket_addr) = remote_string.parse::() { + socket_addr + } else { + let url = Url::parse(&remote_string) + .map_err(|e| format!("Failed to parse remote '{}' as URL. {}", remote_string, e))?; + debug!(remote_url = %url); + let socket_addrs = url + .socket_addrs(|| None) + .map_err(|e| format!("Failed to resolve remote URL '{}'. {}", url, e))?; + *socket_addrs + .first() + .ok_or_else(|| format!("Could not resolve URL '{}'", url))? }; cfg.ingest diff --git a/src/config.rs b/src/config.rs index 309434b..0818f28 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,7 +12,6 @@ use auxon_sdk::{ use derive_more::{Deref, From, Into}; use serde::Deserialize; use std::env; -use std::net::SocketAddr; use std::path::{Path, PathBuf}; use std::str::FromStr; use std::time::Duration; @@ -72,7 +71,7 @@ pub struct TcpCollectorConfig { pub disable_control_plane: bool, pub restart: bool, pub connect_timeout: Option, - pub remote: Option, + pub remote: Option, } #[derive(Clone, Debug, PartialEq, Eq, Deserialize)] @@ -927,7 +926,7 @@ breakpoint = "main" disable_control_plane: true, restart: true, connect_timeout: HumanTime::from_str("100ms").unwrap().into(), - remote: "127.0.0.1:8888".parse::().unwrap().into(), + remote: "127.0.0.1:8888".to_owned().into() }, itm_collector: Default::default(), rtt_collector: Default::default(),