Skip to content

Commit

Permalink
A little cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmturner committed Nov 22, 2024
1 parent 7c5b74d commit 0c2daec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
18 changes: 3 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// specific language governing permissions and limitations
// under the License.

use std::net::SocketAddr;

use clap::Parser;
use color_eyre::Result;
use dft::args::DftArgs;
Expand All @@ -30,7 +28,6 @@ use dft::telemetry;
use dft::tui::state::AppState;
use dft::tui::{state, App};
use log::info;
use metrics_exporter_prometheus::PrometheusBuilder;

#[allow(unused_mut)]
fn main() -> Result<()> {
Expand Down Expand Up @@ -67,22 +64,13 @@ async fn app_entry_point(cli: DftArgs, state: AppState<'_>) -> Result<()> {
execution_ctx.execute_ddl().await;
}
let app_execution = AppExecution::new(execution_ctx);
let app = FlightSqlApp::new(
let app = FlightSqlApp::try_new(
app_execution,
&cli.flightsql_host
.unwrap_or(DEFAULT_SERVER_ADDRESS.to_string()),
&state.config.flightsql.server_metrics_port,
)
.await;
#[cfg(feature = "metrics")]
{
let builder = PrometheusBuilder::new();
let addr: SocketAddr = state.config.flightsql.server_metrics_port.parse()?;
info!("Listening to metrics on {addr}");
builder
.with_http_listener(addr)
.install()
.expect("failed to install metrics recorder/exporter");
}
.await?;
app.run_app().await;
return Ok(());
}
Expand Down
31 changes: 28 additions & 3 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub mod services;

use crate::execution::AppExecution;
use crate::test_utils::trailers_layer::TrailersLayer;
use color_eyre::Result;
use log::info;
use metrics_exporter_prometheus::PrometheusBuilder;
use std::net::SocketAddr;
use std::time::Duration;
use tokio::net::TcpListener;
Expand All @@ -41,7 +44,11 @@ pub struct FlightSqlApp {
impl FlightSqlApp {
/// create a new app for the flightsql server
#[allow(dead_code)]
pub async fn new(app_execution: AppExecution, addr: &str) -> Self {
pub async fn try_new(
app_execution: AppExecution,
addr: &str,
metrics_addr: &str,
) -> Result<Self> {
let flightsql = services::flightsql::FlightSqlServiceImpl::new(app_execution);
// let OS choose a free port
let listener = TcpListener::bind(addr).await.unwrap();
Expand All @@ -65,14 +72,32 @@ impl FlightSqlApp {
shutdown_future,
);

#[cfg(feature = "metrics")]
{
let builder = PrometheusBuilder::new();
let addr: SocketAddr = metrics_addr.parse()?;
info!("Listening to metrics on {addr}");
builder
.with_http_listener(addr)
.install()
.expect("failed to install metrics recorder/exporter");

metrics::describe_histogram!(
"logical_planning_ms",
metrics::Unit::Milliseconds,
"Logical planning ms"
);
}

// Run the server in its own background task
let handle = tokio::task::spawn(serve_future);

Self {
let app = Self {
shutdown: Some(tx),
addr,
handle: Some(handle),
}
};
Ok(app)
}

/// Stops the server and waits for the server to shutdown
Expand Down

0 comments on commit 0c2daec

Please sign in to comment.