: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(warehouse): stop duckgres sink flooding error tracking on cp blips (#73995)
posthog[bot]8bba17965fe4
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/consumer.pyindex 24e875c19e99..a7260ece8870 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/consumer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/consumer.py@@ -13,6 +13,7 @@ import structlogfrom asgiref.sync import sync_to_asyncfrom prometheus_client import Gauge+from posthog.ducklake.team_state import CPUnavailableErrorfrom posthog.exceptions_capture import capture_exceptionfrom posthog.models import DuckgresSinkSchemaStatefrom posthog.sync import database_sync_to_async_pool@@ -177,13 +178,24 @@ class DuckgresBatchConsumerAdapter:team_count=None if self._team_ids is None else len(self._team_ids),org_count=len({org_id for _, org_id, _ in self._team_org_budgets}),)+ except CPUnavailableError:+ # A brief control-plane blip is expected and self-healing: we keep the+ # previously cached team set so the sink keeps serving. Log-only — this+ # is not an error-tracking-worthy failure. Advance the refresh clock on+ # the way out (below) so we don't re-poll the struggling control plane+ # every ~2s cycle across the fleet during an outage.+ logger.warning("duckgres_sink_enablement_control_plane_unreachable")+ if self._team_ids_fetched_at is None:+ # Never had a set: claim nothing rather than everything.+ self._team_ids = []+ self._team_ids_fetched_at = nowexcept Exception as e:logger.exception("duckgres_sink_enablement_refresh_failed")capture_exception(e)if self._team_ids_fetched_at is None:# Never had a set: claim nothing rather than everything.self._team_ids = []- self._team_ids_fetched_at = now+ self._team_ids_fetched_at = nowreturn self._team_idsasync def _run_maintenance(self, conn: psycopg.AsyncConnection[Any], team_ids: list[int] | None) -> None:diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.pyindex fa733fe1ad9a..65f797e3f0af 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.py@@ -21,6 +21,7 @@ import posthoganalyticsfrom posthog.ducklake import cp_teamsfrom posthog.ducklake.common import _get_org_id_for_team, is_dev_mode+from posthog.ducklake.team_state import CPUnavailableErrorfrom posthog.exceptions_capture import capture_exceptionlogger = structlog.get_logger(__name__)@@ -78,7 +79,7 @@ def duckgres_sink_enablement() -> SinkEnablement | None:rows = cp_teams.list_member_teams()if rows is None:- raise RuntimeError("duckgres control plane unreachable; keeping the previous sink enablement")+ raise CPUnavailableError("duckgres control plane unreachable; keeping the previous sink enablement")team_info = {team_id: (str(team_uuid), str(org_id))diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_consumer.pyindex 48c6fb0cc378..5fc5c8bf2c1a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_consumer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_consumer.py@@ -9,6 +9,7 @@ from unittest.mock import AsyncMock, MagicMock, patchimport psycopgfrom asgiref.sync import async_to_sync+from posthog.ducklake.team_state import CPUnavailableErrorfrom posthog.models import DuckgresSinkSchemaState, Organization, Teamfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.batch_consumer import (@@ -16,6 +17,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipelinePermanentBatchApplyError,)from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.duckgres.consumer import (+ ENABLEMENT_REFRESH_SECONDS,DuckgresBatchConsumer,DuckgresBatchConsumerAdapter,DuckgresConsumerConfig,@@ -244,6 +246,32 @@ class TestDuckgresEnablementGating:mock_wrapper.assert_called_once_with(duckgres_sink_enablement)+ @pytest.mark.asyncio+ async def test_control_plane_blip_keeps_cached_teams_without_capture_or_retry_storm(self):+ """A transient control-plane blip is expected and self-healing: keep the cached+ team set, don't report it to error tracking, and re-arm the refresh throttle so+ the next poll doesn't re-hit the struggling control plane every ~2s cycle."""+ adapter = DuckgresBatchConsumerAdapter()+ adapter._team_ids = [7, 8]+ # A timestamp older than the refresh window forces the refresh attempt below.+ adapter._team_ids_fetched_at = time.monotonic() - (ENABLEMENT_REFRESH_SECONDS + 1)++ with (+ patch(+ "products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.duckgres.consumer.database_sync_to_async_pool",+ ) as mock_wrapper,+ patch(+ "products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.duckgres.consumer.capture_exception",+ ) as mock_capture,+ ):+ mock_wrapper.return_value = AsyncMock(side_effect=CPUnavailableError("cp down"))+ team_ids = await adapter._enabled_team_ids()++ assert team_ids == [7, 8]+ mock_capture.assert_not_called()+ assert adapter._team_ids_fetched_at is not None+ assert time.monotonic() - adapter._team_ids_fetched_at < ENABLEMENT_REFRESH_SECONDS+@pytest.mark.asyncioasync def test_fetch_returns_empty_without_querying_when_no_teams_enabled(self):adapter = DuckgresBatchConsumerAdapter()