Skip to content

Commit baba4f1

Browse files
Move host arg (#319)
1 parent 269bb09 commit baba4f1

16 files changed

Lines changed: 312 additions & 62 deletions

File tree

.github/workflows/test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,31 @@ jobs:
313313
- name: Run tests
314314
run: |
315315
cargo t --features=http,flightsql server::http::router
316+
- name: Run CLI cases
317+
run: |
318+
cargo t --features=http,flightsql server_cases::http
319+
test-flightsql-server:
320+
name: Extension / FlightSQL Server
321+
runs-on: ubuntu-latest
322+
strategy:
323+
matrix:
324+
arch: [amd64]
325+
steps:
326+
- uses: actions/checkout@v2
327+
with:
328+
submodules: true
329+
- name: Cache Cargo
330+
uses: actions/cache@v4
331+
with:
332+
path: /home/runner/.cargo
333+
key: cargo-dft-cache-
334+
- name: Cache Rust dependencies
335+
uses: actions/cache@v4
336+
with:
337+
path: target
338+
key: ${{ runner.os }}-cargo-target-${{ hashFiles('Cargo.lock') }}
339+
- name: Setup Rust Toolchain
340+
uses: ./.github/actions/setup-rust
341+
- name: Run CLI cases
342+
run: |
343+
cargo t --features=http,flightsql server_cases::http

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ serde = { version = "1.0.197", features = ["derive"] }
4242
strum = "0.26.2"
4343
tokio = { version = "1.36.0", features = [
4444
"macros",
45+
"process",
4546
"rt-multi-thread",
4647
"signal",
4748
] }

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ benchmark_iterations = 10
112112

113113
[flightsql_server]
114114
connection_url = "http://localhost:50051"
115-
server_metrics_port = "0.0.0.0:9000"
115+
server_metrics_addr = "0.0.0.0:9000"
116116
```
117117

118118
## Editor Config

docs/flightsql_server.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ Prometheus metrics are automatically published to help you monitor server perfor
4949

5050
```toml
5151
[flightsql_server]
52-
# Configure metrics port
53-
server_metrics_port = "0.0.0.0:9000"
52+
# Configure metrics addr
53+
server_metrics_addr = "0.0.0.0:9000"
5454
```
5555

5656
Available metrics include:

docs/http_server.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Prometheus metrics are automatically published.
3636

3737
```toml
3838
[flightsql_server]
39-
server_metrics_port = "0.0.0.0:9000"
39+
server_metrics_addr = "0.0.0.0:9000"
4040
```
4141

4242
## Benchmarking

src/args.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
2020
use crate::config::get_data_dir;
2121
use clap::{Parser, Subcommand};
22-
use std::path::{Path, PathBuf};
22+
use std::{
23+
net::SocketAddr,
24+
path::{Path, PathBuf},
25+
};
2326

2427
const LONG_ABOUT: &str = "
2528
dft - DataFusion TUI
@@ -92,12 +95,7 @@ pub struct DftArgs {
9295
#[clap(short = 'n', help = "Set the number of benchmark iterations to run")]
9396
pub benchmark_iterations: Option<usize>,
9497

95-
#[cfg(any(feature = "flightsql", feature = "http"))]
96-
#[clap(
97-
long,
98-
global = true,
99-
help = "Set the host and port to be used for server"
100-
)]
98+
#[clap(long, help = "Host address to connect to")]
10199
pub host: Option<String>,
102100

103101
#[clap(
@@ -107,13 +105,18 @@ pub struct DftArgs {
107105
)]
108106
pub output: Option<PathBuf>,
109107

108+
#[cfg(any(feature = "flightsql", feature = "http"))]
110109
#[command(subcommand)]
111110
pub command: Option<Command>,
112111
}
113112

114113
impl DftArgs {
115114
pub fn config_path(&self) -> PathBuf {
116-
if let Some(Command::ServeFlightSql { config: Some(cfg) }) = &self.command {
115+
#[cfg(any(feature = "flightsql", feature = "http"))]
116+
if let Some(Command::ServeFlightSql {
117+
config: Some(cfg), ..
118+
}) = &self.command
119+
{
117120
return Path::new(cfg).to_path_buf();
118121
}
119122
if let Some(config) = self.config.as_ref() {
@@ -132,12 +135,20 @@ pub enum Command {
132135
ServeHttp {
133136
#[clap(short, long)]
134137
config: Option<String>,
138+
#[clap(long, help = "Set the port to be used for server")]
139+
addr: Option<SocketAddr>,
140+
#[clap(long, help = "Set the port to be used for serving metrics")]
141+
metrics_addr: Option<SocketAddr>,
135142
},
136143
/// Start a FlightSQL server
137144
#[command(name = "serve-flightsql")]
138145
ServeFlightSql {
139146
#[clap(short, long)]
140147
config: Option<String>,
148+
#[clap(long, help = "Set the port to be used for server")]
149+
addr: Option<SocketAddr>,
150+
#[clap(long, help = "Set the port to be used for serving metrics")]
151+
metrics_addr: Option<SocketAddr>,
141152
},
142153
}
143154

src/config.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
2020
use std::path::PathBuf;
2121

22+
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
23+
2224
use datafusion_app::config::ExecutionConfig;
2325
use directories::{ProjectDirs, UserDirs};
2426
use lazy_static::lazy_static;
@@ -84,8 +86,8 @@ pub struct FlightSQLServerConfig {
8486
pub execution: ExecutionConfig,
8587
#[serde(default = "default_connection_url")]
8688
pub connection_url: String,
87-
#[serde(default = "default_server_metrics_port")]
88-
pub server_metrics_port: String,
89+
#[serde(default = "default_server_metrics_addr")]
90+
pub server_metrics_addr: SocketAddr,
8991
#[serde(default = "default_auth_config")]
9092
pub auth: AuthConfig,
9193
}
@@ -96,7 +98,7 @@ impl Default for FlightSQLServerConfig {
9698
Self {
9799
execution: default_execution_config(),
98100
connection_url: default_connection_url(),
99-
server_metrics_port: default_server_metrics_port(),
101+
server_metrics_addr: default_server_metrics_addr(),
100102
auth: default_auth_config(),
101103
}
102104
}
@@ -131,8 +133,8 @@ pub struct HttpServerConfig {
131133
pub execution: ExecutionConfig,
132134
#[serde(default = "default_connection_url")]
133135
pub connection_url: String,
134-
#[serde(default = "default_server_metrics_port")]
135-
pub server_metrics_port: String,
136+
#[serde(default = "default_server_metrics_addr")]
137+
pub server_metrics_addr: SocketAddr,
136138
#[serde(default = "default_auth_config")]
137139
pub auth: AuthConfig,
138140
#[serde(default = "default_timeout_seconds")]
@@ -147,7 +149,7 @@ impl Default for HttpServerConfig {
147149
Self {
148150
execution: default_execution_config(),
149151
connection_url: default_connection_url(),
150-
server_metrics_port: default_server_metrics_port(),
152+
server_metrics_addr: default_server_metrics_addr(),
151153
auth: default_auth_config(),
152154
timeout_seconds: default_timeout_seconds(),
153155
result_limit: default_result_limit(),
@@ -229,8 +231,8 @@ pub fn default_connection_url() -> String {
229231
}
230232

231233
#[cfg(any(feature = "flightsql", feature = "http"))]
232-
fn default_server_metrics_port() -> String {
233-
"0.0.0.0:9000".to_string()
234+
fn default_server_metrics_addr() -> SocketAddr {
235+
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 9000)
234236
}
235237

236238
#[derive(Clone, Debug, Default, Deserialize)]

src/main.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ async fn app_entry_point(cli: DftArgs) -> Result<()> {
6464
}
6565
#[cfg(feature = "http")]
6666
{
67-
tracing_subscriber::registry()
68-
.with(
69-
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
70-
format!(
71-
"{}=debug,tower_http=debug,axum=trace",
72-
env!("CARGO_CRATE_NAME")
73-
)
74-
.into()
75-
}),
76-
)
77-
.with(tracing_subscriber::fmt::layer().without_time())
78-
.init();
7967
if let Some(Command::ServeHttp { .. }) = cli.command {
68+
tracing_subscriber::registry()
69+
.with(
70+
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
71+
format!(
72+
"{}=debug,tower_http=debug,axum=trace",
73+
env!("CARGO_CRATE_NAME")
74+
)
75+
.into()
76+
}),
77+
)
78+
.with(tracing_subscriber::fmt::layer().without_time())
79+
.init();
8080
server::http::try_run(cli.clone(), cfg.clone()).await?;
8181
return Ok(());
8282
}

src/server/flightsql/mod.rs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
pub mod service;
1919

20-
use crate::args::DftArgs;
20+
use crate::args::{Command, DftArgs};
2121
use crate::config::AppConfig;
2222
use crate::execution::AppExecution;
2323
use color_eyre::{eyre::eyre, Result};
@@ -26,7 +26,7 @@ use datafusion_app::extensions::DftSessionStateBuilder;
2626
use datafusion_app::local::ExecutionContext;
2727
use log::info;
2828
use service::FlightSqlServiceImpl;
29-
use std::net::SocketAddr;
29+
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
3030
use std::time::Duration;
3131
use tokio::net::TcpListener;
3232
use tokio::sync::oneshot;
@@ -38,7 +38,6 @@ use tower_http::validate_request::ValidateRequestHeaderLayer;
3838
use super::try_start_metrics_server;
3939

4040
const DEFAULT_TIMEOUT_SECONDS: u64 = 60;
41-
const DEFAULT_SERVER_ADDRESS: &str = "127.0.0.1:50051";
4241

4342
pub fn create_server_handle(
4443
config: &AppConfig,
@@ -121,8 +120,8 @@ impl FlightSqlApp {
121120
pub async fn try_new(
122121
app_execution: AppExecution,
123122
config: &AppConfig,
124-
addr: &str,
125-
metrics_addr: &str,
123+
addr: SocketAddr,
124+
metrics_addr: SocketAddr,
126125
) -> Result<Self> {
127126
info!("Listening to FlightSQL on {addr}");
128127
let flightsql = service::FlightSqlServiceImpl::new(app_execution);
@@ -132,7 +131,6 @@ impl FlightSqlApp {
132131
let (tx, rx) = tokio::sync::oneshot::channel();
133132
let handle = create_server_handle(config, flightsql, listener, rx)?;
134133

135-
let metrics_addr: SocketAddr = metrics_addr.parse()?;
136134
try_start_metrics_server(metrics_addr)?;
137135

138136
let app = Self {
@@ -188,13 +186,41 @@ pub async fn try_run(cli: DftArgs, config: AppConfig) -> Result<()> {
188186
execution_ctx.execute_ddl().await;
189187
}
190188
let app_execution = AppExecution::new(execution_ctx);
191-
let app = FlightSqlApp::try_new(
192-
app_execution,
193-
&config,
194-
&cli.host.unwrap_or(DEFAULT_SERVER_ADDRESS.to_string()),
195-
&config.flightsql_server.server_metrics_port,
196-
)
197-
.await?;
189+
190+
let (addr, metrics_addr) = if let Some(cmd) = cli.command.clone() {
191+
match cmd {
192+
Command::ServeFlightSql {
193+
addr: Some(addr),
194+
metrics_addr: Some(metrics_addr),
195+
..
196+
} => (addr, metrics_addr),
197+
Command::ServeFlightSql {
198+
addr: Some(addr),
199+
metrics_addr: None,
200+
..
201+
} => (addr, config.flightsql_server.server_metrics_addr),
202+
Command::ServeFlightSql {
203+
addr: None,
204+
metrics_addr: Some(metrics_addr),
205+
..
206+
} => (
207+
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 50051),
208+
metrics_addr,
209+
),
210+
211+
_ => (
212+
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 50051),
213+
config.flightsql_server.server_metrics_addr,
214+
),
215+
}
216+
} else {
217+
(
218+
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 50051),
219+
config.flightsql_server.server_metrics_addr,
220+
)
221+
};
222+
223+
let app = FlightSqlApp::try_new(app_execution, &config, addr, metrics_addr).await?;
198224
app.run().await;
199225
Ok(())
200226
}

0 commit comments

Comments
 (0)