Skip to content

Commit

Permalink
Support URLs in tcp collector remote field
Browse files Browse the repository at this point in the history
  • Loading branch information
jonlamb-gh committed Jul 14, 2024
1 parent 9b83a6f commit 34945a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
25 changes: 20 additions & 5 deletions src/bin/tcp_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -47,11 +48,11 @@ pub struct Opts {
)]
pub connect_timeout: Option<humantime::Duration>,

/// 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<SocketAddr>,
pub remote: Option<String>,
}

#[tokio::main]
Expand Down Expand Up @@ -112,10 +113,24 @@ async fn do_main() -> Result<(), Box<dyn std::error::Error>> {
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::<SocketAddr>() {
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
Expand Down
5 changes: 2 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,7 +71,7 @@ pub struct TcpCollectorConfig {
pub disable_control_plane: bool,
pub restart: bool,
pub connect_timeout: Option<HumanTime>,
pub remote: Option<SocketAddr>,
pub remote: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
Expand Down Expand Up @@ -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::<SocketAddr>().unwrap().into(),
remote: "127.0.0.1:8888".to_owned().into()
},
itm_collector: Default::default(),
rtt_collector: Default::default(),
Expand Down

0 comments on commit 34945a2

Please sign in to comment.