Skip to content

: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.

fix(doit): retry Cloudflare transient 5xx (524) at the HTTP layer (#64654)

Tom Owers1f84209fe06c
diff --git a/posthog/temporal/data_imports/sources/doit/doit.py b/posthog/temporal/data_imports/sources/doit/doit.py
index d73f5cf7ce94..c4844f2119e3 100644
--- a/posthog/temporal/data_imports/sources/doit/doit.py
+++ b/posthog/temporal/data_imports/sources/doit/doit.py
@@ -10,11 +10,17 @@ from structlog.types import FilteringBoundLogger
from posthog.temporal.data_imports.naming_convention import NamingConvention
from posthog.temporal.data_imports.pipelines.pipeline.typings import SourceResponse
from posthog.temporal.data_imports.pipelines.pipeline.utils import table_from_iterator
-from posthog.temporal.data_imports.sources.common.http import make_tracked_session
+from posthog.temporal.data_imports.sources.common.http import DEFAULT_RETRY, make_tracked_session
from posthog.temporal.data_imports.sources.generated_configs import DoItSourceConfig
from products.data_warehouse.backend.types import IncrementalField, IncrementalFieldType
+# DoIt's API sits behind Cloudflare, which returns 52x origin errors (e.g. 524 when the origin
+# times out under load or during maintenance) instead of the standard 502/503/504. These are
+# transient like the gateway errors the default policy already retries, so add the Cloudflare
+# origin family to the forcelist and let the HTTP layer retry them with backoff.
+DOIT_RETRY = DEFAULT_RETRY.new(status_forcelist=(*(DEFAULT_RETRY.status_forcelist or ()), 520, 521, 522, 523, 524))
+
DOIT_INCREMENTAL_FIELDS: list[IncrementalField] = [
{
"field": "timestamp",
@@ -55,7 +61,7 @@ def doit_list_reports(config: DoItSourceConfig, logger: Optional[FilteringBoundL
if logger is None:
logger = structlog.get_logger(__name__)
- res = make_tracked_session().get(
+ res = make_tracked_session(retry=DOIT_RETRY).get(
"https://api.doit.com/analytics/v1/reports",
headers={"Authorization": f"Bearer {config.api_key}"},
)
@@ -139,7 +145,7 @@ def doit_source(
logger.debug(f"Requesting DoIt url: {request_uri}")
- res = make_tracked_session().get(
+ res = make_tracked_session(retry=DOIT_RETRY).get(
request_uri,
headers={"Authorization": f"Bearer {config.api_key}"},
)
diff --git a/posthog/temporal/data_imports/sources/doit/tests/test_doit_source.py b/posthog/temporal/data_imports/sources/doit/tests/test_doit_source.py
index fa3a0314e254..015df1493330 100644
--- a/posthog/temporal/data_imports/sources/doit/tests/test_doit_source.py
+++ b/posthog/temporal/data_imports/sources/doit/tests/test_doit_source.py
@@ -1,5 +1,7 @@
import pytest
+from posthog.temporal.data_imports.sources.common.http import DEFAULT_RETRY
+from posthog.temporal.data_imports.sources.doit.doit import DOIT_RETRY
from posthog.temporal.data_imports.sources.doit.source import DoItSource
from products.data_warehouse.backend.types import ExternalDataSourceType
@@ -17,3 +19,10 @@ class TestDoItSource:
errors = self.source.get_non_retryable_errors()
assert pattern in errors
+
+ @pytest.mark.parametrize("status_code", [520, 521, 522, 523, 524])
+ def test_doit_retry_includes_cloudflare_transient_statuses(self, status_code):
+ assert status_code in (DOIT_RETRY.status_forcelist or ())
+
+ def test_doit_retry_preserves_default_statuses(self):
+ assert set(DEFAULT_RETRY.status_forcelist or ()).issubset(set(DOIT_RETRY.status_forcelist or ()))