: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(experiments): route metrics recalculation to its own temporal queue (#67257)
Rodrigo Iloro4c53c9040efb
diff --git a/posthog/management/commands/start_temporal_worker.py b/posthog/management/commands/start_temporal_worker.pyindex f9a00240c470..f7661914ecd4 100644--- a/posthog/management/commands/start_temporal_worker.py+++ b/posthog/management/commands/start_temporal_worker.py@@ -268,7 +268,6 @@ _task_queue_specs = [+ DLQ_REPLAY_WORKFLOWS+ SYNC_PERSON_DISTINCT_IDS_WORKFLOWS+ EXPERIMENTS_WORKFLOWS- + EXPERIMENTS_RECALCULATION_WORKFLOWS+ CLEANUP_PROPDEFS_WORKFLOWS+ BACKFILL_GROUP_TYPE_CREATED_AT_WORKFLOWS+ INGESTION_ACCEPTANCE_TEST_WORKFLOWS@@ -285,7 +284,6 @@ _task_queue_specs = [+ DLQ_REPLAY_ACTIVITIES+ SYNC_PERSON_DISTINCT_IDS_ACTIVITIES+ EXPERIMENTS_ACTIVITIES- + EXPERIMENTS_RECALCULATION_ACTIVITIES+ CLEANUP_PROPDEFS_ACTIVITIES+ BACKFILL_GROUP_TYPE_CREATED_AT_ACTIVITIES+ INGESTION_ACCEPTANCE_TEST_ACTIVITIES@@ -293,6 +291,11 @@ _task_queue_specs = [+ SYNC_EVENTS_RETENTION_ACTIVITIES+ JOB_LOGS_ACTIVITIES,),+ (+ settings.EXPERIMENTS_RECALCULATION_TASK_QUEUE,+ EXPERIMENTS_RECALCULATION_WORKFLOWS,+ EXPERIMENTS_RECALCULATION_ACTIVITIES,+ ),(settings.HEALTH_CHECK_TASK_QUEUE,HEALTH_CHECK_WORKFLOWS,diff --git a/posthog/settings/temporal.py b/posthog/settings/temporal.pyindex ac2465e0d556..5eaf54a136ef 100644--- a/posthog/settings/temporal.py+++ b/posthog/settings/temporal.py@@ -112,6 +112,7 @@ BATCH_EXPORTS_TASK_QUEUE = _set_temporal_task_queue("batch-exports-task-queue")DATA_MODELING_TASK_QUEUE = _set_temporal_task_queue("data-modeling-task-queue")SYNC_BATCH_EXPORTS_TASK_QUEUE = _set_temporal_task_queue("no-sandbox-python-django")GENERAL_PURPOSE_TASK_QUEUE = _set_temporal_task_queue("general-purpose-task-queue")+EXPERIMENTS_RECALCULATION_TASK_QUEUE = _set_temporal_task_queue("experiments-recalculation-task-queue")HEALTH_CHECK_TASK_QUEUE = _set_temporal_task_queue("health-check-task-queue")DUCKLAKE_TASK_QUEUE = _set_temporal_task_queue("ducklake-task-queue")TASKS_TASK_QUEUE = _set_temporal_task_queue("tasks-task-queue")diff --git a/products/experiments/backend/presentation/views.py b/products/experiments/backend/presentation/views.pyindex a3d50d80f1b3..a543704aa9a7 100644--- a/products/experiments/backend/presentation/views.py+++ b/products/experiments/backend/presentation/views.py@@ -983,7 +983,7 @@ class EnterpriseExperimentsViewSet("experiment-metrics-recalculation-workflow",MetricsRecalcInputs(recalculation_id=recalculation_id),id=f"experiment-metrics-recalculation-{recalculation_id}",- task_queue=settings.GENERAL_PURPOSE_TASK_QUEUE,+ task_queue=settings.EXPERIMENTS_RECALCULATION_TASK_QUEUE,))except Exception:diff --git a/products/experiments/backend/temporal/recalculation_metrics.py b/products/experiments/backend/temporal/recalculation_metrics.pyindex 85dfb08bbe33..55094759f710 100644--- a/products/experiments/backend/temporal/recalculation_metrics.py+++ b/products/experiments/backend/temporal/recalculation_metrics.py@@ -157,7 +157,7 @@ class ExperimentsRecalculationMetricsInterceptor(Interceptor):# Required by `is_task_queue_supported` in `posthog/temporal/common/interceptor.py` — without this attribute# the interceptor is filtered out of every worker and the metrics never emit. The recalc workflow + activities# are registered on this queue in `posthog/management/commands/start_temporal_worker.py`.- task_queue = settings.GENERAL_PURPOSE_TASK_QUEUE+ task_queue = settings.EXPERIMENTS_RECALCULATION_TASK_QUEUEdef intercept_activity(self, next: ActivityInboundInterceptor) -> ActivityInboundInterceptor:return _ActivityInboundInterceptor(super().intercept_activity(next))diff --git a/products/experiments/backend/temporal/recalculation_workflow.py b/products/experiments/backend/temporal/recalculation_workflow.pyindex 6a0a2d90f9a2..f617feb97d15 100644--- a/products/experiments/backend/temporal/recalculation_workflow.py+++ b/products/experiments/backend/temporal/recalculation_workflow.py@@ -24,10 +24,10 @@ with temporalio.workflow.unsafe.imports_passed_through():)from products.experiments.backend.temporal.recalculation_metrics import increment_workflow_finished-# Offline recalc shares the org's ClickHouse query budget (app:query:per-org, default 20,-# halved/quartered under cluster load) with the org's live queries. Cap at 4 so a single run-# stays under the budget even when it drops to 5, avoiding ClickHouseAtCapacity throttling.-MAX_CONCURRENT_METRICS = 4+# Per-run metric fan-out: how many metric activities one run keeps in flight, sized so a typical experiment+# recalculates in a single concurrent wave. Cross-run ClickHouse load is bounded separately by the dedicated+# recalc worker's activity-slot cap (MAX_CONCURRENT_ACTIVITIES), not by this constant.+MAX_CONCURRENT_METRICS = 14@temporalio.workflow.defn(name="experiment-metrics-recalculation-workflow")diff --git a/products/experiments/backend/temporal/test_recalculation_metrics.py b/products/experiments/backend/temporal/test_recalculation_metrics.pyindex c6d86481d4af..d3b5d124352f 100644--- a/products/experiments/backend/temporal/test_recalculation_metrics.py+++ b/products/experiments/backend/temporal/test_recalculation_metrics.py@@ -18,10 +18,12 @@ from products.experiments.backend.temporal.recalculation_metrics import ()-def test_registered_on_general_purpose_queue():- # Pins the interceptor's `task_queue` ClassVar — without it, `is_task_queue_supported` filters the- # interceptor out of every worker and the metrics emit nothing.- assert is_task_queue_supported(settings.GENERAL_PURPOSE_TASK_QUEUE, ExperimentsRecalculationMetricsInterceptor)+def test_registered_on_recalculation_queue():+ # Pins the interceptor's `task_queue` ClassVar to the recalc worker's queue — without a match,+ # `is_task_queue_supported` filters the interceptor out of every worker and the metrics emit nothing.+ assert is_task_queue_supported(+ settings.EXPERIMENTS_RECALCULATION_TASK_QUEUE, ExperimentsRecalculationMetricsInterceptor+ )def test_buckets_sorted_ascending_and_floats():