From fbcba3b003e88141b6185e67073a90da670411b7 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 18 Dec 2024 06:28:32 -0800 Subject: [PATCH] Enable metric integration test for req-blocking (#2445) --- .cspell.json | 1 + .../tests/integration_test/Cargo.toml | 4 ++-- .../tests/integration_test/README.md | 19 +++++++++++----- .../tests/integration_test/src/test_utils.rs | 22 ++++++++++++------- .../tests/integration_test/tests/metrics.rs | 10 ++++----- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/.cspell.json b/.cspell.json index e6935508b9..be8b4c0cda 100644 --- a/.cspell.json +++ b/.cspell.json @@ -61,6 +61,7 @@ "shoppingcart", "struct", "Tescher", + "testresults", "tracerprovider", "updown", "Zhongyang", diff --git a/opentelemetry-otlp/tests/integration_test/Cargo.toml b/opentelemetry-otlp/tests/integration_test/Cargo.toml index 0ce69526b1..60b4869f1e 100644 --- a/opentelemetry-otlp/tests/integration_test/Cargo.toml +++ b/opentelemetry-otlp/tests/integration_test/Cargo.toml @@ -15,7 +15,7 @@ testcontainers = { version = "0.23.1", features = ["http_wait"]} once_cell.workspace = true anyhow = "1.0.94" ctor = "0.2.9" -tracing-subscriber = "0.3.19" +tracing-subscriber = { workspace = true, features = ["env-filter","registry", "std", "fmt"] } tracing = "0.1.41" [target.'cfg(unix)'.dependencies] @@ -28,7 +28,7 @@ hyper-client = ["opentelemetry-otlp/hyper-client", "opentelemetry-otlp/http-prot reqwest-client = ["opentelemetry-otlp/reqwest-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"] reqwest-blocking-client = ["opentelemetry-otlp/reqwest-blocking-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"] tonic-client = ["opentelemetry-otlp/grpc-tonic", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"] -internal-logs = [] +internal-logs = ["opentelemetry-otlp/internal-logs"] # Keep tonic as the default client default = ["tonic-client", "internal-logs"] diff --git a/opentelemetry-otlp/tests/integration_test/README.md b/opentelemetry-otlp/tests/integration_test/README.md index 0b251732dc..10e34df6a3 100644 --- a/opentelemetry-otlp/tests/integration_test/README.md +++ b/opentelemetry-otlp/tests/integration_test/README.md @@ -1,10 +1,17 @@ # OTLP - Integration Tests -This directory contains integration tests for `opentelemetry-otlp`. It uses -[testcontainers](https://testcontainers.com/) to start an instance of the OTEL collector using [otel-collector-config.yaml](otel-collector-config.yaml), which then uses a file exporter per signal to write the output it receives back to the host machine. -The tests connect directly to the collector on `localhost:4317` and `localhost:4318`, push data through, and then check that what they expect -has popped back out into the files output by the collector. +This directory contains integration tests for `opentelemetry-otlp`. It uses +[testcontainers](https://testcontainers.com/) to start an instance of the OTEL +collector using [otel-collector-config.yaml](otel-collector-config.yaml), which +then uses a file exporter per signal to write the output it receives back to the +host machine. + +The tests connect directly to the collector on `localhost:4317` and +`localhost:4318`, push data through, and then check that what they expect has +popped back out into the files output by the collector. + +## Pre-requisites -For this to work, you need a couple of things: * Docker, for the test container -* TCP/4317 and TCP/4318 free on your local machine. If you are running another collector, you'll need to stop it for the tests to run \ No newline at end of file +* TCP/4317 and TCP/4318 free on your local machine. If you are running another + collector, you'll need to stop it for the tests to run. diff --git a/opentelemetry-otlp/tests/integration_test/src/test_utils.rs b/opentelemetry-otlp/tests/integration_test/src/test_utils.rs index f913029c00..bd62674868 100644 --- a/opentelemetry-otlp/tests/integration_test/src/test_utils.rs +++ b/opentelemetry-otlp/tests/integration_test/src/test_utils.rs @@ -27,7 +27,9 @@ use std::sync::{Arc, Mutex, Once, OnceLock}; use testcontainers::core::wait::HttpWaitStrategy; use testcontainers::core::{ContainerPort, Mount}; use testcontainers::{core::WaitFor, runners::AsyncRunner, ContainerAsync, GenericImage, ImageExt}; -use tracing_subscriber::FmtSubscriber; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::{EnvFilter, Layer}; // Static references for container management static COLLECTOR_ARC: OnceLock>>>> = OnceLock::new(); @@ -40,13 +42,17 @@ static INIT_TRACING: Once = Once::new(); fn init_tracing() { INIT_TRACING.call_once(|| { - let subscriber = FmtSubscriber::builder() - .with_max_level(tracing::Level::DEBUG) - .finish(); - - tracing::subscriber::set_global_default(subscriber) - .expect("Failed to set tracing subscriber"); - otel_info!(name: "init_tracing"); + // Info and above for all, debug for opentelemetry + let filter_fmt = + EnvFilter::new("info").add_directive("opentelemetry=debug".parse().unwrap()); + let fmt_layer = tracing_subscriber::fmt::layer() + .with_thread_names(true) + .with_filter(filter_fmt); + + // Initialize the tracing subscriber with the OpenTelemetry layer and the + // Fmt layer. + tracing_subscriber::registry().with(fmt_layer).init(); + otel_info!(name: "tracing initializing completed!"); }); } diff --git a/opentelemetry-otlp/tests/integration_test/tests/metrics.rs b/opentelemetry-otlp/tests/integration_test/tests/metrics.rs index b1b6a5ebdd..125c501e14 100644 --- a/opentelemetry-otlp/tests/integration_test/tests/metrics.rs +++ b/opentelemetry-otlp/tests/integration_test/tests/metrics.rs @@ -30,7 +30,7 @@ async fn init_metrics() -> SdkMeterProvider { let exporter = create_exporter(); let reader = PeriodicReader::builder(exporter) - .with_interval(Duration::from_millis(100)) + .with_interval(Duration::from_millis(500)) .with_timeout(Duration::from_secs(1)) .build(); @@ -146,7 +146,7 @@ async fn setup_metrics_test() -> Result<()> { println!("Running setup before any tests..."); *done = true; // Mark setup as done - // Initialise the metrics subsystem + // Initialize the metrics subsystem _ = init_metrics().await; } @@ -184,13 +184,13 @@ pub fn validate_metrics_against_results(scope_name: &str) -> Result<()> { } /// -/// TODO - the HTTP metrics exporters do not seem to flush at the moment. +/// TODO - the HTTP metrics exporters except reqwest-blocking-client do not seem +/// to work at the moment. /// TODO - fix this asynchronously. /// #[cfg(test)] #[cfg(not(feature = "hyper-client"))] #[cfg(not(feature = "reqwest-client"))] -#[cfg(not(feature = "reqwest-blocking-client"))] mod tests { use super::*; @@ -293,7 +293,7 @@ mod tests { // Set up the exporter let exporter = create_exporter(); let reader = PeriodicReader::builder(exporter) - .with_interval(Duration::from_millis(100)) + .with_interval(Duration::from_secs(30)) .with_timeout(Duration::from_secs(1)) .build(); let resource = Resource::builder_empty()