From 4ce76dfdf3c32cbf44b62ab9676cc1c1c34450f9 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 24 Jan 2025 00:12:09 +0000 Subject: [PATCH 1/3] more tests --- .../tests/integration_test/tests/logs.rs | 155 ++++++++++++++++-- 1 file changed, 141 insertions(+), 14 deletions(-) diff --git a/opentelemetry-otlp/tests/integration_test/tests/logs.rs b/opentelemetry-otlp/tests/integration_test/tests/logs.rs index 169df71601..08e7fb7fae 100644 --- a/opentelemetry-otlp/tests/integration_test/tests/logs.rs +++ b/opentelemetry-otlp/tests/integration_test/tests/logs.rs @@ -46,20 +46,35 @@ fn init_logs(is_simple: bool) -> Result { Ok(logger_provider) } -async fn logs_tokio_helper(is_simple: bool) -> Result<()> { +async fn logs_tokio_helper(is_simple: bool, log_send_outside_rt: bool) -> Result<()> { use crate::{assert_logs_results_contains, init_logs}; test_utils::start_collector_container().await?; let logger_provider = init_logs(is_simple).unwrap(); let layer = OpenTelemetryTracingBridge::new(&logger_provider); - let subscriber = tracing_subscriber::registry().with(layer); + //let subscriber = tracing_subscriber::registry().with(layer); // generate a random uuid and store it to expected guid - let expected_uuid = Uuid::new_v4().to_string(); + let expected_uuid = std::sync::Arc::new(Uuid::new_v4().to_string()); { - let _guard = tracing::subscriber::set_default(subscriber); - info!(target: "my-target", uuid = expected_uuid, "hello from {}. My price is {}.", "banana", 2.99); + let clone_uuid = expected_uuid.clone(); + if log_send_outside_rt { + std::thread::spawn( move || { + let subscriber = tracing_subscriber::registry().with(layer); + let _guard = tracing::subscriber::set_default(subscriber); + info!( + target: "my-target", + uuid = clone_uuid.as_str(), + "hello from {}. My price is {}.", + "banana", + 2.99 + ); + }).join().unwrap(); + } else { + let subscriber = tracing_subscriber::registry().with(layer); + let _guard = tracing::subscriber::set_default(subscriber); + info!(target: "my-target", uuid = expected_uuid.as_str(), "hello from {}. My price is {}.", "banana", 2.99); + } } - let _ = logger_provider.shutdown(); tokio::time::sleep(Duration::from_secs(5)).await; assert_logs_results_contains(test_utils::LOGS_FILE, expected_uuid.as_str())?; @@ -110,6 +125,7 @@ fn assert_logs_results_contains(result: &str, expected_content: &str) -> Result< let mut contents = String::new(); let mut reader = std::io::BufReader::new(&file); reader.read_to_string(&mut contents)?; + println!("---->>>> Contents: {}", contents); assert!(contents.contains(expected_content)); Ok(()) } @@ -152,50 +168,151 @@ mod logtests { // Batch Processor + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest-blocking + // Worker threads - 4 #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] pub async fn logs_batch_tokio_multi_thread() -> Result<()> { - logs_tokio_helper(false).await + logs_tokio_helper(false, false).await } + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest-blocking + // Worker threads - 1 #[tokio::test(flavor = "multi_thread", worker_threads = 1)] #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] pub async fn logs_batch_tokio_multi_with_one_worker() -> Result<()> { - logs_tokio_helper(false).await + logs_tokio_helper(false, false).await } + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest-blocking + // current thread #[tokio::test(flavor = "current_thread")] #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] pub async fn logs_batch_tokio_current() -> Result<()> { - logs_tokio_helper(false).await + logs_tokio_helper(false, false).await + } + + // logger initialization - Inside RT + // Log emission - Outside RT + // Client - Tonic, Reqwest-blocking + // Worker threads - 4 + #[tokio::test(flavor = "multi_thread", worker_threads = 4)] + #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] + pub async fn logs_batch_tokio_log_outside_rt_multi_thread() -> Result<()> { + logs_tokio_helper(false, true).await + } + + // logger initialization - Inside RT + // log emission - Outside RT + // Client - Tonic, Reqwest-blocking + // Worker threads - 1 + #[tokio::test(flavor = "multi_thread", worker_threads = 1)] + #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] + pub async fn logs_batch_tokio_log_outside_rt_multi_with_one_worker() -> Result<()> { + logs_tokio_helper(false, true).await + } + + // logger initialization - Inside RT + // log emission - Outside RT + // Client - Tonic, Reqwest-blocking + // current thread + #[tokio::test(flavor = "current_thread")] + #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] + pub async fn logs_batch_tokio_log_outside_rt_current_thread() -> Result<()> { + logs_tokio_helper(false, true).await } + // logger initialization - Inside RT + // Log emission - Inside RT + // Client - Tonic, Reqwest-blocking + // current thread #[test] #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] pub fn logs_batch_non_tokio_main_init_logs_inside_rt() -> Result<()> { logs_non_tokio_helper(false, true) } + // logger initialization - Outside RT + // log emission - Outside RT + // Client - Tonic, Reqwest-blocking + // current thread #[test] #[cfg(feature = "reqwest-blocking-client")] pub fn logs_batch_non_tokio_main_with_init_logs_outside_rt() -> Result<()> { logs_non_tokio_helper(false, false) } - // Simple Processor + // logger initialization - Inside RT + // log emission - Outside RT + // Client - Tonic, Reqwest-blocking + // current thread + #[test] + #[cfg(feature = "reqwest-blocking-client")] + pub fn logs_batch_non_tokio_main_with_init_logs_inside_rt() -> Result<()> { + logs_non_tokio_helper(false, true) + } + // **Simple Processor** + + // logger initialization - Inside RT + // log emission - Outside RT + // Client - Tonic, Reqwest-blocking #[test] #[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] pub fn logs_simple_non_tokio_main_with_init_logs_inside_rt() -> Result<()> { logs_non_tokio_helper(true, true) } + // logger initialization - Inside RT + // log emission - Outside RT + // Client - reqwest, hyper + #[ignore] // request and hyper client does not work without tokio runtime + #[test] + #[cfg(any(feature = "reqwest-client", feature = "hyper-client"))] + pub fn logs_simple_non_tokio_main_with_init_logs_inside_rt() -> Result<()> { + logs_non_tokio_helper(true, true) + } + + // logger initialization - Outside RT + // log emission - Outside RT + // Client - Reqwest-blocking #[test] - #[cfg(any(feature = "reqwest-blocking-client"))] + #[cfg(feature = "reqwest-blocking-client")] pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt() -> Result<()> { logs_non_tokio_helper(true, false) } + // logger initialization - Outside RT + // log emission - Outside RT + // Client - hyper, tonic, reqwest + #[ignore] // request, tonic and hyper client does not work without tokio runtime + #[test] + #[cfg(any(feature = "hyper-client", feature = "tonic-client", feature = "reqwest-client"))] + pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt() -> Result<()> { + logs_non_tokio_helper(true, false) + } + + // logger initialization - Inside RT + // log emission - Inside RT + // Client - reqwest-blocking + // Worker threads - 4 + #[ignore] // request-blocking client does not work with tokio + #[tokio::test(flavor = "multi_thread", worker_threads = 4)] + #[cfg(feature = "reqwest-blocking-client")] + pub async fn logs_simple_tokio_multi_thread() -> Result<()> { + logs_tokio_helper(true, false).await + } + + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest, hyper + // Worker threads - 4 #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[cfg(any( feature = "tonic-client", @@ -203,9 +320,13 @@ mod logtests { feature = "hyper-client" ))] pub async fn logs_simple_tokio_multi_thread() -> Result<()> { - logs_tokio_helper(true).await + logs_tokio_helper(true, false).await } + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest, hyper + // Worker threads - 1 #[tokio::test(flavor = "multi_thread", worker_threads = 1)] #[cfg(any( feature = "tonic-client", @@ -213,9 +334,13 @@ mod logtests { feature = "hyper-client" ))] pub async fn logs_simple_tokio_multi_with_one_worker() -> Result<()> { - logs_tokio_helper(true).await + logs_tokio_helper(true, false).await } + // logger initialization - Inside RT + // log emission - Inside RT + // Client - Tonic, Reqwest, hyper + // Current thread #[ignore] // https://github.com/open-telemetry/opentelemetry-rust/issues/2539 #[tokio::test(flavor = "current_thread")] #[cfg(any( @@ -224,8 +349,10 @@ mod logtests { feature = "hyper-client" ))] pub async fn logs_simple_tokio_current() -> Result<()> { - logs_tokio_helper(true).await + logs_tokio_helper(true, false).await } + + } /// /// Make sure we stop the collector container, otherwise it will sit around hogging our From 4032881e2ffb6748cc39d427666876b338e58705 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 24 Jan 2025 00:25:42 +0000 Subject: [PATCH 2/3] lint errors --- .../tests/integration_test/tests/logs.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/opentelemetry-otlp/tests/integration_test/tests/logs.rs b/opentelemetry-otlp/tests/integration_test/tests/logs.rs index 08e7fb7fae..7b71b879b3 100644 --- a/opentelemetry-otlp/tests/integration_test/tests/logs.rs +++ b/opentelemetry-otlp/tests/integration_test/tests/logs.rs @@ -58,7 +58,7 @@ async fn logs_tokio_helper(is_simple: bool, log_send_outside_rt: bool) -> Result { let clone_uuid = expected_uuid.clone(); if log_send_outside_rt { - std::thread::spawn( move || { + std::thread::spawn(move || { let subscriber = tracing_subscriber::registry().with(layer); let _guard = tracing::subscriber::set_default(subscriber); info!( @@ -68,7 +68,9 @@ async fn logs_tokio_helper(is_simple: bool, log_send_outside_rt: bool) -> Result "banana", 2.99 ); - }).join().unwrap(); + }) + .join() + .unwrap(); } else { let subscriber = tracing_subscriber::registry().with(layer); let _guard = tracing::subscriber::set_default(subscriber); @@ -293,7 +295,11 @@ mod logtests { // Client - hyper, tonic, reqwest #[ignore] // request, tonic and hyper client does not work without tokio runtime #[test] - #[cfg(any(feature = "hyper-client", feature = "tonic-client", feature = "reqwest-client"))] + #[cfg(any( + feature = "hyper-client", + feature = "tonic-client", + feature = "reqwest-client" + ))] pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt() -> Result<()> { logs_non_tokio_helper(true, false) } @@ -351,8 +357,6 @@ mod logtests { pub async fn logs_simple_tokio_current() -> Result<()> { logs_tokio_helper(true, false).await } - - } /// /// Make sure we stop the collector container, otherwise it will sit around hogging our From 05d11f70067e83b1bddf8ad1e3f531cb9597e9e7 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 23 Jan 2025 16:27:51 -0800 Subject: [PATCH 3/3] Remove commented code and debug print statement --- opentelemetry-otlp/tests/integration_test/tests/logs.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/opentelemetry-otlp/tests/integration_test/tests/logs.rs b/opentelemetry-otlp/tests/integration_test/tests/logs.rs index 7b71b879b3..26ad95c995 100644 --- a/opentelemetry-otlp/tests/integration_test/tests/logs.rs +++ b/opentelemetry-otlp/tests/integration_test/tests/logs.rs @@ -52,7 +52,6 @@ async fn logs_tokio_helper(is_simple: bool, log_send_outside_rt: bool) -> Result let logger_provider = init_logs(is_simple).unwrap(); let layer = OpenTelemetryTracingBridge::new(&logger_provider); - //let subscriber = tracing_subscriber::registry().with(layer); // generate a random uuid and store it to expected guid let expected_uuid = std::sync::Arc::new(Uuid::new_v4().to_string()); { @@ -127,7 +126,6 @@ fn assert_logs_results_contains(result: &str, expected_content: &str) -> Result< let mut contents = String::new(); let mut reader = std::io::BufReader::new(&file); reader.read_to_string(&mut contents)?; - println!("---->>>> Contents: {}", contents); assert!(contents.contains(expected_content)); Ok(()) }