:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-imports): stop reporting queue DB DNS blips to error tracking (#79271)
Tom Owers43dec8177cdf
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.pyindex 5bfd8105ff30..4cc893a7b47b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/batch_consumer.py@@ -58,6 +58,19 @@ POLL_BACKOFF_MAX_DOUBLINGS = 32BATCHES_PER_GROUP_FETCH_FACTOR = 3+# EAI_AGAIN ("Temporary failure in name resolution") means the resolver itself is+# briefly unavailable, not that the queue DB's hostname is invalid — the next+# connection attempt succeeds once resolution recovers. Self-healing, like the+# queue DB's own startup/failover connection refusals, so it shouldn't page anyone.+_DNS_RESOLUTION_TRANSIENT_MARKER = "temporary failure in name resolution"+++def _is_dns_resolution_transient_error(error: BaseException) -> bool:+ if not isinstance(error, psycopg.OperationalError):+ return False+ return _DNS_RESOLUTION_TRANSIENT_MARKER in str(error).lower()++class OwnershipLostError(Exception):"""Raised when the group lease for a (team_id, schema_id) is no longer held by this consumer."""@@ -438,8 +451,11 @@ class BatchConsumer:# path above, not a real queue-DB outage.await self._handle_poll_timeout(poll_start)continue- logger.exception(self._event("poll_failed_queue_db_unreachable"))- capture_exception(e)+ if _is_dns_resolution_transient_error(e):+ logger.warning(self._event("poll_failed_queue_db_dns_unavailable"), error=str(e))+ else:+ logger.exception(self._event("poll_failed_queue_db_unreachable"))+ capture_exception(e)self._note_poll_failure("db_unreachable", duration=time.monotonic() - poll_start)await self._wait_or_shutdown(self._poll_retry_delay())continue@@ -1029,6 +1045,12 @@ class BatchConsumer:try:await self._recovery_sweep_with_timeout()+ except psycopg.OperationalError as e:+ if _is_dns_resolution_transient_error(e):+ logger.warning(self._event("recovery_sweep_dns_unavailable"), error=str(e))+ else:+ logger.exception(self._event("recovery_sweep_error"))+ capture_exception(e)except Exception as e:logger.exception(self._event("recovery_sweep_error"))capture_exception(e)@@ -1045,6 +1067,12 @@ class BatchConsumer:timeout_seconds=self._config.sweep_timeout_seconds,)await self._drop_conn("_recovery_conn")+ except psycopg.OperationalError as e:+ if _is_dns_resolution_transient_error(e):+ logger.warning(self._event("reconcile_sweep_dns_unavailable"), error=str(e))+ else:+ logger.exception(self._event("reconcile_sweep_error"))+ capture_exception(e)except Exception as e:logger.exception(self._event("reconcile_sweep_error"))capture_exception(e)diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.pyindex 16d4502af999..1262c8ef4c2b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py@@ -15,6 +15,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline)from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.batch_consumer import (OwnershipLostError,+ _is_dns_resolution_transient_error,)from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.load.health import HealthStatefrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.postgres_queue.consumer import (@@ -587,6 +588,52 @@ class TestRecoverySweep:)+class TestDnsResolutionTransientErrorClassification:+ @pytest.mark.parametrize(+ "message, expected",+ [+ ("[Errno -3] Temporary failure in name resolution", True),+ ("TEMPORARY FAILURE IN NAME RESOLUTION", True), # case-insensitive+ ("could not translate host name", False),+ ("connection to server was lost during table metadata discovery", False),+ ],+ )+ def test_classifies_operational_errors(self, message: str, expected: bool) -> None:+ assert _is_dns_resolution_transient_error(psycopg.OperationalError(message)) is expected++ def test_ignores_non_operational_errors(self) -> None:+ # The DNS resolver's EAI_AGAIN only ever surfaces via psycopg.OperationalError;+ # a generic exception carrying the same text must not be misclassified.+ assert _is_dns_resolution_transient_error(RuntimeError("Temporary failure in name resolution")) is False++ @pytest.mark.asyncio+ async def test_recovery_loop_does_not_report_dns_resolution_error(self):+ # Reproduces the reported issue: a resolver hiccup while reconnecting to the queue+ # DB during the periodic recovery sweep must be treated as self-healing (logged,+ # not sent to error tracking) since the sweep already retries every interval.+ consumer = _make_consumer(recovery_interval_seconds=0.01)+ swept = asyncio.Event()++ async def raise_dns_error(*args: Any, **kwargs: Any) -> list[PendingBatch]:+ swept.set()+ raise psycopg.OperationalError("[Errno -3] Temporary failure in name resolution")++ with (+ patch(+ "products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.postgres_queue.consumer.BatchQueue.get_stale_executing",+ side_effect=raise_dns_error,+ ),+ patch.object(consumer, "_reconcile_failed_runs", new_callable=AsyncMock),+ patch(f"{batch_consumer_module.__name__}.capture_exception") as mock_capture,+ ):+ loop_task = asyncio.create_task(consumer._recovery_loop())+ await asyncio.wait_for(swept.wait(), timeout=2.0)+ consumer._shutdown.set()+ await asyncio.wait_for(loop_task, timeout=5.0)++ mock_capture.assert_not_called()++class TestStartupLiveness:@pytest.mark.asyncioasync def test_heartbeat_reports_liveness_while_startup_sweep_runs(self):