: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 paging on self-recovering quota exhaustion (#89604)
posthog[bot]1eb401af62cc
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.pyindex 540fe4d1271e..d2cca254f2cf 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py@@ -104,7 +104,9 @@ class GoogleSearchConsoleQuotaExceededError(Exception):Deliberately NOT matched by `get_non_retryable_errors` so Temporal retriesthe activity later (the resumable source picks up from the last saved date),- which is the right recovery for the longer 10-minute / daily load quotas.+ which is the right recovery for the longer 10-minute / daily load quotas. Its+ messages carry a `(retryable)` marker that `get_retryable_errors` matches, so+ the self-recovering failure is logged as a warning instead of tracked as noise."""@@ -410,7 +412,7 @@ def _query_search_analytics(if _is_daily_quota_error(response):raise GoogleSearchConsoleQuotaExceededError(- f"Search Analytics daily quota for '{site_url}' exhausted; retrying at the activity level"+ f"Search Analytics daily quota for '{site_url}' exhausted; retrying at the activity level (retryable)")# Quota (403 usageLimits / 429) and transient Google-side 5xx both clear on their own,@@ -426,7 +428,7 @@ def _query_search_analytics(# retries the activity (resuming from the last saved date).response.raise_for_status()raise GoogleSearchConsoleQuotaExceededError(- f"Search Analytics quota for '{site_url}' still exhausted after {QUOTA_MAX_RETRIES} retries"+ f"Search Analytics quota for '{site_url}' still exhausted after {QUOTA_MAX_RETRIES} retries (retryable)")wait = _quota_backoff_seconds(response, attempt)@@ -440,7 +442,7 @@ def _query_search_analytics(time.sleep(wait)# Unreachable: the loop either returns, raises for status, or raises the quota error.- raise GoogleSearchConsoleQuotaExceededError(f"Search Analytics quota for '{site_url}' exhausted")+ raise GoogleSearchConsoleQuotaExceededError(f"Search Analytics quota for '{site_url}' exhausted (retryable)")def _parse_api_datetime(value: Any) -> dt.datetime | None:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/source.pyindex 41eb04ef6696..1d951d825e9d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/source.py@@ -115,6 +115,14 @@ class GoogleSearchConsoleSource("invalid_grant": "Your Google Search Console connection has expired or been revoked. Please reconnect your account.",}+ def get_retryable_errors(self) -> set[str]:+ # `_query_search_analytics` already retries Search Analytics quota exhaustion in-line with+ # backoff; if it stays exhausted once those retries run out, the property's quota refills+ # over time and the resumable source picks up from the last saved date and row, so let+ # Temporal retry the activity without paging it as a bug. The three quota raise sites carry a+ # stable `(retryable)` marker, which does not collide with the 401/403 non-retryable keys.+ return {"(retryable)"}+def get_oauth_accounts(self, integration_id: int, team_id: int, search: str | None = None) -> list[IntegrationAccount]:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.pyindex f92b6c618494..f8cc2d71ca3d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console_source.py@@ -5,6 +5,7 @@ import requestsfrom posthog.schema import SourceFieldSelectConfig+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import error_message_matchesfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.googlesearchconsole import (GoogleSearchConsoleSourceConfig,)@@ -190,6 +191,22 @@ def test_missing_integration_is_non_retryable():assert any(key in error_message for key in non_retryable_errors)+ "error_message",+ [+ # The three `GoogleSearchConsoleQuotaExceededError` messages raised by `_query_search_analytics`+ # once its in-line quota retries run out. Each carries the `(retryable)` marker so the resumable+ # source resumes on the next Temporal retry instead of tracking the quota exhaustion as a bug.+ "Search Analytics daily quota for 'sc-domain:example.com' exhausted; retrying at the activity level (retryable)",+ "Search Analytics quota for 'sc-domain:example.com' still exhausted after 3 retries (retryable)",+ "Search Analytics quota for 'sc-domain:example.com' exhausted (retryable)",+ ],+)+def test_exhausted_quota_is_retryable(error_message):+ retryable_errors = GoogleSearchConsoleSource().get_retryable_errors()+ assert error_message_matches(error_message, retryable_errors)++@pytest.mark.parametrize("status_code,body,expected_substring",[