: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(alerts): evaluate 15-minute insight alerts on the platform in parallel (#114178)
Jimmy Zhuab39e51bff23
diff --git a/docs/internal/alerts-platform-temporal.md b/docs/internal/alerts-platform-temporal.mdindex ced9ee39876e..fc7eccaa0c93 100644--- a/docs/internal/alerts-platform-temporal.md+++ b/docs/internal/alerts-platform-temporal.md@@ -468,7 +468,7 @@ Insight alerts are copied the same way:python manage.py backfill_platform_insight_alert_configurations```-It copies threshold alerts on an hourly or slower cadence only, and skips detector alerts and the real-time and 15-minute cadences.+It copies threshold alerts on a 15-minute or slower cadence only, and skips detector alerts and the real-time cadence.Run it only after the evaluation worker's chart sets `CLICKHOUSE_ALERTS_PLATFORM_INSIGHT_USER` and its token file.Insight checks tag their queries with `ClickHouseUser.ALERTS_PLATFORM_INSIGHT`, a user of their own, so the parallel run never takes from the per-user budget of the user that production insight alerts query as.Without that env the tag resolves to the worker's default user, which other workloads on the same servers already push against its concurrent query limit.diff --git a/products/alerts/backend/platform_alert_backfill.py b/products/alerts/backend/platform_alert_backfill.pyindex f4c0bb3e3f53..0d288bb0046d 100644--- a/products/alerts/backend/platform_alert_backfill.py+++ b/products/alerts/backend/platform_alert_backfill.py@@ -22,9 +22,10 @@ from products.alerts_platform.backend.facade.enums import PlatformAlertConfiguralogger = structlog.get_logger(__name__)-# Minutes for the hourly cadence, a calendar unit for the rest. A calendar unit reads its cadence+# Minutes for the 15-minute and hourly cadences, a calendar unit for the rest. A calendar unit reads its cadence# from the unit, so its minutes only feed the shard offset, which an anchored unit ignores._RECURRENCE: dict[str, tuple[int, str | None]] = {+ AlertCalculationInterval.EVERY_15_MINUTES: (15, None),AlertCalculationInterval.HOURLY: (60, None),AlertCalculationInterval.DAILY: (60 * 24, RecurrenceUnit.DAY),AlertCalculationInterval.WEEKLY: (60 * 24 * 7, RecurrenceUnit.WEEK),diff --git a/products/alerts/backend/platform_source_cycle.py b/products/alerts/backend/platform_source_cycle.pyindex 7c7a18c3b421..5958981c573a 100644--- a/products/alerts/backend/platform_source_cycle.py+++ b/products/alerts/backend/platform_source_cycle.py@@ -75,10 +75,11 @@ QUERY_ID_PREFIX = "alerts-platform-insight:"# matches on it to set those checks aside.CAPACITY_REJECTED = "ClickHouse refused the query for capacity"-# Real-time and 15-minute alerts are the most expensive cadences and the ones production holds to a-# tighter budget, so the parallel run leaves them out until it agrees with production elsewhere.+# Real-time is the most expensive cadence and the one production holds to a tighter budget, so the+# parallel run leaves it out until it agrees with production elsewhere.EVALUATED_INTERVALS = frozenset({+ AlertCalculationInterval.EVERY_15_MINUTES,AlertCalculationInterval.HOURLY,AlertCalculationInterval.DAILY,AlertCalculationInterval.WEEKLY,@@ -88,7 +89,7 @@ EVALUATED_INTERVALS = frozenset(def is_evaluated_on_the_platform(alert: AlertConfiguration) -> bool:- """Threshold alerts on an hourly or slower cadence. A detector alert makes its own decision,+ """Threshold alerts on a 15-minute or slower cadence. A detector alert makes its own decision,and the LLM detector makes a charged model call, so evaluating either in parallel costs twice."""return not alert.detector_config and alert.calculation_interval in EVALUATED_INTERVALSdiff --git a/products/alerts/backend/test/test_platform_alert_backfill.py b/products/alerts/backend/test/test_platform_alert_backfill.pyindex e927b5e22c1c..ef2536a5a0e7 100644--- a/products/alerts/backend/test/test_platform_alert_backfill.py+++ b/products/alerts/backend/test/test_platform_alert_backfill.py@@ -51,7 +51,8 @@ class TestPlatformInsightAlertBackfill(APIBaseTest):)return {view.legacy_configuration_id: view for view in page.configurations}- def test_only_hourly_and_slower_threshold_alerts_are_copied_on_their_recurrence(self) -> None:+ def test_only_15_minute_and_slower_threshold_alerts_are_copied_on_their_recurrence(self) -> None:+ quarter_hourly = self._alert(calculation_interval=AlertCalculationInterval.EVERY_15_MINUTES.value)hourly = self._alert(calculation_interval=AlertCalculationInterval.HOURLY.value, schedule_start_time="09:30")daily = self._alert(schedule_start_time="09:30")self._alert(calculation_interval=AlertCalculationInterval.REAL_TIME.value)@@ -61,10 +62,11 @@ class TestPlatformInsightAlertBackfill(APIBaseTest):counts = backfill_platform_insight_alert_configurations(team_id=self.team.id)again = backfill_platform_insight_alert_configurations(team_id=self.team.id)- assert (counts.created, counts.skipped, counts.failed, again.created, again.updated) == (2, 2, 1, 0, 2)+ assert (counts.created, counts.skipped, counts.failed, again.created, again.updated) == (3, 2, 1, 0, 3)copies = self._copies()assert unparseable.id not in copiesassert {key: (v.check_interval_minutes, v.recurrence_unit, v.anchor_time) for key, v in copies.items()} == {+ quarter_hourly.id: (15, None, None),hourly.id: (60, None, None),daily.id: (60 * 24, "day", "09:30"),}