Skip to content

: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.

feat(alerts): key the real-time cadence on the alerts platform (#123642)

Jimmy Zhu88b295f75b3b
diff --git a/products/alerts/backend/test/test_platform_source_cycle.py b/products/alerts/backend/test/test_platform_source_cycle.py
index 1a85b2a6d97a..70988b3edc28 100644
--- a/products/alerts/backend/test/test_platform_source_cycle.py
+++ b/products/alerts/backend/test/test_platform_source_cycle.py
@@ -347,6 +347,10 @@ class TestPlatformInsightEvaluation(APIBaseTest):
("hourly_quiet_hours", AlertCalculationInterval.HOURLY, 60, None, ("16:00", "17:00"), None),
("daily_quiet_hours", AlertCalculationInterval.DAILY, 60 * 24, "day", ("00:30", "02:00"), None),
("hourly_start_time", AlertCalculationInterval.HOURLY, 60, None, None, "09:20"),
+ # Real time steps from the previous due time, seconds and all, rather than from a grid.
+ ("real_time", AlertCalculationInterval.REAL_TIME, 2, None, None, None, timedelta(seconds=90)),
+ ("real_time_quiet_hours", AlertCalculationInterval.REAL_TIME, 2, None, ("15:31", "16:30"), None),
+ ("real_time_start_time", AlertCalculationInterval.REAL_TIME, 2, None, None, "09:20", timedelta(seconds=90)),
]
)
def test_a_copy_is_next_due_when_the_production_alert_is(
@@ -357,13 +361,17 @@ class TestPlatformInsightEvaluation(APIBaseTest):
unit: str | None,
quiet: tuple[str, str] | None,
start_time: str | None,
+ overdue: timedelta = timedelta(minutes=1),
) -> None:
# A half-hour timezone, where the local hour starts at :30 UTC.
self.team.timezone = "Asia/Kolkata"
self.team.save()
restriction = {"blocked_windows": [{"start": quiet[0], "end": quiet[1]}]} if quiet else None
alert = self._alert(
- calculation_interval=interval, schedule_restriction=restriction, schedule_start_time=start_time
+ calculation_interval=interval,
+ schedule_restriction=restriction,
+ schedule_start_time=start_time,
+ next_check_at=CUTOFF - overdue,
)
configuration = self._copy(
alert,
@@ -371,6 +379,7 @@ class TestPlatformInsightEvaluation(APIBaseTest):
recurrence_unit=unit,
schedule_restriction=restriction,
anchor_time=start_time,
+ next_check_at=CUTOFF - overdue,
)
with time_machine.travel(CUTOFF, tick=False):
diff --git a/products/alerts_platform/backend/facade/scheduling.py b/products/alerts_platform/backend/facade/scheduling.py
index 31ef8f64e9ff..221427df47b3 100644
--- a/products/alerts_platform/backend/facade/scheduling.py
+++ b/products/alerts_platform/backend/facade/scheduling.py
@@ -415,6 +415,7 @@ def to_recurrence_interval(recurrence_unit: str) -> CalendarInterval:
# The minute cadences `next_calendar_check_time` also schedules, so a keyed configuration on one of
# them can follow the source's own stack.
_KEYED_MINUTE_CADENCES: Final[dict[int, CalendarInterval]] = {
+ REAL_TIME_CADENCE_MINUTES: CalendarInterval.REAL_TIME,
EVERY_15_MINUTES_CADENCE_MINUTES: CalendarInterval.EVERY_15_MINUTES,
60: CalendarInterval.HOURLY,
}
@@ -446,7 +447,8 @@ def advance_schedule(
`schedule_key` names the alert the source's own stack times this one by. With it, a 15-minute
or hourly cadence follows that stack's local interval boundary and offset rather than the UTC
- grid and shard, a calendar unit spreads by the key rather than by `configuration_id`, and a
+ grid and shard, a real-time cadence steps from the previous due time as that stack does, a
+ calendar unit spreads by the key rather than by `configuration_id`, and a
check that would land in `blocked_windows` moves out of it the way that stack moves it. Without
a key, quiet hours never move the schedule: the check runs and only its announcement is held.
"""