diff --git a/quickwit/quickwit-indexing/src/source/mod.rs b/quickwit/quickwit-indexing/src/source/mod.rs index dae5d9f5053..db2583d0e95 100644 --- a/quickwit/quickwit-indexing/src/source/mod.rs +++ b/quickwit/quickwit-indexing/src/source/mod.rs @@ -421,7 +421,7 @@ pub async fn check_source_connectivity( #[allow(unused_variables)] SourceParams::Kafka(params) => { #[cfg(not(feature = "kafka"))] - anyhow::bail!("Quickwit binary was not compiled with the `kafka` feature"); + anyhow::bail!("Quickwit was compiled without the `kafka` feature"); #[cfg(feature = "kafka")] { @@ -432,7 +432,7 @@ pub async fn check_source_connectivity( #[allow(unused_variables)] SourceParams::Kinesis(params) => { #[cfg(not(feature = "kinesis"))] - anyhow::bail!("Quickwit binary was not compiled with the `kinesis` feature"); + anyhow::bail!("Quickwit was compiled without the `kinesis` feature"); #[cfg(feature = "kinesis")] { @@ -443,7 +443,7 @@ pub async fn check_source_connectivity( #[allow(unused_variables)] SourceParams::Pulsar(params) => { #[cfg(not(feature = "pulsar"))] - anyhow::bail!("Quickwit binary was not compiled with the `pulsar` feature"); + anyhow::bail!("Quickwit was compiled without the `pulsar` feature"); #[cfg(feature = "pulsar")] { diff --git a/quickwit/quickwit-serve/src/developer_api/mod.rs b/quickwit/quickwit-serve/src/developer_api/mod.rs index c731d705616..491f57fe663 100644 --- a/quickwit/quickwit-serve/src/developer_api/mod.rs +++ b/quickwit/quickwit-serve/src/developer_api/mod.rs @@ -19,10 +19,12 @@ mod debug; mod log_level; +mod pprof; mod server; use debug::debug_handler; use log_level::log_level_handler; +use pprof::pprof_handlers; use quickwit_cluster::Cluster; pub(crate) use server::DeveloperApiServer; use warp::{Filter, Rejection}; @@ -37,6 +39,9 @@ pub(crate) fn developer_api_routes( cluster: Cluster, env_filter_reload_fn: EnvFilterReloadFn, ) -> impl Filter + Clone { - warp::path!("api" / "developer" / ..) - .and(debug_handler(cluster.clone()).or(log_level_handler(env_filter_reload_fn.clone()))) + warp::path!("api" / "developer" / ..).and( + debug_handler(cluster.clone()) + .or(log_level_handler(env_filter_reload_fn.clone())) + .or(pprof_handlers()), + ) } diff --git a/quickwit/quickwit-serve/src/pprof.rs b/quickwit/quickwit-serve/src/developer_api/pprof.rs similarity index 91% rename from quickwit/quickwit-serve/src/pprof.rs rename to quickwit/quickwit-serve/src/developer_api/pprof.rs index 51cd66636fb..12083a7ec6f 100644 --- a/quickwit/quickwit-serve/src/pprof.rs +++ b/quickwit/quickwit-serve/src/developer_api/pprof.rs @@ -22,25 +22,24 @@ use warp::Filter; /// pprof/start disabled /// pprof/flamegraph disabled #[cfg(not(feature = "pprof"))] -pub fn pprof_routes() -> impl Filter + Clone { +pub fn pprof_handlers() -> impl Filter + Clone +{ let start_profiler = { warp::path!("pprof" / "start").map(move || { warp::reply::with_status( - "not compiled with pprof feature", - warp::http::StatusCode::BAD_REQUEST, + "Quickwit was compiled without the `pprof` feature", + warp::http::StatusCode::NOT_IMPLEMENTED, ) }) }; - let stop_profiler = { warp::path!("pprof" / "flamegraph").map(move || { warp::reply::with_status( - "not compiled with pprof feature", - warp::http::StatusCode::BAD_REQUEST, + "Quickwit was compiled without the `pprof` feature", + warp::http::StatusCode::NOT_IMPLEMENTED, ) }) }; - start_profiler.or(stop_profiler) } @@ -54,7 +53,8 @@ pub fn pprof_routes() -> impl Filter impl Filter + Clone { +pub fn pprof_handlers() -> impl Filter + Clone +{ use std::sync::{Arc, Mutex}; use pprof::ProfilerGuard; @@ -101,6 +101,7 @@ pub fn pprof_routes() -> impl Filter Result { let mut state = profiler_state.lock().unwrap(); + if state.profiler_guard.is_none() { let max_duration = params.max_duration.unwrap_or(30).min(300); let sampling = params.sampling.unwrap_or(100).min(1000); @@ -128,11 +129,12 @@ pub fn pprof_routes() -> impl Filter impl Filter tokio::task::JoinHandle<()> { spawn_blocking(move || { let mut state = profiler_state.lock().unwrap(); + if let Some(profiler) = state.profiler_guard.take() { if let Ok(report) = profiler.report().build() { let mut buffer = Vec::new(); diff --git a/quickwit/quickwit-serve/src/lib.rs b/quickwit/quickwit-serve/src/lib.rs index b56d89a0da2..22c6730fc43 100644 --- a/quickwit/quickwit-serve/src/lib.rs +++ b/quickwit/quickwit-serve/src/lib.rs @@ -38,7 +38,6 @@ mod metrics_api; mod node_info_handler; mod openapi; mod otlp_api; -mod pprof; mod rate_modulator; mod rest; mod rest_api_response; diff --git a/quickwit/quickwit-serve/src/rest.rs b/quickwit/quickwit-serve/src/rest.rs index b97d0fee031..8945faf783f 100644 --- a/quickwit/quickwit-serve/src/rest.rs +++ b/quickwit/quickwit-serve/src/rest.rs @@ -46,7 +46,6 @@ use crate::jaeger_api::jaeger_api_handlers; use crate::metrics_api::metrics_handler; use crate::node_info_handler::node_info_handler; use crate::otlp_api::otlp_ingest_api_handlers; -use crate::pprof::pprof_routes; use crate::rest_api_response::{RestApiError, RestApiResponse}; use crate::search_api::{search_get_handler, search_post_handler, search_stream_handler}; use crate::template_api::index_template_api_handlers; @@ -158,10 +157,6 @@ pub(crate) async fn start_rest_server( quickwit_services.cluster.clone(), quickwit_services.env_filter_reload_fn.clone(), ); - - // `/pprof` route. - let cpu_pprof_routes = pprof_routes(); - // `/api/v1/*` routes. let api_v1_root_route = api_v1_routes(quickwit_services.clone()); @@ -185,7 +180,6 @@ pub(crate) async fn start_rest_server( .or(health_check_routes) .or(metrics_routes) .or(developer_routes) - .or(cpu_pprof_routes) .with(request_counter) .recover(recover_fn) .with(extra_headers)