Skip to content

Commit

Permalink
Add node_url field to Cli struct and update related code (#734)
Browse files Browse the repository at this point in the history
* Add node_url field to Cli struct and update related code

* Update required flag for Node URL in CLI

* updated logic to have server address (ip:port) in parquet file name similar to other json files

---------

Co-authored-by: Nikhil Sinha <[email protected]>
  • Loading branch information
Eshanatnight and nikhilsinhaparseable authored Apr 3, 2024
1 parent ec30a5c commit 7bbb584
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
21 changes: 20 additions & 1 deletion server/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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";

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -354,6 +367,12 @@ impl FromArgMatches for Cli {
.get_one::<String>(Self::ADDRESS)
.cloned()
.expect("default value for address");

self.node_url = m
.get_one::<String>(Self::NODE_URL)
.cloned()
.unwrap_or_else(|| self.address.clone());

self.local_staging_path = m
.get_one::<PathBuf>(Self::STAGING)
.cloned()
Expand Down
2 changes: 1 addition & 1 deletion server/src/handlers/http/modal/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<SocketAddr>()
.unwrap()
}
Expand Down
17 changes: 6 additions & 11 deletions server/src/storage/staging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use std::{
collections::HashMap,
fs,
net::SocketAddr,
path::{Path, PathBuf},
process,
sync::Arc,
Expand All @@ -37,6 +36,7 @@ use parquet::{
schema::types::ColumnPath,
};

use super::super::handlers::http::modal::server::Server;
use crate::{
event::DEFAULT_TIMESTAMP_KEY,
metrics,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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::<SocketAddr>()
.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 =
Expand Down
4 changes: 2 additions & 2 deletions server/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn hostname() -> Option<String> {
.ok()
.and_then(|hostname| hostname.into_string().ok())
}

#[allow(dead_code)]
pub fn hostname_unchecked() -> String {
hostname::get().unwrap().into_string().unwrap()
}
Expand Down Expand Up @@ -228,7 +228,7 @@ impl TimePeriod {

#[inline(always)]
pub fn get_address() -> (IpAddr, u16) {
let addr = CONFIG.parseable.address.parse::<SocketAddr>().unwrap();
let addr = CONFIG.parseable.node_url.parse::<SocketAddr>().unwrap();
(addr.ip(), addr.port())
}

Expand Down

0 comments on commit 7bbb584

Please sign in to comment.