Skip to content

Commit 22e82e8

Browse files
authored
trace: tweak tracing & test support for the multithreaded runtime (#616)
This branch makes a couple minor tweaks to improve tracing with the multithreaded Tokio runtime. It enables the option to print thread IDs when logging trace output, which should make it somewhat clearer when events occur on different threads. Additionally, there's currently an issue where traces are not logged from the proxy during integration tests. Only traces from the test support code are logged. This is because we are using `tracing`'s scoped thread-local dispatcher in the test proxy, so that each test can create its own subscriber. We set the test's subscriber as the default for the test proxy thread, but *not* as the global default for all threads. However, when the multithreaded runtime is enabled, the default runtime returned by `tokio::runtime::Runtime::new` is now a multithreaded runtime. Therefore, the test proxy runs on the runtime's worker threads, rather than the main thread spawned by the tests, and the dispatcher is not set for the worker threads. This branch fixes that issue by explicitly using the basic (single threaded) scheduler when creating the test proxy. This should (hopefully) also improve test flakiness a bit by not spawning a whole bunch of workers.
1 parent 0603e14 commit 22e82e8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

linkerd/app/core/src/trace.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ pub fn with_filter_and_format(
6363
// Set up the subscriber
6464
let start_time = clock::now();
6565
let filter = tracing_subscriber::EnvFilter::new(filter);
66-
66+
let formatter = tracing_subscriber::fmt::format()
67+
.with_timer(Uptime { start_time })
68+
.with_thread_ids(true);
6769
let (dispatch, level, tasks) = match format.as_ref().to_uppercase().as_ref() {
6870
"JSON" => {
6971
let (tasks, tasks_layer) = TasksLayer::<format::JsonFields>::new();
@@ -72,7 +74,7 @@ pub fn with_filter_and_format(
7274
.with(tasks_layer)
7375
.with(
7476
tracing_subscriber::fmt::layer()
75-
.with_timer(Uptime { start_time })
77+
.event_format(formatter)
7678
.json()
7779
.with_span_list(true),
7880
)
@@ -86,7 +88,7 @@ pub fn with_filter_and_format(
8688
let (filter, level) = tracing_subscriber::reload::Layer::new(filter);
8789
let dispatch = tracing_subscriber::registry()
8890
.with(tasks_layer)
89-
.with(tracing_subscriber::fmt::layer().with_timer(Uptime { start_time }))
91+
.with(tracing_subscriber::fmt::layer().event_format(formatter))
9092
.with(filter)
9193
.into();
9294
let handle = LevelHandle::Plain(level);

linkerd/app/integration/src/proxy.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ async fn run(proxy: Proxy, mut env: TestEnv, random_ports: bool) -> Listening {
310310
let span = info_span!("proxy", test = %thread_name());
311311
let _enter = span.enter();
312312

313-
tokio::runtime::Runtime::new()
313+
tokio::runtime::Builder::new()
314+
.enable_all()
315+
.basic_scheduler()
316+
.build()
314317
.expect("proxy")
315318
.block_on(async move {
316319
let main = config.build(trace_handle).await.expect("config");

0 commit comments

Comments
 (0)