diff --git a/server/src/cli.rs b/server/src/cli.rs index 691547f86..cc8aed23b 100644 --- a/server/src/cli.rs +++ b/server/src/cli.rs @@ -86,6 +86,9 @@ pub struct Cli { /// Mode of operation pub mode: Mode, + + /// public address for the parseable server + pub node_url: String, } impl Cli { @@ -112,6 +115,7 @@ impl Cli { pub const ROW_GROUP_SIZE: &'static str = "row-group-size"; pub const PARQUET_COMPRESSION_ALGO: &'static str = "compression-algo"; pub const MODE: &'static str = "mode"; + pub const NODE_URL: &'static str = "node-url"; pub const DEFAULT_USERNAME: &'static str = "admin"; pub const DEFAULT_PASSWORD: &'static str = "admin"; @@ -247,7 +251,7 @@ impl Cli { Arg::new(Self::OPENID_ISSUER) .long(Self::OPENID_ISSUER) .env("P_OIDC_ISSUER") - .value_name("URl") + .value_name("URL") .required(false) .value_parser(validation::url) .help("OIDC provider's host address"), @@ -312,6 +316,15 @@ impl Cli { "all"]) .help("Mode of operation"), ) + .arg( + Arg::new(Self::NODE_URL) + .long(Self::NODE_URL) + .env("P_NODE_URL") + .value_name("URL") + .required(false) + .value_parser(validation::socket_addr) + .help("Node URL for Parseable server") + ) .arg( Arg::new(Self::PARQUET_COMPRESSION_ALGO) .long(Self::PARQUET_COMPRESSION_ALGO) @@ -354,6 +367,12 @@ impl FromArgMatches for Cli { .get_one::(Self::ADDRESS) .cloned() .expect("default value for address"); + + self.node_url = m + .get_one::(Self::NODE_URL) + .cloned() + .unwrap_or_else(|| self.address.clone()); + self.local_staging_path = m .get_one::(Self::STAGING) .cloned() diff --git a/server/src/handlers/http/modal/server.rs b/server/src/handlers/http/modal/server.rs index 01ed5553f..74767683a 100644 --- a/server/src/handlers/http/modal/server.rs +++ b/server/src/handlers/http/modal/server.rs @@ -480,7 +480,7 @@ impl Server { pub fn get_server_address() -> SocketAddr { // this might cause an issue down the line // best is to make the Cli Struct better, but thats a chore - (CONFIG.parseable.address.clone()) + (CONFIG.parseable.node_url.clone()) .parse::() .unwrap() } diff --git a/server/src/storage/staging.rs b/server/src/storage/staging.rs index 2dfc11b08..578abfb26 100644 --- a/server/src/storage/staging.rs +++ b/server/src/storage/staging.rs @@ -20,7 +20,6 @@ use std::{ collections::HashMap, fs, - net::SocketAddr, path::{Path, PathBuf}, process, sync::Arc, @@ -37,6 +36,7 @@ use parquet::{ schema::types::ColumnPath, }; +use super::super::handlers::http::modal::server::Server; use crate::{ event::DEFAULT_TIMESTAMP_KEY, metrics, @@ -65,8 +65,10 @@ impl StorageDir { + &utils::hour_to_prefix(time.hour()) + &utils::minute_to_prefix(time.minute(), OBJECT_STORE_DATA_GRANULARITY).unwrap(); let local_uri = str::replace(&uri, "/", "."); - let hostname = utils::hostname_unchecked(); - format!("{local_uri}{hostname}.{extention}") + let sock = Server::get_server_address(); + let ip = sock.ip(); + let port = sock.port(); + format!("{local_uri}{ip}.{port}.{extention}") } fn filename_by_time(stream_hash: &str, time: NaiveDateTime) -> String { @@ -161,15 +163,8 @@ impl StorageDir { let filename = path.file_name().unwrap().to_str().unwrap(); let (_, filename) = filename.split_once('.').unwrap(); - let port = CONFIG - .parseable - .address - .clone() - .parse::() - .unwrap() - .port(); let filename = filename.rsplit_once('.').unwrap(); - let filename = format!("{}.{}.{}", filename.0, port, filename.1); + let filename = format!("{}.{}", filename.0, filename.1); /* let file_stem = path.file_stem().unwrap().to_str().unwrap(); let random_string = diff --git a/server/src/utils.rs b/server/src/utils.rs index 530f2b21d..6949873a0 100644 --- a/server/src/utils.rs +++ b/server/src/utils.rs @@ -35,7 +35,7 @@ pub fn hostname() -> Option { .ok() .and_then(|hostname| hostname.into_string().ok()) } - +#[allow(dead_code)] pub fn hostname_unchecked() -> String { hostname::get().unwrap().into_string().unwrap() } @@ -228,7 +228,7 @@ impl TimePeriod { #[inline(always)] pub fn get_address() -> (IpAddr, u16) { - let addr = CONFIG.parseable.address.parse::().unwrap(); + let addr = CONFIG.parseable.node_url.parse::().unwrap(); (addr.ip(), addr.port()) }