Repository: influxdata/influxdb
File: influxdb3_server/src/lib.rs (Rust)

Code before:

#[allow(dead_code)]
#[derive(Debug)]
pub struct Server<'a> {
    common_state: CommonServerState,
    http: Arc<HttpApi>,
    persister: Arc<Persister>,
    authorizer: Arc<dyn AuthProvider>,
    listener: TcpListener,
    key_file: Option<PathBuf>,
    cert_file: Option<PathBuf>,
    tls_minimum_version: &'a [&'static SupportedProtocolVersion],
}

impl Server<'_> {
    pub fn authorizer(&self) -> Arc<dyn Authorizer> {
        Arc::clone(&self.authorizer.upcast())
    }
}

pub async fn serve(
    server: Server<'_>,
    shutdown: CancellationToken,
    startup_timer: Instant,
    without_auth: bool,
    paths_without_authz: Vec<String>,
    tcp_listener_file_path: Option<PathBuf>,
) -> Result<()> {
    let req_metrics = RequestMetrics::new(
        Arc::clone(&server.common_state.metrics),
        MetricFamily::HttpServer,
    );
    let trace_layer = TraceLayer::new(
        server.common_state.trace_header_parser.clone(),
        Arc::new(req_metrics),
        server.common_state.trace_collector().clone(),
        TRACE_SERVER_NAME,
    );

    if let (Some(key_file), Some(cert_file)) = (&server.key_file, &server.cert_file) {
        let grpc_service = trace_layer.clone().layer(make_flight_server(
            Arc::clone(&server.http.query_executor),
            Some(server.authorizer()),
        ));

        let rest_service = hyper::service::make_service_fn(|_| {
            let http_server = Arc::clone(&server.http);
            let paths_without_authz = paths_without_authz.clone();
            let service = service_fn(move |req: hyper::Request<hyper::Body>| {
                route_request(
                    Arc::clone(&http_server),

Review comment (suggestion):
Might be able to make this cheaper to clone with `Vec<Arc<str>>`, or it could maybe be `Vec<&'static str>`, but that's not a blocker, since this is already pretty small and at most holds the three `health`, `ping`, and `metrics` strings...

Code after:

#[allow(dead_code)]
#[derive(Debug)]
pub struct Server<'a> {
    common_state: CommonServerState,
    http: Arc<HttpApi>,
    persister: Arc<Persister>,
    authorizer: Arc<dyn AuthProvider>,
    listener: TcpListener,
    key_file: Option<PathBuf>,
    cert_file: Option<PathBuf>,
    tls_minimum_version: &'a [&'static SupportedProtocolVersion],
}

impl Server<'_> {
    pub fn authorizer(&self) -> Arc<dyn Authorizer> {
        Arc::clone(&self.authorizer.upcast())
    }
}

pub async fn serve(
    server: Server<'_>,
    shutdown: CancellationToken,
    startup_timer: Instant,
    without_auth: bool,
    paths_without_authz: &'static Vec<&'static str>,
    tcp_listener_file_path: Option<PathBuf>,
) -> Result<()> {
    let req_metrics = RequestMetrics::new(
        Arc::clone(&server.common_state.metrics),
        MetricFamily::HttpServer,
    );
    let trace_layer = TraceLayer::new(
        server.common_state.trace_header_parser.clone(),
        Arc::new(req_metrics),
        server.common_state.trace_collector().clone(),
        TRACE_SERVER_NAME,
    );

    if let (Some(key_file), Some(cert_file)) = (&server.key_file, &server.cert_file) {
        let grpc_service = trace_layer.clone().layer(make_flight_server(
            Arc::clone(&server.http.query_executor),
            Some(server.authorizer()),
        ));

        let rest_service = hyper::service::make_service_fn(|_| {
            let http_server = Arc::clone(&server.http);
            let service = service_fn(move |req: hyper::Request<hyper::Body>| {
                route_request(
                    Arc::clone(&http_server),
                    req,