Skip to content

Commit 4afc592

Browse files
committed
Added test
1 parent 6d582af commit 4afc592

File tree

1 file changed

+8
-61
lines changed

1 file changed

+8
-61
lines changed

tests/integ_tests/metrics_tests.rs

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -818,39 +818,6 @@ async fn evict_on_complete_does_not_count_as_forced_eviction() {
818818
assert!(!body.contains("temporal_sticky_cache_total_forced_eviction"));
819819
}
820820

821-
#[tokio::test]
822-
async fn test_otel_errors_are_logged_as_errors() {
823-
// Create a subscriber that captures logs
824-
let collector = tracing_subscriber::fmt()
825-
.with_max_level(tracing::Level::ERROR)
826-
.with_test_writer()
827-
.finish();
828-
829-
// Set this subscriber as default
830-
let _guard = tracing::subscriber::set_default(collector);
831-
832-
let opts = OtelCollectorOptionsBuilder::default()
833-
// Intentionally invalid endpoint
834-
.url("http://localhost:9999/v1/metrics".parse().unwrap())
835-
// .protocol(OtlpProtocol::Http)
836-
.build()
837-
.unwrap();
838-
839-
// This exporter will fail every time it tries to export metrics
840-
let exporter = build_otlp_metric_exporter(opts).unwrap();
841-
842-
}
843-
844-
// use std::sync::{Arc, Mutex};
845-
// use std::time::Duration;
846-
// use temporal_sdk_core::{
847-
// CoreRuntime, TelemetryOptionsBuilder, telemetry::{build_otlp_metric_exporter, OtlpProtocol, OtelCollectorOptionsBuilder, CoreMeter},
848-
// };
849-
// use tracing_subscriber::fmt::MakeWriter;
850-
// use tracing::Level;
851-
// use tokio::time::sleep;
852-
853-
// A writer that captures logs into a buffer so we can assert on them.
854821
struct CapturingWriter {
855822
buf: Arc<Mutex<Vec<u8>>>,
856823
}
@@ -876,22 +843,18 @@ impl std::io::Write for CapturingHandle {
876843
}
877844
}
878845

879-
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
880-
async fn test_otel_error_logged() {
846+
#[tokio::test]
847+
async fn otel_errors_logged_as_errors() {
881848
// Set up tracing subscriber to capture ERROR logs
882849
let logs = Arc::new(Mutex::new(Vec::new()));
883850
let writer = CapturingWriter { buf: logs.clone() };
884-
885851
let subscriber = tracing_subscriber::fmt()
886-
.with_max_level(tracing::Level::TRACE)
887852
.with_writer(writer)
888853
.finish();
889854
let _guard = tracing::subscriber::set_default(subscriber);
890855

891-
// Configure OTLP exporter with an invalid endpoint so it fails
892856
let opts = OtelCollectorOptionsBuilder::default()
893-
.url("http://localhost:9999/v1/metrics".parse().unwrap()) // Invalid endpoint
894-
// .protocol(OtlpProtocol::Http)
857+
.url("https://localhostt:9995/v1/metrics".parse().unwrap()) // Invalid endpoint
895858
.build()
896859
.unwrap();
897860
let exporter = build_otlp_metric_exporter(opts).unwrap();
@@ -902,38 +865,22 @@ async fn test_otel_error_logged() {
902865
.unwrap();
903866

904867
let rt = CoreRuntime::new_assume_tokio(telemopts).unwrap();
868+
let mut starter = CoreWfStarter::new_with_runtime("otel_errors_logged_as_errors", rt);
869+
let _worker = starter.get_worker().await;
905870

906-
let opts = get_integ_server_options();
907-
let mut raw_client = opts
908-
.connect_no_namespace(rt.telemetry().get_temporal_metric_meter())
909-
.await
910-
.unwrap();
911-
assert!(raw_client.get_client().capabilities().is_some());
912-
913-
let _ = raw_client
914-
.list_namespaces(ListNamespacesRequest::default())
915-
.await
916-
.unwrap();
917-
918-
// Trigger metric emission or just wait for exporter attempts
919-
// If you have a Temporal client to generate metrics, you can do so here.
920-
// For now, just wait to allow exporter to attempt sending metrics and fail.
921-
tokio::time::sleep(Duration::from_secs(5)).await;
922-
871+
// Wait to allow exporter to attempt sending metrics and fail.
872+
tokio::time::sleep(Duration::from_secs(2)).await;
923873

924-
// Check the captured logs
925874
let logs = logs.lock().unwrap();
926875
let log_str = String::from_utf8_lossy(&logs);
927876

928-
// Assert that there is an error log
929877
assert!(
930878
log_str.contains("ERROR"),
931879
"Expected ERROR log not found in logs: {}",
932880
log_str
933881
);
934-
// Look for some substring that indicates OTLP export failed
935882
assert!(
936-
log_str.contains("failed") || log_str.contains("error"),
883+
log_str.contains("Metrics exporter otlp failed with the grpc server returns error"),
937884
"Expected an OTel exporter error message in logs: {}",
938885
log_str
939886
);

0 commit comments

Comments
 (0)