: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
feat(infra): granian streaming entrypoint and a streaming readiness role (#67969)
Fernando Gomesc06acdf8c194
diff --git a/posthog/health.py b/posthog/health.pyindex 4568dddf1990..1c741b709522 100644--- a/posthog/health.py+++ b/posthog/health.py@@ -39,7 +39,7 @@ from posthog.security.outbound_proxy import internal_requestslogger = get_logger(__name__)-ServiceRole = Literal["events", "web", "worker", "decide", "query", "report", "conversations"]+ServiceRole = Literal["events", "web", "worker", "decide", "query", "report", "conversations", "streaming"]service_dependencies: dict[ServiceRole, list[str]] = {"events": ["http"],@@ -73,6 +73,11 @@ service_dependencies: dict[ServiceRole, list[str]] = {"query": ["http", "postgres", "cache"],"report": ["http"],"conversations": ["http", "postgres", "cache"],+ # The dedicated SSE tier: streams are Redis-only after their initial read+ # (sse_streaming_response releases DB connections before streaming), so its+ # readiness must NOT couple to Postgres — the tier has to keep serving open+ # streams even while the database is saturated.+ "streaming": ["http", "cache"],}# if atleast one of the checks is True, then the service is considered healthydiff --git a/posthog/test/test_health.py b/posthog/test/test_health.pyindex 7262db3c6243..7a53b6262029 100644--- a/posthog/test/test_health.py+++ b/posthog/test/test_health.py@@ -169,6 +169,28 @@ def test_readyz_accepts_role_worker_and_filters_by_relevant_services(client: Cliassert resp.status_code == 200, resp.content+def test_readyz_accepts_role_streaming_and_stays_ready_without_postgres(client: Client):+ # The streaming tier serves Redis-backed SSE only; coupling its readiness to+ # Postgres would pull healthy stream-serving pods out of the load balancer+ # exactly when the database is saturated.+ with simulate_postgres_error():+ resp = get_readyz(client=client, role="streaming")++ assert resp.status_code == 200, resp.content++ with simulate_clickhouse_cannot_connect(), simulate_celery_cannot_connect():+ resp = get_readyz(client=client, role="streaming")++ assert resp.status_code == 200, resp.content++ with simulate_cache_cannot_connect():+ resp = get_readyz(client=client, role="streaming")++ # Redis is the one hard dependency: streams are fed from it.+ assert resp.status_code == 503, resp.content++@pytest.mark.django_dbdef test_readyz_accepts_no_role_and_fails_on_everything(client: Client):"""