: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(custom): clean up probe timeout and connection error messages (#67677)
Tom Owers975e0ee7d5a6
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.pyindex af87efa60721..5e6bf4c052e9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py@@ -12,7 +12,7 @@ from django.db import IntegrityErrorimport structlogfrom jsonpath_ng.exceptions import JSONPathErrorfrom pydantic import BaseModel, ConfigDict, Field, ValidationError, model_validator-from requests import PreparedRequest, Response+from requests import PreparedRequest, Response, Timeoutfrom urllib3.util.retry import Retryfrom posthog.schema import (@@ -931,8 +931,19 @@ class CustomSource(SimpleSource[CustomSourceConfig]):timeout=(PROBE_CONNECT_TIMEOUT, PROBE_READ_TIMEOUT),stream=True,)- except Exception as exc:- return False, f"Resource {resource['name']!r}: could not reach {url}: {exc}"+ except Timeout:+ # str(exc) here is the raw urllib3 "HTTPSConnectionPool(...): Read timed out" dump,+ # which isn't actionable — surface the configured timeouts instead.+ return False, (+ f"Resource {resource['name']!r}: timed out reaching {url} "+ f"(connect timeout {PROBE_CONNECT_TIMEOUT}s, read timeout {PROBE_READ_TIMEOUT}s). "+ "The endpoint may be slow or temporarily unreachable — check the URL and try again."+ )+ except Exception:+ return False, (+ f"Resource {resource['name']!r}: could not reach {url}. "+ "Check that the URL is correct and the endpoint is reachable."+ )# Only an auth rejection (401/403) is a credential problem. Other# statuses — 404 (resource not yet provisioned), 405, 429 (ratediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.pyindex 2300b031f7b1..3188ab752773 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py@@ -1388,18 +1388,32 @@ class TestCustomSourceValidateCredentials(SimpleTestCase):assert mock_session.call_args.kwargs["redact_values"] == ("sk_live_leaky",)+ @parameterized.expand(+ [+ # A connection-level failure surfaces a clean "could not reach" message.+ ("connection", requests.exceptions.ConnectionError("boom at 10.0.0.1"), "could not reach", "boom"),+ # A read timeout surfaces the configured timeouts, not the raw urllib3 dump.+ (+ "timeout",+ requests.Timeout("HTTPSConnectionPool(host='x'): Read timed out. (read timeout=10)"),+ "timed out",+ "HTTPSConnectionPool",+ ),+ ]+ )@patch("products.warehouse_sources.backend.temporal.data_imports.sources.custom.source.make_tracked_session")- def test_returns_false_on_network_error(self, mock_session):- # A connection-level failure (DNS, TLS, timeout) must surface as a- # credential validation error pointing at the offending resource.- mock_session.return_value.request.side_effect = ConnectionError("boom")+ def test_returns_false_on_network_error(self, _name, side_effect, expected_fragment, leaked_text, mock_session):+ # A connection-level failure (DNS, TLS, timeout) must surface as a credential validation+ # error pointing at the offending resource, without leaking the raw requests exception.+ mock_session.return_value.request.side_effect = side_effectsource = CustomSource()config = CustomSourceConfig(manifest_json=json.dumps(_minimal_manifest()), auth_token="abc")ok, err = source.validate_credentials(config, team_id=999)assert not ok- assert "could not reach" in (err or "")+ assert expected_fragment in (err or "")assert "users" in (err or "")+ assert leaked_text not in (err or "")def test_returns_false_on_invalid_manifest(self):source = CustomSource()