Skip to content

Commit 537e8fc

Browse files
apollo_monitoring_endpoint: add route to get log directives (#10185)
1 parent 77b7abf commit 537e8fc

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

crates/apollo_infra/src/trace_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,6 @@ pub fn set_log_level(handle: &ReloadHandle, crate_name: &str, level: LevelFilter
126126
}
127127
}
128128

129-
pub fn get_log_directives(handle: &ReloadHandle) -> String {
130-
handle.with_current(|f| f.to_string()).expect("handle should be valid")
129+
pub fn get_log_directives(handle: &ReloadHandle) -> Result<String, reload::Error> {
130+
handle.with_current(|f| f.to_string())
131131
}

crates/apollo_infra/src/trace_util_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ fn log_level_directive_updates() {
1010

1111
set_log_level(&reload_handle, "a", LevelFilter::DEBUG);
1212
set_log_level(&reload_handle, "b", LevelFilter::DEBUG);
13-
let directives = get_log_directives(&reload_handle);
13+
let directives = get_log_directives(&reload_handle).unwrap();
1414
assert_eq!(directives, "b=debug,a=debug,info");
1515
set_log_level(&reload_handle, "a", LevelFilter::INFO);
16-
let directives = get_log_directives(&reload_handle);
16+
let directives = get_log_directives(&reload_handle).unwrap();
1717
assert_eq!(directives, "b=debug,a=info,info");
1818
}

crates/apollo_monitoring_endpoint/src/monitoring_endpoint.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::net::SocketAddr;
22

33
use apollo_infra::component_definitions::ComponentStarter;
4-
use apollo_infra::trace_util::{configure_tracing, set_log_level};
4+
use apollo_infra::trace_util::{configure_tracing, get_log_directives, set_log_level};
55
use apollo_infra_utils::type_name::short_type_name;
66
use apollo_l1_provider_types::{L1ProviderSnapshot, SharedL1ProviderClient};
77
use apollo_mempool_types::communication::SharedMempoolClient;
@@ -32,6 +32,7 @@ pub(crate) const METRICS: &str = "metrics";
3232
pub(crate) const MEMPOOL_SNAPSHOT: &str = "mempoolSnapshot";
3333
pub(crate) const L1_PROVIDER_SNAPSHOT: &str = "l1ProviderSnapshot";
3434
pub(crate) const SET_LOG_LEVEL: &str = "setLogLevel";
35+
pub(crate) const LOG_LEVEL: &str = "logLevel";
3536

3637
pub const HISTOGRAM_BUCKETS: &[f64] =
3738
&[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];
@@ -130,6 +131,10 @@ impl MonitoringEndpoint {
130131
format!("/{MONITORING_PREFIX}/{SET_LOG_LEVEL}/:crate/:level").as_str(),
131132
post(set_log_level_endpoint),
132133
)
134+
.route(
135+
format!("/{MONITORING_PREFIX}/{LOG_LEVEL}").as_str(),
136+
get(get_log_directives_endpoint),
137+
)
133138
}
134139
}
135140

@@ -228,3 +233,14 @@ async fn set_log_level_endpoint(
228233
set_log_level(&handle, &crate_name, level_filter);
229234
Ok(StatusCode::OK)
230235
}
236+
237+
async fn get_log_directives_endpoint() -> impl IntoResponse {
238+
let handle = configure_tracing().await;
239+
match get_log_directives(&handle) {
240+
Ok(directives) => (StatusCode::OK, directives).into_response(),
241+
Err(err) => {
242+
(StatusCode::INTERNAL_SERVER_ERROR, format!("failed to read log directives: {err}"))
243+
.into_response()
244+
}
245+
}
246+
}

0 commit comments

Comments
 (0)