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(data-warehouse): wait out the crisp rate limit instead of failing the sync (#117106)

Daniel RC7b4cb2fb8301
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/crisp/crisp.py b/products/warehouse_sources/backend/temporal/data_imports/sources/crisp/crisp.py
index 7ebca5e0cbcb..b9e7397b3109 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/crisp/crisp.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/crisp/crisp.py
@@ -98,6 +98,9 @@ def client_config(config: CrispSourceConfig, api_version: str) -> ClientConfig:
"allowed_hosts": [],
"allow_redirects": False,
"request_timeout": (10, 60),
+ # Crisp sends no Retry-After with a 429, and the default five tries end before its
+ # rate limit clears. Nine tries keep one request waiting inside the retry budget.
+ "max_retries": 9,
"retry_budget_seconds": 240,
"retry_after_max_seconds": 120,
}
@@ -177,8 +180,11 @@ def credential_resource(config: CrispSourceConfig, team_id: int, api_version: st
settings = ENDPOINTS[settings.fanout.parent_name]
endpoint = endpoint_config(settings, config.website_id)
endpoint["paginator"] = "single_page"
+ client = client_config(config, api_version)
+ # The probe runs inside a web request, so it keeps the default retries to answer before the gateway timeout.
+ client.pop("max_retries")
rest_config: RESTAPIConfig = {
- "client": client_config(config, api_version),
+ "client": client,
"resources": [{"name": "credential_probe", "endpoint": endpoint}],
}
return rest_api_resource(rest_config, team_id, "crisp_credential_probe", None)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/crisp/tests/test_crisp_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/crisp/tests/test_crisp_source.py
index 25d1db1b9b2c..d264ef0704ff 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/crisp/tests/test_crisp_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/crisp/tests/test_crisp_source.py
@@ -2,6 +2,7 @@ import pytest
from products.warehouse_sources.backend.temporal.data_imports.sources.common.testing import (
ScriptedResponse,
+ always,
scripted_network,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.crisp.source import CrispSource
@@ -43,6 +44,15 @@ def test_credential_probe_maps_workspace_and_table_errors(
assert request.headers["x-crisp-tier"] == "website"
+def test_credential_probe_does_not_wait_out_a_rate_limit_like_a_sync(config: CrispSourceConfig) -> None:
+ with scripted_network(
+ always(ScriptedResponse(status=429, json={"error": True, "reason": "rate_limited"}))
+ ) as network:
+ with pytest.raises(Exception):
+ CrispSource().validate_credentials(config, team_id=1)
+ assert len(network.requests_log) <= 5
+
+
@pytest.mark.parametrize(
("field", "value", "message"),
[