Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the multi_thread executor to run the telemetry hang test #922

Merged
merged 2 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions apollo-router/src/plugins/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,13 @@ impl Drop for Telemetry {
// Tracer providers must be flushed. This may happen as part of otel if the provider was set
// as the global, but may also happen in the case of an failed config reload.
// If the tracer prover is present then it was not handed over so we must flush it.
// The magic incantation seems to be that the flush MUST happen in a separate thread.
// We must make the call to force_flush() from spawn_blocking() (or spawn a thread) to
// ensure that the call to force_flush() is made from a separate thread.
::tracing::debug!("flushing telemetry");
std::thread::spawn(|| async {
let jh = tokio::task::spawn_blocking(move || {
opentelemetry::trace::TracerProvider::force_flush(&tracer_provider);
});
futures::executor::block_on(jh).expect("failed to flush tracer provider");
let jh = tokio::task::spawn_blocking(move || {
opentelemetry::trace::TracerProvider::force_flush(&tracer_provider);
});
futures::executor::block_on(jh).expect("failed to flush tracer provider");
}

if let Some(sender) = self.spaceport_shutdown.take() {
Expand Down
4 changes: 3 additions & 1 deletion apollo-router/src/router_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ mod test {
assert!(service.is_err())
}

#[tokio::test]
// This test must use the multi_thread tokio executor or the opentelemetry hang bug will
// be encountered. (See https://github.com/open-telemetry/opentelemetry-rust/issues/536)
#[tokio::test(flavor = "multi_thread")]
async fn test_telemetry_doesnt_hang_with_invalid_schema() {
use crate::subscriber::{set_global_subscriber, RouterSubscriber};
use tracing_subscriber::EnvFilter;
Expand Down