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): deliver an insight alert the platform owns (#119964)

Jimmy Zhu433b6bdce298
diff --git a/products/alerts/backend/platform_source_cycle.py b/products/alerts/backend/platform_source_cycle.py
index 0deccb93f06f..cf4e2390c113 100644
--- a/products/alerts/backend/platform_source_cycle.py
+++ b/products/alerts/backend/platform_source_cycle.py
@@ -2,8 +2,9 @@
A parallel run. The production insight fleet evaluates the same alerts against
`AlertConfiguration` and notifies their destinations. This decides what the platform would have
-said, and asks for a delivery only for the alerts in `LIVE_DELIVERY_INSIGHT_ALERT_IDS`. The
-platform still sends only to projects on its live delivery flag.
+said, and asks for a delivery for the alerts the platform owns and for the alerts in
+`LIVE_DELIVERY_INSIGHT_ALERT_IDS`. An owned alert sends without the platform's live delivery flag.
+Every other alert on the list still sends only to projects on that flag.
Each platform row resolves to its production alert through `legacy_configuration_id`, because
`check_alert_for_insight` reads the insight, the threshold and the condition off that model. The
@@ -120,9 +121,9 @@ EVALUATED_INTERVALS = frozenset(
)
-# The production insight alerts whose platform evaluations ask for a native delivery, as a test. The
-# platform's live delivery flag still has to be on for the project, and every other insight alert
-# keeps production as its only deliverer. Widening the test means adding an id here.
+# The production insight alerts whose platform evaluations ask for a native delivery while production
+# still owns them, as a test. The platform's live delivery flag still has to be on for the project.
+# The list stays short because production also sends for these alerts, so each one sends twice.
LIVE_DELIVERY_INSIGHT_ALERT_IDS: Final = frozenset({"01a11d6f-598e-0000-8529-4bcb65526f6d"})
# Which event each announced kind's destinations listen on. A resolve is left out, because
@@ -299,8 +300,11 @@ def _delivery(check: PlatformAlertCheckInput, outcome: PlatformAlertOutcome) ->
kinds.append(outcome.failure.kind)
if not any(kind.value in _EVENT_IDS_BY_KIND for kind in kinds):
return None
- legacy_id = str(check.legacy_configuration_id) if check.legacy_configuration_id is not None else None
- if legacy_id not in LIVE_DELIVERY_INSIGHT_ALERT_IDS:
+ # Destinations are matched on the legacy alert's id, so a copy without one has nobody to send to.
+ if check.legacy_configuration_id is None:
+ return None
+ legacy_id = str(check.legacy_configuration_id)
+ if not check.owned_by_platform and legacy_id not in LIVE_DELIVERY_INSIGHT_ALERT_IDS:
return None
return AlertDeliveryRequest(
source=SourceKind.INSIGHT,
@@ -310,6 +314,7 @@ def _delivery(check: PlatformAlertCheckInput, outcome: PlatformAlertOutcome) ->
evaluation_key=outcome.evaluation_key,
destination_alert_id=legacy_id,
event_ids_by_kind=_EVENT_IDS_BY_KIND,
+ owned_by_platform=check.owned_by_platform,
overflowed=outcome.overflowed,
parts=delivery_parts(outcome),
)
diff --git a/products/alerts/backend/test/test_platform_source_cycle.py b/products/alerts/backend/test/test_platform_source_cycle.py
index 1fe8f8104d58..5818ced2425d 100644
--- a/products/alerts/backend/test/test_platform_source_cycle.py
+++ b/products/alerts/backend/test/test_platform_source_cycle.py
@@ -55,6 +55,7 @@ from products.alerts_platform.backend.facade.contracts import (
SourceEvaluationInputs,
SourceKind,
)
+from products.alerts_platform.backend.facade.enums import PlatformAlertOwner
_MODULE = "products.alerts.backend.platform_source_cycle"
# A Wednesday, so no weekend rule applies.
@@ -237,16 +238,17 @@ class TestPlatformInsightEvaluation(APIBaseTest):
@parameterized.expand(
[
- ("allowlisted", True, False),
- ("not_allowlisted", False, False),
- ("allowlisted_resolve", True, True),
+ ("allowlisted", True, False, False),
+ ("not_allowlisted", False, False, False),
+ ("allowlisted_resolve", True, True, False),
+ ("platform_owned", False, False, True),
]
)
- def test_only_an_allowlisted_firing_or_failure_asks_for_a_delivery(
- self, _name: str, allowlisted: bool, was_firing: bool
+ def test_only_an_allowlisted_or_platform_owned_firing_or_failure_asks_for_a_delivery(
+ self, _name: str, allowlisted: bool, was_firing: bool, owned: bool
) -> None:
alert = self._alert()
- configuration = self._copy(alert)
+ configuration = self._copy(alert, **({"owner": PlatformAlertOwner.PLATFORM} if owned else {}))
allowlist = frozenset({str(alert.id)}) if allowlisted else frozenset()
if was_firing:
fired, _ = self._evaluate(configuration, result=AlertEvaluationResult(value=150.0, breaches=["above 100"]))
@@ -266,12 +268,18 @@ class TestPlatformInsightEvaluation(APIBaseTest):
str(configuration.id),
str(alert.id),
{"firing": "$insight_alert_firing", "errored": INSIGHT_ALERT_ERRORED_EVENT_ID},
+ owned,
)
]
assert [
- (delivery.configuration_id, delivery.destination_alert_id, delivery.event_ids_by_kind)
+ (
+ delivery.configuration_id,
+ delivery.destination_alert_id,
+ delivery.event_ids_by_kind,
+ delivery.owned_by_platform,
+ )
for delivery in self.deliveries
- ] == (expected if allowlisted and not was_firing else [])
+ ] == (expected if (allowlisted or owned) and not was_firing else [])
@parameterized.expand(
[