11use std:: net:: SocketAddr ;
22
33use apollo_infra:: component_definitions:: ComponentStarter ;
4+ use apollo_infra:: trace_util:: { configure_tracing, set_log_level} ;
45use apollo_infra_utils:: type_name:: short_type_name;
56use apollo_l1_provider_types:: { L1ProviderSnapshot , SharedL1ProviderClient } ;
67use apollo_mempool_types:: communication:: SharedMempoolClient ;
78use apollo_mempool_types:: mempool_types:: MempoolSnapshot ;
89use apollo_metrics:: metrics:: COLLECT_SEQUENCER_PROFILING_METRICS ;
910use apollo_monitoring_endpoint_config:: config:: MonitoringEndpointConfig ;
11+ use axum:: extract:: Path ;
1012use axum:: http:: StatusCode ;
1113use axum:: response:: { IntoResponse , Response } ;
12- use axum:: routing:: get;
14+ use axum:: routing:: { get, post } ;
1315use axum:: { async_trait, Json , Router , Server } ;
1416use hyper:: Error ;
1517use metrics_exporter_prometheus:: { PrometheusBuilder , PrometheusHandle } ;
18+ use tracing:: level_filters:: LevelFilter ;
1619use tracing:: { error, info, instrument} ;
1720
1821use crate :: tokio_metrics:: setup_tokio_metrics;
@@ -28,6 +31,7 @@ pub(crate) const VERSION: &str = "nodeVersion";
2831pub ( crate ) const METRICS : & str = "metrics" ;
2932pub ( crate ) const MEMPOOL_SNAPSHOT : & str = "mempoolSnapshot" ;
3033pub ( crate ) const L1_PROVIDER_SNAPSHOT : & str = "l1ProviderSnapshot" ;
34+ pub ( crate ) const SET_LOG_LEVEL : & str = "setLogLevel" ;
3135
3236pub const HISTOGRAM_BUCKETS : & [ f64 ] =
3337 & [ 0.001 , 0.0025 , 0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 0.25 , 0.5 , 1.0 , 2.5 , 5.0 , 10.0 , 25.0 , 50.0 ] ;
@@ -122,6 +126,10 @@ impl MonitoringEndpoint {
122126 format ! ( "/{MONITORING_PREFIX}/{L1_PROVIDER_SNAPSHOT}" ) . as_str ( ) ,
123127 get ( move || get_l1_provider_snapshot ( l1_provider_client) ) ,
124128 )
129+ . route (
130+ format ! ( "/{MONITORING_PREFIX}/{SET_LOG_LEVEL}/:crate/:level" ) . as_str ( ) ,
131+ post ( set_log_level_endpoint) ,
132+ )
125133 }
126134}
127135
@@ -211,3 +219,12 @@ async fn get_l1_provider_snapshot(
211219 None => Err ( StatusCode :: METHOD_NOT_ALLOWED ) ,
212220 }
213221}
222+
223+ async fn set_log_level_endpoint (
224+ Path ( ( crate_name, level) ) : Path < ( String , String ) > ,
225+ ) -> Result < StatusCode , StatusCode > {
226+ let level_filter = level. parse :: < LevelFilter > ( ) . map_err ( |_| StatusCode :: BAD_REQUEST ) ?;
227+ let handle = configure_tracing ( ) . await ;
228+ set_log_level ( & handle, & crate_name, level_filter) ;
229+ Ok ( StatusCode :: OK )
230+ }
0 commit comments