: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(batch-exports): use workflow time in monitoring (#76658)
Vasiliyc1bf40e5a57c
diff --git a/products/batch_exports/backend/temporal/monitoring.py b/products/batch_exports/backend/temporal/monitoring.pyindex e38d28080c2f..741e5b27c44a 100644--- a/products/batch_exports/backend/temporal/monitoring.py+++ b/products/batch_exports/backend/temporal/monitoring.py@@ -374,7 +374,7 @@ class BatchExportMonitoringWorkflow(PostHogWorkflow):# time interval to check is not the previous hour but the hour before that# (just to ensure all recent batch exports have run successfully)- now = dt.datetime.now(tz=dt.UTC)+ now = workflow.now()interval_end = now.replace(minute=0, second=0, microsecond=0) - dt.timedelta(hours=1)interval_start = interval_end - dt.timedelta(hours=1)interval_end_str = datetime_to_str(interval_end)diff --git a/products/batch_exports/backend/tests/temporal/test_monitoring.py b/products/batch_exports/backend/tests/temporal/test_monitoring.pyindex d45a66f030f0..52f78d29eab1 100644--- a/products/batch_exports/backend/tests/temporal/test_monitoring.py+++ b/products/batch_exports/backend/tests/temporal/test_monitoring.py@@ -2,7 +2,6 @@ import uuidimport datetime as dtimport pytest-from freezegun import freeze_timefrom unittest.mock import MagicMock, patchfrom django.conf import settings@@ -132,29 +131,30 @@ async def generate_batch_export_runs(async def _run_workflow(batch_export):workflow_id = str(uuid.uuid4())inputs = BatchExportMonitoringInputs(batch_export_id=batch_export.id)- async with await WorkflowEnvironment.start_time_skipping() as activity_environment:- async with Worker(- activity_environment.client,- task_queue=settings.BATCH_EXPORTS_TASK_QUEUE,- workflows=[BatchExportMonitoringWorkflow],- activities=[- get_batch_export,- get_clickhouse_event_counts,- fetch_exported_event_counts,- update_batch_export_runs,- reconcile_event_counts,- ],- workflow_runner=UnsandboxedWorkflowRunner(),- ):- batch_export_runs_updated = await activity_environment.client.execute_workflow(- BatchExportMonitoringWorkflow.run,- inputs,- id=workflow_id,+ with patch("products.batch_exports.backend.temporal.monitoring.workflow.now", return_value=NOW):+ async with await WorkflowEnvironment.start_time_skipping() as activity_environment:+ async with Worker(+ activity_environment.client,task_queue=settings.BATCH_EXPORTS_TASK_QUEUE,- retry_policy=RetryPolicy(maximum_attempts=1),- execution_timeout=dt.timedelta(seconds=30),- )- return batch_export_runs_updated+ workflows=[BatchExportMonitoringWorkflow],+ activities=[+ get_batch_export,+ get_clickhouse_event_counts,+ fetch_exported_event_counts,+ update_batch_export_runs,+ reconcile_event_counts,+ ],+ workflow_runner=UnsandboxedWorkflowRunner(),+ ):+ batch_export_runs_updated = await activity_environment.client.execute_workflow(+ BatchExportMonitoringWorkflow.run,+ inputs,+ id=workflow_id,+ task_queue=settings.BATCH_EXPORTS_TASK_QUEUE,+ retry_policy=RetryPolicy(maximum_attempts=1),+ execution_timeout=dt.timedelta(seconds=30),+ )+ return batch_export_runs_updatedasync def test_monitoring_workflow_when_no_event_data(batch_export):@@ -177,7 +177,6 @@ async def test_monitoring_workflow_when_no_event_data(batch_export):["every 5 minutes"],indirect=True,)-@freeze_time(NOW)async def test_monitoring_workflow_no_issues(batch_export,generate_test_data,@@ -234,7 +233,6 @@ async def test_monitoring_workflow_no_issues(["every 5 minutes"],indirect=True,)-@freeze_time(NOW)async def test_monitoring_workflow_when_missing_batch_export_runs(batch_export,generate_test_data,@@ -296,7 +294,6 @@ async def test_monitoring_workflow_when_missing_batch_export_runs(["every 5 minutes"],indirect=True,)-@freeze_time(NOW)async def test_monitoring_workflow_when_missing_events(batch_export,generate_test_data,