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.

fix(alerts): hand a firing logs alert over to the platform (#121598)

Jimmy Zhu069e3ea1b816
diff --git a/products/alerts_platform/backend/delivery/dispatch.py b/products/alerts_platform/backend/delivery/dispatch.py
index f74340434bfc..78515c08dbf5 100644
--- a/products/alerts_platform/backend/delivery/dispatch.py
+++ b/products/alerts_platform/backend/delivery/dispatch.py
@@ -43,6 +43,7 @@ def deliver(
announcement: EvaluationAnnouncement,
incident_action: IncidentAction | None = None,
source_alert_url: str | None = None,
+ source_incident_key: str | None = None,
) -> None:
channel_target = transport.channel_target(target)
busy = 0
@@ -57,25 +58,6 @@ def deliver(
channel_target=channel_target,
transition=transition,
)
- if key is None:
- _send(
- transport=transport,
- team_id=team_id,
- configuration_id=configuration_id,
- target=target,
- destination_id=destination_id,
- message=build_message(
- announcement,
- transition,
- team_id=team_id,
- incident_action=incident_action,
- source_alert_url=source_alert_url,
- overflowed=overflowed,
- ),
- in_reply_to=None,
- )
- continue
-
try:
claim = thread_store.claim(key, evaluation_key)
except ThreadBusy:
@@ -101,6 +83,7 @@ def deliver(
incident_action=incident_action,
source_alert_url=source_alert_url,
overflowed=overflowed,
+ source_incident_key=source_incident_key,
),
in_reply_to=claim.handle,
)
@@ -183,19 +166,19 @@ def _thread_key(
provider: str,
channel_target: str,
transition: AnnouncedTransition,
-) -> ThreadKey | None:
- """Which conversation this message belongs to, or None when it belongs to none.
-
- A message about no firing, which is a failed or a turned-off check, continues no
- conversation and starts none. Keying one on the absent firing would thread every such
- message for a configuration into the first one, which is the defect the episode prevents.
+) -> ThreadKey:
+ """Which conversation this message belongs to.
+
+ A message about no known firing, which is a failed or a turned-off check or the resolve of a
+ firing that began before the platform recorded starts, continues no conversation. Keying one
+ on the absent firing would thread every such message for a configuration into the first one,
+ which is the defect the episode prevents. So it is keyed on its own transition: it starts a
+ conversation nothing else joins, and a retried delivery still finds its claim and sends nothing.
"""
- if transition.episode_started_at is None:
- return None
return ThreadKey(
configuration_id=configuration_id,
grouping_key=transition.grouping_key,
provider=provider,
channel_target=channel_target,
- episode_started_at=transition.episode_started_at,
+ episode_started_at=transition.episode_started_at or transition.occurred_at,
)
diff --git a/products/alerts_platform/backend/delivery/evaluation.py b/products/alerts_platform/backend/delivery/evaluation.py
index f0a1d9e1db8e..ccde6197e4d0 100644
--- a/products/alerts_platform/backend/delivery/evaluation.py
+++ b/products/alerts_platform/backend/delivery/evaluation.py
@@ -23,7 +23,7 @@ from products.alerts_platform.backend.delivery.dispatch import deliver
from products.alerts_platform.backend.delivery.email import EmailTransport
from products.alerts_platform.backend.delivery.in_app import InAppTransport
from products.alerts_platform.backend.delivery.message import AlertMessage
-from products.alerts_platform.backend.delivery.pagerduty import PagerDutyTransport
+from products.alerts_platform.backend.delivery.pagerduty import PagerDutyTransport, source_incident_key
from products.alerts_platform.backend.delivery.slack import SlackTransport
from products.alerts_platform.backend.delivery.team_flags import team_flag_enabled
from products.alerts_platform.backend.delivery.teams import TeamsTransport
@@ -254,6 +254,9 @@ def deliver_evaluation(request: AlertDeliveryRequest) -> DeliveryOutcome:
),
incident_action=action_by_event_id.get(event_id),
source_alert_url=request.source_alert_url,
+ source_incident_key=source_incident_key(request.destination_alert_id)
+ if request.owned_by_platform
+ else None,
)
except ThreadBusy as error:
busy.append(str(error))
diff --git a/products/alerts_platform/backend/delivery/message.py b/products/alerts_platform/backend/delivery/message.py
index d89d47e1d3c9..fbf3f2361351 100644
--- a/products/alerts_platform/backend/delivery/message.py
+++ b/products/alerts_platform/backend/delivery/message.py
@@ -74,6 +74,8 @@ class AlertMessage:
image: MessageImage | None = None
slack_elements: tuple[dict[str, Any], ...] = ()
incident_action: IncidentAction | None = None
+ # The incident key the source's own stack opened incidents under, for a firing the platform took over.
+ source_incident_key: str | None = None
@property
def title(self) -> str:
@@ -157,6 +159,7 @@ def build_message(
incident_action: IncidentAction | None = None,
source_alert_url: str | None = None,
overflowed: int = 0,
+ source_incident_key: str | None = None,
) -> AlertMessage:
"""The message for one transition.
@@ -205,4 +208,5 @@ def build_message(
image=resolve_image(announcement.source, team_id=team_id, transition=transition),
slack_elements=description.slack_elements,
incident_action=incident_action,
+ source_incident_key=source_incident_key,
)
diff --git a/products/alerts_platform/backend/delivery/pagerduty.py b/products/alerts_platform/backend/delivery/pagerduty.py
index 3d5b42a8dad3..ff6075c2b47c 100644
--- a/products/alerts_platform/backend/delivery/pagerduty.py
+++ b/products/alerts_platform/backend/delivery/pagerduty.py
@@ -46,13 +46,26 @@ _MAX_SUMMARY_LENGTH: Final = 1024
_MAX_DEDUP_KEY_LENGTH: Final = 255
+def source_incident_key(destination_alert_id: str) -> str:
+ """The key the stock PagerDuty HogFunction opens an alert's incidents under.
+
+ pinned: the `dedup_key` input of the PagerDuty destination in
+ products/alerts/backend/logic/destination_configs.py, which every alert source shares.
+ """
+ return f"posthog-alert-{destination_alert_id}"
+
+
def dedup_key(message: AlertMessage) -> str:
"""One firing episode of one group, so its trigger and its resolve address the same incident.
- A firing that began before the platform recorded starts has no known start. Its resolve then
- addresses an incident the platform never opened, which PagerDuty ignores.
+ A firing that began before the platform recorded starts has no known start. When the platform
+ took that firing over from its source, the incident is the source's own, so its resolve uses
+ the source's key. Otherwise the resolve addresses an incident nobody opened, which PagerDuty
+ ignores.
"""
transition = message.transition
+ if transition.episode_started_at is None and message.source_incident_key is not None:
+ return message.source_incident_key
episode = rfc3339(transition.episode_started_at) if transition.episode_started_at else "unknown"
key = f"{message.configuration_id}:{transition.grouping_key}:{episode}"
if len(key) <= _MAX_DEDUP_KEY_LENGTH:
diff --git a/products/alerts_platform/backend/facade/contracts.py b/products/alerts_platform/backend/facade/contracts.py
index 848edb4eec26..dcc95448bac2 100644
--- a/products/alerts_platform/backend/facade/contracts.py
+++ b/products/alerts_platform/backend/facade/contracts.py
@@ -381,7 +381,8 @@ class PlatformOwnershipHandover:
class HandbackRefusal(StrEnum):
"""Why the platform keeps an alert its source asked for back."""
- # Firing episodes are keyed per stack, so a firing alert stays until it resolves.
+ # The platform keys its incidents by episode, which the source's own stack cannot address, so a
+ # firing alert stays until it resolves.
FIRING = "firing"
# A platform check may be running and could record or notify after the handback.
CHECK_DUE = "check_due"
diff --git a/products/alerts_platform/backend/facade/testing.py b/products/alerts_platform/backend/facade/testing.py
index 92fa67cec176..ee7493b7ad01 100644
--- a/products/alerts_platform/backend/facade/testing.py
+++ b/products/alerts_platform/backend/facade/testing.py
@@ -22,7 +22,12 @@ from products.alerts_platform.backend.facade.contracts import (
)
from products.alerts_platform.backend.logic.platform_alert_events import PlatformAlertEventRow, insert_events
from products.alerts_platform.backend.logic.platform_reads import instance_view
-from products.alerts_platform.backend.models import PlatformAlert, PlatformAlertConfiguration, PlatformAlertDeliveryPath
+from products.alerts_platform.backend.models import (
+ PlatformAlert,
+ PlatformAlertConfiguration,
+ PlatformAlertDeliveryPath,
+ PlatformAlertThread,
+)
def _configuration_snapshot(row: PlatformAlertConfiguration) -> PlatformConfigurationSnapshot:
@@ -77,11 +82,14 @@ def start_firing(
team_id: int,
at: datetime,
delivered_via: DeliveryPath | None = None,
+ sent_natively: bool = False,
grouping_key: str = "",
) -> None:
"""Put a configuration's instance inside a firing, as live delivery can leave one.
With `delivered_via`, the firing's first delivery took that path, so its resolve takes it too.
+ With `sent_natively`, a native transport sent the firing, as live delivery does for an alert
+ its source owns.
"""
PlatformAlert.objects.update_or_create(
team_id=team_id,
@@ -97,6 +105,15 @@ def start_firing(
episode_started_at=at,
path=delivered_via.value,
)
+ if sent_natively:
+ PlatformAlertThread.objects.for_team(team_id).create(
+ team_id=team_id,
+ configuration_id=configuration_id,
+ grouping_key=grouping_key,
+ provider="slack",
+ channel_target="C0",
+ episode_started_at=at,
+ )
def set_check_status(configuration_id: UUID, check_status: str) -> None:
diff --git a/products/alerts_platform/backend/logic/platform_lifecycle.py b/products/alerts_platform/backend/logic/platform_lifecycle.py
index a8c2c653311d..5e9b6f502121 100644
--- a/products/alerts_platform/backend/logic/platform_lifecycle.py
+++ b/products/alerts_platform/backend/logic/platform_lifecycle.py
@@ -907,26 +907,59 @@ def refresh_settings(team_id: int, configuration_id: UUID, upsert: PlatformAlert
)
-# Firing episodes are keyed per stack, so a firing alert stays with its source until it resolves.
-_HANDOVER_STATES: Final = frozenset(
- {PlatformAlertState.NOT_FIRING, PlatformAlertState.ERRORED, PlatformAlertState.BROKEN}
-)
_HANDOVER_FENCE: Final = timedelta(minutes=1)
+# Longer than a delivery workflow can wait between the check that starts a firing and the first
+# thread claim. Inside it, a firing with no claimed thread may still have a delivery on its way.
+_DELIVERY_FENCE: Final = timedelta(minutes=10)
+
+
+def _delivered_firing(
+ team_id: int, configuration: PlatformAlertConfiguration, alerts: Sequence[PlatformAlert], *, at: datetime
+) -> bool:
+ """Whether any of these instances is inside a firing the platform delivered, or may still deliver.
+
+ Every native send claims a thread keyed on the firing's start, so a firing with no claimed
+ thread was never sent, once its delivery had time to start. A firing with an unknown start has
+ no key to find, so it counts as sent.
+ """
+ started: list[PlatformAlert] = []
+ for instance in alerts:
+ if instance.firing_started_at is None:
+ if instance.state == PlatformAlertState.FIRING:
+ return True
+ elif instance.firing_started_at > at - _DELIVERY_FENCE:
+ return True
+ else:
+ started.append(instance)
+ if not started:
+ return False
+ delivered = Q()
+ for instance in started:
+ delivered |= Q(grouping_key=instance.grouping_key, episode_started_at=instance.firing_started_at)
+ return PlatformAlertThread.objects.for_team(team_id).filter(delivered, configuration=configuration).exists()
+
+
def take_ownership(handover: PlatformOwnershipHandover) -> bool:
"""Makes the platform the owner of a copied alert, carrying on from the source's state.
The second writer of an alert's state beside `record_outcomes`. The caller holds the source's
row lock and writes the source's owner in the same transaction, so both rows change together.
- Returns False, changing nothing, when the copy is inside a firing of its own: a team on live
- delivery can have one open while its source is quiet, and replacing it would orphan the incident.
+ Returns False, changing nothing, when the copy is inside a firing of its own that the platform
+ delivered: a team on live delivery can have one open while its source is quiet, and replacing it
+ would orphan the incident. A firing the platform never delivered opened nothing, so the source's
+ state replaces it.
A grouped copy carries only the configuration's fields. Its source holds one state for the whole
alert, which no group inherits, and each group's row comes from the check that finds it.
- Raises `PlatformAlertConfiguration.DoesNotExist` when the alert was never copied.
+ A firing carries over with its start unknown, the state of a firing that began before the
+ platform recorded starts, so its resolve addresses the incident the source opened.
+ Raises `PlatformAlertConfiguration.DoesNotExist` when the alert was never copied, and `ValueError`
+ for a snooze, which the platform carries as a mute rather than a state, or for a firing of a
+ grouped copy, which has no single group to carry it to. Only a platform-owned copy is grouped.
"""
- if handover.state not in _HANDOVER_STATES:
- raise ValueError(f"an alert in state {handover.state} stays with its source until it resolves")
+ if handover.state == PlatformAlertState.SNOOZED:
+ raise ValueError("a snoozed alert is handed over with its snooze, not in a snoozed state")
with transaction.atomic():
configuration = (
PlatformAlertConfiguration.objects.for_team(handover.team_id)
@@ -939,13 +972,14 @@ def take_ownership(handover: PlatformOwnershipHandover) -> bool:
alert = _alerts_for_write(handover.team_id, [configuration], [key])[key]
alerts = [alert]
else:
+ if handover.state == PlatformAlertState.FIRING:
+ raise ValueError("a grouped copy has no single group to carry a firing to")
# No grouped check writes the empty key, so a row for it would only hold a slot of the cap.
alerts = _instances_by_configuration(handover.team_id, [configuration]).get(str(configuration.id), [])
# A failing check status means the machine already ended the firing the row still holds.
- live_firing = any(
- instance.state == PlatformAlertState.FIRING or instance.firing_started_at is not None for instance in alerts
- )
- if live_firing and configuration.check_status == PlatformAlertConfiguration.CheckStatus.OK:
+ if configuration.check_status == PlatformAlertConfiguration.CheckStatus.OK and _delivered_firing(
+ handover.team_id, configuration, alerts, at=handover.at
+ ):
return False
# ERRORED and BROKEN are the configuration's check status, so the instance starts at rest.
failing = handover.state in (PlatformAlertState.ERRORED, PlatformAlertState.BROKEN)
diff --git a/products/alerts_platform/backend/tests/test_delivery_dispatch.py b/products/alerts_platform/backend/tests/test_delivery_dispatch.py
index 7f7b1950ed90..6483dbff2991 100644
--- a/products/alerts_platform/backend/tests/test_delivery_dispatch.py
+++ b/products/alerts_platform/backend/tests/test_delivery_dispatch.py
@@ -1,4 +1,5 @@
-from datetime import UTC, datetime
+from dataclasses import replace
+from datetime import UTC, datetime, timedelta
from typing import Any, cast
import pytest
@@ -255,13 +256,28 @@ class TestDeliveryDispatch(SimpleTestCase):
assert retry.sends == []
- def test_a_check_that_never_fired_starts_no_conversation(self) -> None:
+ @parameterized.expand(
+ [
+ ("failed_check", AlertEventKind.ERRORED),
+ ("resolve_of_a_firing_taken_over_from_the_source", AlertEventKind.RESOLVED),
+ ]
+ )
+ def test_a_message_about_no_known_firing_joins_no_conversation_and_is_sent_once(
+ self, _name: str, kind: AlertEventKind
+ ) -> None:
store = RecordingThreadStore()
- transport = FakeTransport()
+ first, retry, later = FakeTransport(), FakeTransport(), FakeTransport()
- self._deliver(transport, store, _announcement(AlertEventKind.ERRORED, None))
+ self._deliver(first, store, _announcement(kind, None), evaluation_key="eval-1")
+ self._deliver(retry, store, _announcement(kind, None), evaluation_key="eval-1")
+ later_transition = replace(_transition(kind, None), occurred_at=FIRST_FIRING + timedelta(minutes=5))
+ self._deliver(
+ later, store, replace(_announcement(kind, None), transitions=(later_transition,)), evaluation_key="eval-2"
+ )
- assert store.threads == {}
+ assert [handle for _, handle in first.sends] == [None]
+ assert retry.sends == []
+ assert [handle for _, handle in later.sends] == [None]
def test_a_provider_outage_is_counted_as_a_failed_delivery(self) -> None:
transport = FakeTransport(error=ConnectionError("slack unreachable"))
diff --git a/products/alerts_platform/backend/tests/test_delivery_evaluation.py b/products/alerts_platform/backend/tests/test_delivery_evaluation.py
index ae419e52df4f..128e2339ee7d 100644
--- a/products/alerts_platform/backend/tests/test_delivery_evaluation.py
+++ b/products/alerts_platform/backend/tests/test_delivery_evaluation.py
@@ -365,6 +365,19 @@ class TestDeliverEvaluation(APIBaseTest):
assert [m.headline for channel, m in RecordingTransport.sends if channel == "C-1"] == chat_headlines
assert [m.incident_action for channel, m in RecordingTransport.sends if channel == "R-1"] == [action]
+ @parameterized.expand([("owned_by_the_platform", True, "posthog-alert-legacy-1"), ("live_delivery", False, None)])
+ def test_only_an_alert_the_platform_owns_resolves_under_its_source_incident_key(
+ self, _name: str, owned_by_platform: bool, expected: str | None
+ ) -> None:
+ self._run(
+ _announcement(_transition(AlertEventKind.RESOLVED)),
+ {CLOSED_EVENT: [_group(PAGERDUTY)]},
+ incident_actions={"": IncidentAction.RESOLVE},
+ owned_by_platform=owned_by_platform,
+ )
+
+ assert [m.source_incident_key for channel, m in RecordingTransport.sends if channel == "R-1"] == [expected]
+
def test_a_destination_with_no_transport_is_skipped_rather_than_failing_the_send(self) -> None:
outcome = self._run(
_announcement(_transition(AlertEventKind.FIRING)),
diff --git a/products/alerts_platform/backend/tests/test_delivery_pagerduty.py b/products/alerts_platform/backend/tests/test_delivery_pagerduty.py
index c92bfd1ffed8..cb1416f16d36 100644
--- a/products/alerts_platform/backend/tests/test_delivery_pagerduty.py
+++ b/products/alerts_platform/backend/tests/test_delivery_pagerduty.py
@@ -1,4 +1,5 @@
import json
+from dataclasses import replace
from datetime import datetime
from typing import Any, cast
@@ -77,6 +78,23 @@ class TestPagerDutyBody(SimpleTestCase):
assert key(IncidentAction.TRIGGER, grouping_key="search") != trigger
assert key(IncidentAction.TRIGGER, episode_started_at=datetime(2026, 9, 30, 11)) != trigger
+ @parameterized.expand(
+ [
+ ("taken_over_from_its_source", "posthog-alert-legacy-1", "posthog-alert-legacy-1"),
+ ("never_opened_here", None, "cfg-1::unknown"),
+ ]
+ )
+ def test_a_resolve_of_a_firing_with_no_known_start(
+ self, _name: str, source_incident_key: str | None, expected: str
+ ) -> None:
+ message = replace(
+ _message(IncidentAction.RESOLVE, episode_started_at=None), source_incident_key=source_incident_key
+ )
+
+ body = pagerduty_body(message, routing_key=ROUTING_KEY, severity=PagerDutySeverity.ERROR)
+
+ assert body["dedup_key"] == expected
+
def test_an_oversized_key_stays_within_what_pagerduty_accepts(self) -> None:
body = pagerduty_body(
_message(IncidentAction.TRIGGER, grouping_key="g" * 300),
diff --git a/products/alerts_platform/backend/tests/test_platform_lifecycle.py b/products/alerts_platform/backend/tests/test_platform_lifecycle.py
index 525ad96478cb..83b2ac6b3803 100644
--- a/products/alerts_platform/backend/tests/test_platform_lifecycle.py
+++ b/products/alerts_platform/backend/tests/test_platform_lifecycle.py
@@ -152,22 +152,34 @@ class TestPlatformAlertLifecycle(ClickhouseTestMixin, APIBaseTest):
@parameterized.expand(
[
- ("a_live_firing_stays_with_its_source", "ok", False, ("source", "firing", True)),
+ ("a_delivered_firing_stays_with_its_source", "ok", True, 60, False, ("source", "firing", True)),
+ # A copy checking beside its source fires without sending, so nothing it opened is orphaned.
+ ("an_undelivered_firing_is_taken_over", "ok", False, 60, True, ("platform", "not_firing", False)),
+ ("a_firing_whose_delivery_may_be_queued_stays", "ok", False, 1, False, ("source", "firing", True)),
# The machine ended the firing when the check broke, so the row's firing is stale.
- ("a_broken_copy_is_taken_over", "broken", True, ("platform", "not_firing", False)),
- ("an_errored_copy_is_taken_over", "errored", True, ("platform", "not_firing", False)),
+ ("a_broken_copy_is_taken_over", "broken", True, 60, True, ("platform", "not_firing", False)),
+ ("an_errored_copy_is_taken_over", "errored", True, 60, True, ("platform", "not_firing", False)),
]
)
- def test_a_copy_inside_its_own_firing_is_taken_over_only_once_that_firing_ended(
- self, _name: str, check_status: str, expected_taken: bool, expected: tuple[str, str, bool]
+ def test_a_copy_inside_its_own_firing_is_taken_over_unless_that_firing_was_delivered_and_runs(
+ self,
+ _name: str,
+ check_status: str,
+ delivered: bool,
+ started_minutes_ago: int,
+ expected_taken: bool,
+ expected: tuple[str, str, bool],
) -> None:
legacy_id = uuid4()
with team_scope(self.team.id):
PlatformAlertConfiguration.objects.filter(id=self.configuration.id).update(
legacy_configuration_id=legacy_id, check_status=check_status
)
- PlatformAlert.objects.create(
- team=self.team, configuration=self.configuration, state="firing", firing_started_at=self.cutoff
+ platform_testing.start_firing(
+ self.configuration.id,
+ team_id=self.team.id,
+ at=self.cutoff - timedelta(minutes=started_minutes_ago),
+ sent_natively=delivered,
)
taken = take_ownership(
@@ -187,6 +199,34 @@ class TestPlatformAlertLifecycle(ClickhouseTestMixin, APIBaseTest):
assert taken is expected_taken
assert (self.configuration.owner, alert.state, alert.firing_started_at is not None) == expected
+ def test_a_firing_is_taken_over_with_its_start_unknown(self) -> None:
+ legacy_id = uuid4()
+ with team_scope(self.team.id):
+ PlatformAlertConfiguration.objects.filter(id=self.configuration.id).update(
+ legacy_configuration_id=legacy_id
+ )
+
+ taken = take_ownership(
+ PlatformOwnershipHandover(
+ legacy_configuration_id=legacy_id,
+ team_id=self.team.id,
+ state=PlatformAlertState.FIRING,
+ last_notified_at=self.cutoff,
+ consecutive_failures=0,
+ next_check_at=self.cutoff + timedelta(minutes=2),
+ at=self.cutoff,
+ )
+ )
+
+ alert = self._alert()
+ self.configuration.refresh_from_db()
+ assert (taken, self.configuration.owner, alert.state, alert.firing_started_at) == (
+ True,
+ "platform",
+ "firing",
+ None,
+ )
+
def test_a_grouped_copy_taken_over_leaves_its_one_slot_to_the_first_group(self) -> None:
legacy_id = uuid4()
with team_scope(self.team.id):
diff --git a/products/logs/backend/platform_alert_backfill.py b/products/logs/backend/platform_alert_backfill.py
index 41be923412a3..b1b9a2c12e98 100644
--- a/products/logs/backend/platform_alert_backfill.py
+++ b/products/logs/backend/platform_alert_backfill.py
@@ -74,10 +74,12 @@ def platform_upsert_of(alert: LogsAlertConfiguration) -> PlatformAlertUpsert:
# A muted logs alert is a state of its own. On the platform a mute only silences notifications,
-# so the copy keeps checking with the snooze carried on `snooze_until`. Firing states have no entry,
-# because a firing alert stays with logs until it resolves.
+# so the copy keeps checking with the snooze carried on `snooze_until`. A pending resolve is still
+# firing, because its incident stays open until the resolve completes.
PLATFORM_HANDOVER_STATE: Final[dict[str, PlatformAlertState]] = {
LogsAlertConfiguration.State.NOT_FIRING: PlatformAlertState.NOT_FIRING,
+ LogsAlertConfiguration.State.FIRING: PlatformAlertState.FIRING,
+ LogsAlertConfiguration.State.PENDING_RESOLVE: PlatformAlertState.FIRING,
LogsAlertConfiguration.State.SNOOZED: PlatformAlertState.NOT_FIRING,
LogsAlertConfiguration.State.ERRORED: PlatformAlertState.ERRORED,
LogsAlertConfiguration.State.BROKEN: PlatformAlertState.BROKEN,
diff --git a/products/logs/backend/platform_cutover.py b/products/logs/backend/platform_cutover.py
index 33d305b239af..7c93abd4ef7c 100644
--- a/products/logs/backend/platform_cutover.py
+++ b/products/logs/backend/platform_cutover.py
@@ -19,7 +19,7 @@ from posthog.dataclasses import frozen
from products.alerts_platform.backend.facade.api import give_back_ownership, take_ownership, upsert_configuration
from products.alerts_platform.backend.facade.contracts import Grouping, HandbackRefusal, PlatformOwnershipHandover
from products.alerts_platform.backend.facade.enums import PlatformAlertOwner
-from products.logs.backend.alert_state_machine import FIRING_STATES, ControlPlaneOutcome, apply_outcome
+from products.logs.backend.alert_state_machine import ControlPlaneOutcome, apply_outcome
from products.logs.backend.alert_utils import due_alerts_q
from products.logs.backend.models import LogsAlertConfiguration, LogsAlertEvent
from products.logs.backend.platform_alert_backfill import (
@@ -35,8 +35,6 @@ class CutoverSkip(StrEnum):
"""Why an alert stays with the logs stack for now."""
ALREADY_MOVED = "already_moved"
- # The two stacks key incidents differently, so a firing moves only after it resolves.
- FIRING = "firing"
# The logs scheduler owes this alert a check, which may already be running and could notify
# after the move.
CHECK_DUE = "check_due"
@@ -90,8 +88,6 @@ def _cut_over_alert(alert_id: UUID, now: datetime | None, *, dry_run: bool) -> C
return CutoverSkip.ALREADY_MOVED
if in_an_environment(alert):
return CutoverSkip.ENVIRONMENT
- if alert.state in FIRING_STATES:
- return CutoverSkip.FIRING
if _logs_check_owed(alert.id, at):
return CutoverSkip.CHECK_DUE
if not hand_over(alert, at):
diff --git a/products/logs/backend/test/test_platform_cutover.py b/products/logs/backend/test/test_platform_cutover.py
index 978a16d91a7c..99e561a88e12 100644
--- a/products/logs/backend/test/test_platform_cutover.py
+++ b/products/logs/backend/test/test_platform_cutover.py
@@ -53,6 +53,8 @@ class TestPlatformCutover(APIBaseTest):
@parameterized.expand(
[
("quiet", {}, "not_firing"),
+ ("firing", {"state": State.FIRING}, "firing"),
+ ("pending_resolve", {"state": State.PENDING_RESOLVE}, "firing"),
(
"snoozed_keeps_checking_muted",
{"state": State.SNOOZED, "snooze_until": NOW + timedelta(hours=1)},
@@ -88,16 +90,15 @@ class TestPlatformCutover(APIBaseTest):
max(alert.next_check_at or NOW, NOW + timedelta(minutes=1)),
)
assert instance is not None
- assert (instance.state, instance.last_notified_at, instance.snooze_until) == (
+ assert (instance.state, instance.firing_started_at, instance.last_notified_at, instance.snooze_until) == (
platform_state,
+ None,
alert.last_notified_at,
alert.snooze_until,
)
@parameterized.expand(
[
- ("firing", {"state": State.FIRING}, CutoverSkip.FIRING),
- ("pending_resolve", {"state": State.PENDING_RESOLVE}, CutoverSkip.FIRING),
("check_due", {"next_check_at": NOW}, CutoverSkip.CHECK_DUE),
("never_scheduled", {"next_check_at": None}, CutoverSkip.CHECK_DUE),
]
@@ -123,12 +124,15 @@ class TestPlatformCutover(APIBaseTest):
alert.refresh_from_db()
assert alert.owner == "source"
- def test_a_refused_cutover_leaves_the_firing_platform_copy_as_it_was(self) -> None:
- alert = self._alert()
+ @parameterized.expand([("quiet", State.NOT_FIRING), ("firing", State.FIRING)])
+ def test_a_refused_cutover_leaves_the_firing_platform_copy_as_it_was(self, _name: str, state: str) -> None:
+ alert = self._alert(state=state)
upsert_configuration(platform_upsert_of(alert))
with team_scope(self.team.id):
copy = platform_testing.copy_of(alert.id)
- platform_testing.start_firing(copy.id, team_id=self.team.id, at=NOW - timedelta(hours=1))
+ platform_testing.start_firing(
+ copy.id, team_id=self.team.id, at=NOW - timedelta(hours=1), sent_natively=True
+ )
LogsAlertConfiguration.objects.filter(id=alert.id).update(enabled=False, next_check_at=None)
(result,) = cut_over_team(self.team.id, now=NOW)