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 alert the platform owns without the pilot flag (#116614)

Jimmy Zhu66546096d05a
diff --git a/products/alerts_platform/backend/delivery/evaluation.py b/products/alerts_platform/backend/delivery/evaluation.py
index f69628f80441..cee05297e34b 100644
--- a/products/alerts_platform/backend/delivery/evaluation.py
+++ b/products/alerts_platform/backend/delivery/evaluation.py
@@ -40,10 +40,10 @@ from products.alerts_platform.backend.logic.platform_alert_events import announc
logger = structlog.get_logger(__name__)
-# Whether the platform may contact a team's destinations. Only the platform reads it: the
-# production logs path keeps delivering regardless, so a team with this on receives the legacy
-# message and the native one. Flipping a team from one deliverer to the other is the cutover,
-# and it is not this.
+# Whether the platform may contact a team's destinations for an alert its source still owns. Only
+# the platform reads it: the source keeps delivering regardless, so a team with this on receives
+# the legacy message and the native one. An alert the platform owns never reads it, because the
+# source sends nothing for that alert and a flag-eval failure would silence it.
LIVE_DELIVERY_FLAG: Final = "alert-platform-live-delivery"
# A destination type with no entry here has no native transport, and delivery skips it. Make a
@@ -160,7 +160,7 @@ class _WebhookTransports:
def deliver_evaluation(request: AlertDeliveryRequest) -> DeliveryOutcome:
"""Sends what one evaluation decided, to every destination configured for it."""
team = Team.objects.filter(id=request.team_id).first()
- if team is None or not destinations_are_live(team):
+ if team is None or not (request.owned_by_platform or destinations_are_live(team)):
return DeliveryOutcome(live=False, sent=0, skipped_without_transport=0)
announced = announcement(
diff --git a/products/alerts_platform/backend/facade/contracts.py b/products/alerts_platform/backend/facade/contracts.py
index aba6cfd133c6..b9234bdda2b0 100644
--- a/products/alerts_platform/backend/facade/contracts.py
+++ b/products/alerts_platform/backend/facade/contracts.py
@@ -125,6 +125,7 @@ class PlatformAlertCheckInput:
last_notified_at: datetime | None
snooze_until: datetime | None
firing_started_at: datetime | None = None
+ owned_by_platform: bool = False
@property
def filters(self) -> dict[str, Any]:
@@ -333,6 +334,10 @@ class AlertDeliveryRequest:
actions, so its rows reach no message destination even when their kind has an event id.
`event_ids_by_incident_action` maps each action onto the event id an incident manager
destination filters on, the way `event_ids_by_kind` does for a message.
+
+ `owned_by_platform` is the owner when the check was read, not when the delivery runs. The
+ source decided its own send for that check from the same owner, so a retry across a cutover
+ or a rollback still has exactly one stack sending.
"""
source: SourceKind
@@ -344,6 +349,7 @@ class AlertDeliveryRequest:
incident_actions: dict[str, IncidentAction] = field(default_factory=dict)
sends_messages: bool = True
event_ids_by_incident_action: dict[str, str] = field(default_factory=dict)
+ owned_by_platform: bool = False
@frozen
diff --git a/products/alerts_platform/backend/logic/platform_lifecycle.py b/products/alerts_platform/backend/logic/platform_lifecycle.py
index c8c6bd55bf9b..8873be96881e 100644
--- a/products/alerts_platform/backend/logic/platform_lifecycle.py
+++ b/products/alerts_platform/backend/logic/platform_lifecycle.py
@@ -135,6 +135,7 @@ def _check(c: PlatformAlertConfiguration, alert: PlatformAlert | None) -> Platfo
last_notified_at=alert.last_notified_at if alert else None,
snooze_until=alert.snooze_until if alert else None,
firing_started_at=alert.firing_started_at if alert else None,
+ owned_by_platform=c.owner == PlatformAlertConfiguration.Owner.PLATFORM,
)
diff --git a/products/alerts_platform/backend/tests/test_delivery_evaluation.py b/products/alerts_platform/backend/tests/test_delivery_evaluation.py
index a5ebc9b5f683..134fff218009 100644
--- a/products/alerts_platform/backend/tests/test_delivery_evaluation.py
+++ b/products/alerts_platform/backend/tests/test_delivery_evaluation.py
@@ -84,7 +84,11 @@ class HeldTransport(RecordingTransport):
def _request(
- team_id: int, *, sends_messages: bool = True, incident_actions: dict[str, IncidentAction] | None = None
+ team_id: int,
+ *,
+ sends_messages: bool = True,
+ incident_actions: dict[str, IncidentAction] | None = None,
+ owned_by_platform: bool = False,
) -> AlertDeliveryRequest:
return AlertDeliveryRequest(
source=SourceKind.LOGS,
@@ -96,6 +100,7 @@ def _request(
sends_messages=sends_messages,
incident_actions=incident_actions or {},
event_ids_by_incident_action={"trigger": OPENED_EVENT, "resolve": CLOSED_EVENT},
+ owned_by_platform=owned_by_platform,
)
@@ -136,16 +141,20 @@ class TestDeliverEvaluation(APIBaseTest):
self,
announced: Any,
by_event: dict[str, list[AlertDestinationGroup]],
- live: bool = True,
+ live: bool | Exception = True,
transports: dict[DestinationType, type] | None = None,
sends_messages: bool = True,
incident_actions: dict[str, IncidentAction] | None = None,
+ owned_by_platform: bool = False,
) -> Any:
def groups(*, team_id: int, alert_id: str, allowed_event_ids: list[str]) -> list[AlertDestinationGroup]:
return by_event.get(allowed_event_ids[0], [])
with (
- patch(f"{_MODULE}.posthoganalytics.feature_enabled", return_value=live),
+ patch(
+ f"{_MODULE}.posthoganalytics.feature_enabled",
+ **({"side_effect": live} if isinstance(live, Exception) else {"return_value": live}),
+ ),
patch(f"{_MODULE}.announcement", return_value=announced),
patch(f"{_MODULE}.list_alert_destination_groups", side_effect=groups),
patch(f"{_MODULE}.DatabaseThreadStore"),
@@ -159,7 +168,12 @@ class TestDeliverEvaluation(APIBaseTest):
),
):
return deliver_evaluation(
- _request(self.team.id, sends_messages=sends_messages, incident_actions=incident_actions)
+ _request(
+ self.team.id,
+ sends_messages=sends_messages,
+ incident_actions=incident_actions,
+ owned_by_platform=owned_by_platform,
+ )
)
def test_a_destination_hears_only_about_the_kinds_it_subscribed_to(self) -> None:
@@ -302,12 +316,18 @@ class TestDeliverEvaluation(APIBaseTest):
assert flag.call_args.kwargs["groups"]["project"] == str(self.team.id)
assert flag.call_args.kwargs["group_properties"]["project"]["uuid"] == str(self.team.uuid)
- def test_a_flag_that_cannot_be_read_leaves_the_legacy_path_as_the_only_deliverer(self) -> None:
- with patch(f"{_MODULE}.posthoganalytics.feature_enabled", side_effect=RuntimeError("flags unreachable")):
- outcome = deliver_evaluation(_request(self.team.id))
+ @parameterized.expand([("owned_by_the_source", False), ("owned_by_the_platform", True)])
+ def test_a_flag_that_cannot_be_read_silences_only_alerts_the_source_still_delivers(
+ self, _name: str, delivers: bool
+ ) -> None:
+ outcome = self._run(
+ _announcement(_transition(AlertEventKind.FIRING)),
+ {FIRING_EVENT: [_group(SLACK)]},
+ live=RuntimeError("flags unreachable"),
+ owned_by_platform=delivers,
+ )
- assert RecordingTransport.sends == []
- assert outcome.live is False
+ assert (outcome.live, len(RecordingTransport.sends)) == (delivers, int(delivers))
@parameterized.expand(
[
diff --git a/products/logs/backend/alert_source_cycle.py b/products/logs/backend/alert_source_cycle.py
index 74d52d5fe23d..17907df49d16 100644
--- a/products/logs/backend/alert_source_cycle.py
+++ b/products/logs/backend/alert_source_cycle.py
@@ -396,6 +396,7 @@ def _request(
# Logs does not group, so its one row has the empty grouping key.
incident_actions={"": incident_action} if incident_action is not None else {},
sends_messages=sends_messages,
+ owned_by_platform=check.owned_by_platform,
)
diff --git a/products/logs/backend/test/test_alert_evaluate.py b/products/logs/backend/test/test_alert_evaluate.py
index 58e2d4967821..119a060435a2 100644
--- a/products/logs/backend/test/test_alert_evaluate.py
+++ b/products/logs/backend/test/test_alert_evaluate.py
@@ -108,9 +108,17 @@ class TestLogsAlertEvaluation(APIBaseTest):
"""
record_outcomes(self.team.id, evaluation.outcomes, self.cutoff)
- @parameterized.expand([("without_a_paging_destination", False), ("with_a_paging_destination", True)])
- def test_a_breaching_configuration_fires_and_records_its_own_state(self, _name: str, paged: bool) -> None:
- configuration = self._configuration()
+ @parameterized.expand(
+ [
+ ("without_a_paging_destination", False, "source"),
+ ("with_a_paging_destination", True, "source"),
+ ("owned_by_the_platform", False, "platform"),
+ ]
+ )
+ def test_a_breaching_configuration_fires_and_records_its_own_state(
+ self, _name: str, paged: bool, owner: str
+ ) -> None:
+ configuration = self._configuration(owner=owner)
if paged:
self._add_incident_destination(configuration)
@@ -118,8 +126,8 @@ class TestLogsAlertEvaluation(APIBaseTest):
self._record(evaluation)
assert [(o.kind, o.value) for o in evaluation.outcomes] == [(AlertEventKind.FIRING, 500.0)]
- assert [(d.sends_messages, d.incident_actions) for d in evaluation.deliveries] == [
- (True, {"": IncidentAction.TRIGGER} if paged else {})
+ assert [(d.sends_messages, d.incident_actions, d.owned_by_platform) for d in evaluation.deliveries] == [
+ (True, {"": IncidentAction.TRIGGER} if paged else {}, owner == "platform")
]
# The event a PagerDuty destination subscribes to, so the trigger reaches it.
assert evaluation.deliveries[0].event_ids_by_incident_action["trigger"] == "$logs_alert_incident_opened"