Skip to content

Commit

Permalink
Add /reset-tracing route to admin server
Browse files Browse the repository at this point in the history
  • Loading branch information
mystenmark committed Oct 6, 2023
1 parent 8897482 commit e1e7840
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions crates/sui-node/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ use tracing::info;
// automatically.
//
// $ curl -X POST 'http://127.0.0.1:1337/enable-tracing?filter=info&duration=10s'
//
// Reset tracing to the TRACE_FILTER env var.
//
// $ curl -X POST 'http://127.0.0.1:1337/reset-tracing'

const LOGGING_ROUTE: &str = "/logging";
const TRACING_ROUTE: &str = "/enable-tracing";
const TRACING_RESET_ROUTE: &str = "/reset-tracing";
const SET_BUFFER_STAKE_ROUTE: &str = "/set-override-buffer-stake";
const CLEAR_BUFFER_STAKE_ROUTE: &str = "/clear-override-buffer-stake";
const FORCE_CLOSE_EPOCH: &str = "/force-close-epoch";
Expand Down Expand Up @@ -77,6 +82,7 @@ pub async fn run_admin_server(node: Arc<SuiNode>, port: u16, filters: Filters) {
)
.route(FORCE_CLOSE_EPOCH, post(force_close_epoch))
.route(TRACING_ROUTE, post(enable_tracing))
.route(TRACING_RESET_ROUTE, post(reset_tracing))
.with_state(Arc::new(app_state));

let socket_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), port);
Expand Down Expand Up @@ -117,6 +123,16 @@ async fn enable_tracing(
}
}

async fn reset_tracing(State(state): State<Arc<AppState>>) -> (StatusCode, String) {
match state.filters.reset_trace() {
Ok(()) => (
StatusCode::OK,
"tracing filter reset to TRACE_FILTER env var".into(),
),
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()),
}
}

async fn get_filter(State(state): State<Arc<AppState>>) -> (StatusCode, String) {
match state.filters.get_log() {
Ok(filter) => (StatusCode::OK, filter),
Expand Down
10 changes: 9 additions & 1 deletion crates/telemetry-subscribers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ impl Filters {
let res = trace.update(directives);
// after duration is elapsed, reset to the env setting
let trace = trace.clone();
// load TRACE_FILTER env
let trace_filter_env = env::var("TRACE_FILTER").unwrap_or_else(|_| "off".to_string());
tokio::spawn(async move {
tokio::time::sleep(duration).await;
Expand All @@ -132,6 +131,15 @@ impl Filters {
Ok(())
}
}

pub fn reset_trace(&self) {
if let Some(trace) = &self.trace {
let trace_filter_env = env::var("TRACE_FILTER").unwrap_or_else(|_| "off".to_string());
if let Err(e) = trace.update(trace_filter_env) {
error!("failed to reset trace filter: {}", e);
}
}
}
}

fn get_output(log_file: Option<String>) -> (NonBlocking, WorkerGuard) {
Expand Down

0 comments on commit e1e7840

Please sign in to comment.