-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
linkerd/linkerd2-proxy
#1437Labels
Description
In the proxy's test initialization code, we use std::env::set_var
to configure a log format:
pub fn trace_subscriber(default: impl ToString) -> (Dispatch, Handle) {
let log_level = env::var("LINKERD2_PROXY_LOG")
.or_else(|_| env::var("RUST_LOG"))
.unwrap_or_else(|_| default.to_string());
let log_format = env::var("LINKERD2_PROXY_LOG_FORMAT").unwrap_or_else(|_| "PLAIN".to_string());
env::set_var("LINKERD2_PROXY_LOG_FORMAT", &log_format);
// This may fail, since the global log compat layer may have been
// initialized by another test.
let _ = init_log_compat();
Settings::for_test(log_level, log_format).build()
}
My understanding is that this is unsafe, per rust-lang/rust#90308, because our tests run in multiple threads. It would be great if we could avoid environment mutation in our codebase.
Can we remove this? Do we actually care about JSON formatting in our tests?
Are there tools we could use to, for instance, make clippy fail on new uses of set_var
/remove_var
?