Skip to content

Commit c93a8f1

Browse files
Update config and add new routes
1 parent 754a7e2 commit c93a8f1

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ pub struct HttpServerConfig {
135135
pub server_metrics_port: String,
136136
#[serde(default = "default_auth_config")]
137137
pub auth: AuthConfig,
138+
#[serde(default = "default_timeout_seconds")]
139+
pub timeout_seconds: u64,
138140
}
139141

140142
#[cfg(feature = "http")]
@@ -145,6 +147,7 @@ impl Default for HttpServerConfig {
145147
connection_url: default_connection_url(),
146148
server_metrics_port: default_server_metrics_port(),
147149
auth: default_auth_config(),
150+
timeout_seconds: default_timeout_seconds(),
148151
}
149152
}
150153
}
@@ -241,6 +244,11 @@ fn default_auth_config() -> AuthConfig {
241244
AuthConfig::default()
242245
}
243246

247+
#[cfg(feature = "http")]
248+
fn default_timeout_seconds() -> u64 {
249+
10
250+
}
251+
244252
pub fn create_config(config_path: PathBuf) -> AppConfig {
245253
if config_path.exists() {
246254
debug!("Config exists");

src/server/http/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ pub struct HttpApp {
6969

7070
impl HttpApp {
7171
/// create a new app for the flightsql server
72-
pub async fn try_new(execution: AppExecution, addr: &str, metrics_addr: &str) -> Result<Self> {
72+
pub async fn try_new(
73+
execution: AppExecution,
74+
config: AppConfig,
75+
addr: &str,
76+
metrics_addr: &str,
77+
) -> Result<Self> {
7378
info!("Listening to HTTP on {addr}");
7479
let listener = TcpListener::bind(addr).await.unwrap();
7580

7681
// prepare the shutdown channel
7782
let state = execution.execution_ctx().clone();
7883

79-
let router = create_router(state);
84+
let router = create_router(state, config.http_server);
8085

8186
let metrics_addr: SocketAddr = metrics_addr.parse()?;
8287
try_start_metrics_server(metrics_addr)?;
@@ -114,6 +119,7 @@ pub async fn try_run(cli: DftArgs, config: AppConfig) -> Result<()> {
114119
let app_execution = AppExecution::new(execution_ctx);
115120
let app = HttpApp::try_new(
116121
app_execution,
122+
config.clone(),
117123
&cli.host.unwrap_or(DEFAULT_SERVER_ADDRESS.to_string()),
118124
&config.http_server.server_metrics_port,
119125
)

src/server/http/router.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,22 @@ use log::error;
3131
use tokio_stream::StreamExt;
3232
use tower_http::{timeout::TimeoutLayer, trace::TraceLayer};
3333

34-
const DEFAULT_TIMEOUT_SECONDS: u64 = 10;
34+
use crate::config::HttpServerConfig;
3535

36-
pub fn create_router(execution: ExecutionContext) -> Router {
36+
pub fn create_router(execution: ExecutionContext, config: HttpServerConfig) -> Router {
3737
Router::new()
3838
.route(
3939
"/",
4040
get(|State(_): State<ExecutionContext>| async { "Hello, from DFT!" }),
4141
)
4242
.route("/sql", get(execute_sql))
43+
.route("/catalog", get(execute_sql))
44+
.route("/{catalog}/{schema}/{table}", get(execute_sql))
4345
.layer((
4446
TraceLayer::new_for_http(),
4547
// Graceful shutdown will wait for outstanding requests to complete. Add a timeout so
4648
// requests don't hang forever.
47-
TimeoutLayer::new(Duration::from_secs(DEFAULT_TIMEOUT_SECONDS)),
49+
TimeoutLayer::new(Duration::from_secs(config.timeout_seconds)),
4850
))
4951
.with_state(execution)
5052
}

0 commit comments

Comments
 (0)