Skip to content

Commit 4522caa

Browse files
github-actions[bot]Abhishekmishra2808henry3260
authored andcommitted
[v3-1-test] Fix flaky OTel integration test with DNS health check (#61070) (#61242) (#61286)
* Fix flaky OTel integration test with DNS health check (#61070) * Update airflow-core/tests/integration/otel/test_otel.py --------- (cherry picked from commit 8ac25dd) Co-authored-by: Abhishek Mishra <mishra.abhishek2808@gmail.com> Co-authored-by: Henry Chen <henryhenry0512@gmail.com>
1 parent c7ea5ef commit 4522caa

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

airflow-core/tests/integration/otel/test_otel.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import logging
2121
import os
2222
import signal
23+
import socket
2324
import subprocess
2425
import time
2526

@@ -52,6 +53,44 @@
5253
log = logging.getLogger("integration.otel.test_otel")
5354

5455

56+
def wait_for_otel_collector(host: str, port: int, timeout: int = 120) -> None:
57+
"""
58+
Wait for the OTel collector to be reachable before running tests.
59+
60+
This prevents flaky test failures caused by transient DNS resolution issues
61+
(e.g., 'Temporary failure in name resolution' for breeze-otel-collector).
62+
63+
Note: If the collector is not reachable after timeout, logs a warning but
64+
does not fail - allows tests to run and fail naturally if needed.
65+
"""
66+
deadline = time.monotonic() + timeout
67+
last_error = None
68+
while time.monotonic() < deadline:
69+
try:
70+
# Test DNS resolution and TCP connectivity
71+
with socket.create_connection((host, port), timeout=5):
72+
pass
73+
log.info("OTel collector at %s:%d is reachable.", host, port)
74+
return
75+
except (socket.gaierror, TimeoutError, OSError) as e:
76+
last_error = e
77+
log.debug(
78+
"OTel collector at %s:%d not reachable: %s. Retrying...",
79+
host,
80+
port,
81+
e,
82+
)
83+
time.sleep(2)
84+
log.warning(
85+
"OTel collector at %s:%d is not reachable after %ds. Last error: %s. "
86+
"Tests will proceed but may fail if collector is required.",
87+
host,
88+
port,
89+
timeout,
90+
last_error,
91+
)
92+
93+
5594
def unpause_trigger_dag_and_get_run_id(dag_id: str) -> str:
5695
unpause_command = ["airflow", "dags", "unpause", dag_id]
5796

@@ -611,9 +650,17 @@ class TestOtelIntegration:
611650

612651
@classmethod
613652
def setup_class(cls):
653+
otel_host = "breeze-otel-collector"
654+
otel_port = 4318
655+
656+
# Wait for OTel collector to be reachable before running tests.
657+
# This prevents flaky test failures caused by transient DNS resolution issues
658+
# during scheduler handoff (see https://github.com/apache/airflow/issues/61070).
659+
wait_for_otel_collector(otel_host, otel_port)
660+
614661
os.environ["AIRFLOW__TRACES__OTEL_ON"] = "True"
615-
os.environ["AIRFLOW__TRACES__OTEL_HOST"] = "breeze-otel-collector"
616-
os.environ["AIRFLOW__TRACES__OTEL_PORT"] = "4318"
662+
os.environ["AIRFLOW__TRACES__OTEL_HOST"] = otel_host
663+
os.environ["AIRFLOW__TRACES__OTEL_PORT"] = str(otel_port)
617664
if cls.use_otel != "true":
618665
os.environ["AIRFLOW__TRACES__OTEL_DEBUGGING_ON"] = "True"
619666

0 commit comments

Comments
 (0)