: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
refactor(alerts): read platform alerts by public id (#128790)
Jimmy Zhuf06a816655fa
diff --git a/products/alerts/backend/platform_alert_reads.py b/products/alerts/backend/platform_alert_reads.pyindex dd7ae0967216..4631cbd7ccc4 100644--- a/products/alerts/backend/platform_alert_reads.py+++ b/products/alerts/backend/platform_alert_reads.py@@ -28,10 +28,10 @@ from products.alerts.backend.platform_cutover import insight_state_of_platformfrom products.alerts.backend.platform_investigation_detail import SUPPRESSED_BY_AGENT_KEYfrom products.alerts.backend.platform_source_cycle import ERROR_CODE_KEYfrom products.alerts_platform.backend.facade.api import (- check_page_by_legacy_id,- checks_with_detail_by_legacy_id,- last_check_by_legacy_id,- runtime_by_legacy_id,+ check_page_by_public_id,+ checks_with_detail_by_public_id,+ last_check_by_public_id,+ runtime_by_public_id,source_suppressed_holds_by_legacy_id,)from products.alerts_platform.backend.facade.contracts import PlatformCheckEntry@@ -61,9 +61,9 @@ def moved_alert_statuses(*, team_id: int, alert_ids: Sequence[UUID], now: datetiif not snoozed_until:return {}moved = list(snoozed_until)- runtime = runtime_by_legacy_id(team_id=team_id, legacy_configuration_ids=moved)+ runtime = runtime_by_public_id(team_id=team_id, public_ids=moved)try:- last_checks = last_check_by_legacy_id(team_id=team_id, legacy_configuration_ids=moved)+ last_checks = last_check_by_public_id(team_id=team_id, public_ids=moved)except Exception as error:capture_exception(error, additional_properties={"team_id": team_id})last_checks = {}@@ -104,9 +104,9 @@ def moved_alert_check_page(if not AlertConfiguration.objects.filter(team_id=team_id, id=alert_id, owner=PlatformAlertOwner.PLATFORM).exists():return Nonetry:- page = check_page_by_legacy_id(+ page = check_page_by_public_id(team_id=team_id,- legacy_configuration_id=alert_id,+ public_id=alert_id,since=since or _EARLIEST,# The platform's window leaves out its end, and the API's keeps a check made at that moment.until=until + timedelta(microseconds=1) if until is not None else _LATEST,@@ -163,9 +163,9 @@ def moved_alert_fired_checks(return {}since = {alert_id: max(at, not_before) if not_before is not None else at for alert_id, at in moved_at.items()}try:- checks = checks_with_detail_by_legacy_id(+ checks = checks_with_detail_by_public_id(team_id=team_id,- legacy_configuration_ids=list(since),+ public_ids=list(since),detail_paths=[(FIRED_DATES_KEY,), *([AI_REASON_PATH] if ai_verdicts_only else [])],since=min(since.values()),limit=limit,diff --git a/products/alerts/backend/tests/api/test_alert_platform_owned.py b/products/alerts/backend/tests/api/test_alert_platform_owned.pyindex 4c9481bfaa6b..c0694f565e24 100644--- a/products/alerts/backend/tests/api/test_alert_platform_owned.py+++ b/products/alerts/backend/tests/api/test_alert_platform_owned.py@@ -289,7 +289,7 @@ class TestPlatformOwnedInsightAlert(ClickhouseTestMixin, APIBaseTest):self._record(30, "firing", value=150.0)with patch(- "products.alerts.backend.platform_alert_reads.check_page_by_legacy_id",+ "products.alerts.backend.platform_alert_reads.check_page_by_public_id",side_effect=RuntimeError("ClickHouse is down"),):row = self._row("retrieve")diff --git a/products/alerts_platform/backend/facade/api.py b/products/alerts_platform/backend/facade/api.pyindex 8748245245cc..9132cbd60fd6 100644--- a/products/alerts_platform/backend/facade/api.py+++ b/products/alerts_platform/backend/facade/api.py@@ -168,9 +168,9 @@ def give_back_ownership()-def reset_broken(*, team_id: int, legacy_configuration_id: UUID, at: datetime) -> int | None:+def reset_broken(*, team_id: int, public_id: UUID, at: datetime) -> int | None:"""Clears a broken alert the platform owns. Returns the failure count it cleared, or None when not broken."""- return platform_lifecycle.reset_broken(team_id=team_id, legacy_configuration_id=legacy_configuration_id, at=at)+ return platform_lifecycle.reset_broken(team_id=team_id, public_id=public_id, at=at)def disable_configurations(@@ -213,23 +213,21 @@ def get_configuration()-def runtime_by_legacy_id(- *, team_id: int, legacy_configuration_ids: Collection[UUID]-) -> dict[UUID, PlatformAlertRuntime]:- """The runtime state of each named alert the platform owns, keyed by the source's id."""- return platform_reads.runtime_by_legacy_id(team_id=team_id, legacy_configuration_ids=legacy_configuration_ids)+def runtime_by_public_id(*, team_id: int, public_ids: Collection[UUID]) -> dict[UUID, PlatformAlertRuntime]:+ """The runtime state of each named alert the platform owns, keyed by its public id."""+ return platform_reads.runtime_by_public_id(team_id=team_id, public_ids=public_ids)-def check_page_by_legacy_id(- *, team_id: int, legacy_configuration_id: UUID, since: datetime, until: datetime, limit: int, offset: int+def check_page_by_public_id(+ *, team_id: int, public_id: UUID, since: datetime, until: datetime, limit: int, offset: int) -> PlatformCheckPage | None:"""A page of one owned alert's checks in a window, newest first, or None when the platform does not own it.Raises when ClickHouse fails, so a caller can fall back to what it shows without the platform."""- return platform_reads.check_page_by_legacy_id(+ return platform_reads.check_page_by_public_id(team_id=team_id,- legacy_configuration_id=legacy_configuration_id,+ public_id=public_id,since=since,until=until,limit=limit,@@ -237,61 +235,55 @@ def check_page_by_legacy_id()-def checks_with_detail_by_legacy_id(+def checks_with_detail_by_public_id(*,team_id: int,- legacy_configuration_ids: Collection[UUID],+ public_ids: Collection[UUID],detail_paths: Sequence[Sequence[str]],since: datetime,limit: int,) -> dict[UUID, tuple[PlatformCheckEntry, ...]]:"""Each named owned alert's newest `limit` checks since `since` whose source detail holds- every one of `detail_paths`, newest first, keyed by the source's id.+ every one of `detail_paths`, newest first, keyed by its public id.Raises when ClickHouse fails, so a caller can fall back to what it shows without the platform."""- return platform_reads.checks_with_detail_by_legacy_id(+ return platform_reads.checks_with_detail_by_public_id(team_id=team_id,- legacy_configuration_ids=legacy_configuration_ids,+ public_ids=public_ids,detail_paths=detail_paths,since=since,limit=limit,)-def history_by_legacy_id(- *, team_id: int, legacy_configuration_ids: Collection[UUID], since: datetime, until: datetime+def history_by_public_id(+ *, team_id: int, public_ids: Collection[UUID], since: datetime, until: datetime) -> dict[UUID, PlatformAlertHistory]:- """The check history in a window of each named alert the platform owns, keyed by the source's id.+ """The check history in a window of each named alert the platform owns, keyed by its public id.Raises when ClickHouse fails, so a caller can fall back to what it shows without the platform."""- return platform_reads.history_by_legacy_id(- team_id=team_id, legacy_configuration_ids=legacy_configuration_ids, since=since, until=until- )+ return platform_reads.history_by_public_id(team_id=team_id, public_ids=public_ids, since=since, until=until)-def last_check_by_legacy_id(- *, team_id: int, legacy_configuration_ids: Collection[UUID]-) -> dict[UUID, PlatformLastCheck]:- """The newest check of each named alert the platform owns, keyed by the source's id.+def last_check_by_public_id(*, team_id: int, public_ids: Collection[UUID]) -> dict[UUID, PlatformLastCheck]:+ """The newest check of each named alert the platform owns, keyed by its public id.Raises when ClickHouse fails, so a caller can fall back to what it shows without the platform."""- return platform_reads.last_check_by_legacy_id(team_id=team_id, legacy_configuration_ids=legacy_configuration_ids)+ return platform_reads.last_check_by_public_id(team_id=team_id, public_ids=public_ids)-def notable_checks_by_legacy_id(- *, team_id: int, legacy_configuration_id: UUID, since: datetime, limit: int+def notable_checks_by_public_id(+ *, team_id: int, public_id: UUID, since: datetime, limit: int) -> PlatformCheckEventPage | None:"""The newest `limit` checks since `since` that moved a named alert's state or failed, withtheir total, or None when the platform does not own the alert.Raises when ClickHouse fails, so a caller can fall back to what it shows without the platform."""- return platform_reads.notable_checks_by_legacy_id(- team_id=team_id, legacy_configuration_id=legacy_configuration_id, since=since, limit=limit- )+ return platform_reads.notable_checks_by_public_id(team_id=team_id, public_id=public_id, since=since, limit=limit)def update_configuration(diff --git a/products/alerts_platform/backend/logic/platform_lifecycle.py b/products/alerts_platform/backend/logic/platform_lifecycle.pyindex 812eb4ffe5fe..6663df7b0ff1 100644--- a/products/alerts_platform/backend/logic/platform_lifecycle.py+++ b/products/alerts_platform/backend/logic/platform_lifecycle.py@@ -1138,17 +1138,19 @@ def give_back_ownership(return handback-def reset_broken(*, team_id: int, legacy_configuration_id: UUID, at: datetime) -> int | None:+def reset_broken(*, team_id: int, public_id: UUID, at: datetime) -> int | None:"""Clears a broken alert the platform owns so the next tick checks it again, from rest.- Returns the failure count it cleared, or None when the alert is not broken. Discovery skips a- broken alert, so without this it never runs again. The caller holds the source's row lock.+ `public_id` is the alert's `destination_alert_id`. Returns the failure count it cleared, or None+ when the alert is not broken.+ Discovery skips a broken alert, so without this it never runs again. The caller holds the source's+ row lock, when there is one."""with transaction.atomic():configuration = (PlatformAlertConfiguration.objects.for_team(team_id).select_for_update()- .get(legacy_configuration_id=legacy_configuration_id)+ .get(PlatformAlertConfiguration.with_destination_alert_ids([public_id])))if configuration.owner != PlatformAlertOwner.PLATFORM:raise ValueError("the platform does not own this alert, so its source resets it")diff --git a/products/alerts_platform/backend/logic/platform_reads.py b/products/alerts_platform/backend/logic/platform_reads.pyindex f6a366fd7c67..23c63e33d22e 100644--- a/products/alerts_platform/backend/logic/platform_reads.py+++ b/products/alerts_platform/backend/logic/platform_reads.py@@ -9,6 +9,7 @@ from datetime import datetimefrom uuid import UUIDfrom django.db.models import Case, Exists, Max, OuterRef, Prefetch, QuerySet, Subquery, Value, When+from django.db.models.functions import Coalescefrom products.alerts_platform.backend.facade.contracts import (Grouping,@@ -148,24 +149,33 @@ def alert_snapshot(team_id: int, configuration_id: str, grouping_key: str) -> Plreturn instance_view(alert, alert.configuration) if alert is not None else None-def runtime_by_legacy_id(- *, team_id: int, legacy_configuration_ids: Collection[UUID]-) -> dict[UUID, PlatformAlertRuntime]:- """The runtime state of each named alert the platform owns, keyed by the source's id, in one query.+# A configuration's `destination_alert_id`, computed in the query.+_PUBLIC_ID = Coalesce("legacy_configuration_id", "id")+++def _owned_with_public_ids(team_id: int, public_ids: Collection[UUID]) -> QuerySet[PlatformAlertConfiguration]:+ """The alerts the platform owns with these public ids (`PlatformAlertConfiguration.destination_alert_id`)."""+ return PlatformAlertConfiguration.objects.for_team(team_id).filter(+ PlatformAlertConfiguration.with_destination_alert_ids(public_ids), owner=PlatformAlertOwner.PLATFORM+ )+++def runtime_by_public_id(*, team_id: int, public_ids: Collection[UUID]) -> dict[UUID, PlatformAlertRuntime]:+ """The runtime state of each named alert the platform owns, keyed by its public id, in one query.An alert the platform does not own is left out, because its source's own row is then the onethat moves. A source shows one state per alert, so a grouped alert fires while any of its groupsfires, and was last notified when any group last was. A copy with no instance yet has not beenchecked since the handover."""- if not legacy_configuration_ids:+ if not public_ids:return {}instances = PlatformAlert.objects.for_team(team_id).filter(configuration=OuterRef("pk"))latest_notified = instances.order_by().values("configuration").annotate(at=Max("last_notified_at")).values("at")rows = (- PlatformAlertConfiguration.objects.for_team(team_id)- .filter(legacy_configuration_id__in=list(legacy_configuration_ids), owner=PlatformAlertOwner.PLATFORM)+ _owned_with_public_ids(team_id, public_ids).annotate(+ public_id=_PUBLIC_ID,instance_state=Case(When(Exists(instances.filter(state=PlatformAlertState.FIRING)),@@ -176,7 +186,7 @@ def runtime_by_legacy_id(instance_last_notified_at=Subquery(latest_notified),).values_list(- "legacy_configuration_id",+ "public_id","instance_state","check_status","instance_last_notified_at",@@ -186,7 +196,7 @@ def runtime_by_legacy_id())return {- legacy_id: PlatformAlertRuntime(+ public_id: PlatformAlertRuntime(state=PlatformAlertState(InstanceCheckState.composed(grouping_key="",@@ -200,100 +210,87 @@ def runtime_by_legacy_id(next_check_at=next_check_at,grouping=Grouping.from_stored(grouping),)- for legacy_id, state, check_status, last_notified_at, consecutive_failures, next_check_at, grouping in rows- if legacy_id is not None+ for public_id, state, check_status, last_notified_at, consecutive_failures, next_check_at, grouping in rows}-def _owned_by_legacy_id(team_id: int, legacy_configuration_ids: Collection[UUID]) -> dict[UUID, UUID]:- """The source's id of each named alert the platform owns, keyed by the platform's id."""- return {- platform_id: legacy_id- for platform_id, legacy_id in PlatformAlertConfiguration.objects.for_team(team_id)- .filter(legacy_configuration_id__in=list(legacy_configuration_ids), owner=PlatformAlertOwner.PLATFORM)- .values_list("id", "legacy_configuration_id")- if legacy_id is not None- }+def _public_id_by_platform_id(team_id: int, public_ids: Collection[UUID]) -> dict[UUID, UUID]:+ """The public id of each named alert the platform owns, keyed by the platform's id."""+ return dict(+ _owned_with_public_ids(team_id, public_ids).annotate(public_id=_PUBLIC_ID).values_list("id", "public_id")+ )++def _platform_id_of(team_id: int, public_id: UUID) -> UUID | None:+ return _owned_with_public_ids(team_id, [public_id]).values_list("id", flat=True).first()-def history_by_legacy_id(- *, team_id: int, legacy_configuration_ids: Collection[UUID], since: datetime, until: datetime++def history_by_public_id(+ *, team_id: int, public_ids: Collection[UUID], since: datetime, until: datetime) -> dict[UUID, PlatformAlertHistory]:- """The check history in `[since, until)` of each named alert the platform owns, keyed by the- source's id.+ """The check history in `[since, until)` of each named alert the platform owns, keyed by its+ public id.One Postgres query finds the platform's ids and one ClickHouse query reads the history. An- alert the platform does not own is left out, as in `runtime_by_legacy_id`.+ alert the platform does not own is left out, as in `runtime_by_public_id`."""- if not legacy_configuration_ids:+ if not public_ids:return {}- legacy_by_platform_id = _owned_by_legacy_id(team_id, legacy_configuration_ids)- histories = platform_alert_events.history(team_id, legacy_by_platform_id, since=since, until=until)- return {legacy_by_platform_id[platform_id]: history for platform_id, history in histories.items()}+ public_by_platform_id = _public_id_by_platform_id(team_id, public_ids)+ histories = platform_alert_events.history(team_id, public_by_platform_id, since=since, until=until)+ return {public_by_platform_id[platform_id]: history for platform_id, history in histories.items()}-def last_check_by_legacy_id(- *, team_id: int, legacy_configuration_ids: Collection[UUID]-) -> dict[UUID, PlatformLastCheck]:- """The newest check of each named alert the platform owns, keyed by the source's id.+def last_check_by_public_id(*, team_id: int, public_ids: Collection[UUID]) -> dict[UUID, PlatformLastCheck]:+ """The newest check of each named alert the platform owns, keyed by its public id.- An alert the platform does not own is left out, as in `runtime_by_legacy_id`.+ An alert the platform does not own is left out, as in `runtime_by_public_id`."""- if not legacy_configuration_ids:+ if not public_ids:return {}- legacy_by_platform_id = _owned_by_legacy_id(team_id, legacy_configuration_ids)- checks = platform_alert_events.last_checks(team_id, legacy_by_platform_id)- return {legacy_by_platform_id[platform_id]: check for platform_id, check in checks.items()}+ public_by_platform_id = _public_id_by_platform_id(team_id, public_ids)+ checks = platform_alert_events.last_checks(team_id, public_by_platform_id)+ return {public_by_platform_id[platform_id]: check for platform_id, check in checks.items()}-def notable_checks_by_legacy_id(- *, team_id: int, legacy_configuration_id: UUID, since: datetime, limit: int+def notable_checks_by_public_id(+ *, team_id: int, public_id: UUID, since: datetime, limit: int) -> PlatformCheckEventPage | None:"""The newest checks since `since` that moved the named alert's state or failed, or None whenthe platform does not own it."""- platform_id = (- PlatformAlertConfiguration.objects.for_team(team_id)- .filter(legacy_configuration_id=legacy_configuration_id, owner=PlatformAlertOwner.PLATFORM)- .values_list("id", flat=True)- .first()- )+ platform_id = _platform_id_of(team_id, public_id)if platform_id is None:return Nonereturn platform_alert_events.notable_checks(team_id, platform_id, since=since, limit=limit)-def check_page_by_legacy_id(- *, team_id: int, legacy_configuration_id: UUID, since: datetime, until: datetime, limit: int, offset: int+def check_page_by_public_id(+ *, team_id: int, public_id: UUID, since: datetime, until: datetime, limit: int, offset: int) -> PlatformCheckPage | None:"""A page of the checks of one alert the platform owns, or None when the platform does not own it."""- platform_id = (- PlatformAlertConfiguration.objects.for_team(team_id)- .filter(legacy_configuration_id=legacy_configuration_id, owner=PlatformAlertOwner.PLATFORM)- .values_list("id", flat=True)- .first()- )+ platform_id = _platform_id_of(team_id, public_id)if platform_id is None:return Nonereturn platform_alert_events.check_page(team_id, platform_id, since=since, until=until, limit=limit, offset=offset)-def checks_with_detail_by_legacy_id(+def checks_with_detail_by_public_id(*,team_id: int,- legacy_configuration_ids: Collection[UUID],+ public_ids: Collection[UUID],detail_paths: Sequence[Sequence[str]],since: datetime,limit: int,) -> dict[UUID, tuple[PlatformCheckEntry, ...]]:"""Each named alert's newest `limit` checks since `since` whose source detail holds every one of `detail_paths`,- keyed by the source's id.+ keyed by its public id.- An alert the platform does not own is left out, as in `runtime_by_legacy_id`.+ An alert the platform does not own is left out, as in `runtime_by_public_id`."""- if not legacy_configuration_ids:+ if not public_ids:return {}- legacy_by_platform_id = _owned_by_legacy_id(team_id, legacy_configuration_ids)+ public_by_platform_id = _public_id_by_platform_id(team_id, public_ids)checks = platform_alert_events.checks_with_detail(- team_id, legacy_by_platform_id, detail_paths=detail_paths, since=since, limit=limit+ team_id, public_by_platform_id, detail_paths=detail_paths, since=since, limit=limit)- return {legacy_by_platform_id[platform_id]: entries for platform_id, entries in checks.items()}+ return {public_by_platform_id[platform_id]: entries for platform_id, entries in checks.items()}diff --git a/products/alerts_platform/backend/models/platform_alert.py b/products/alerts_platform/backend/models/platform_alert.pyindex 2f7e1a79cd7b..f8d4c7f0a2ac 100644--- a/products/alerts_platform/backend/models/platform_alert.py+++ b/products/alerts_platform/backend/models/platform_alert.py@@ -8,6 +8,7 @@ configuration already holds in this app. The prefix names what the rows are for:source configures on the shared platform, rather than one product's own table."""+from collections.abc import Collectionfrom typing import Anyfrom uuid import UUID@@ -130,10 +131,18 @@ class PlatformAlertConfiguration(ModelActivityMixin, TeamScopedRootMixin, UUIDMo@propertydef destination_alert_id(self) -> UUID:- """The id the alert's destinations are matched on: the source row's for a copy, and the- configuration's own for an alert whose source keeps no row."""+ """The alert's public id: the id its source, its clients and its destinations know it by. The+ source row's id for a copy, and the configuration's own id for an alert with no source row."""return self.legacy_configuration_id or self.id+ @staticmethod+ def with_destination_alert_ids(ids: Collection[UUID]) -> models.Q:+ """Matches the configurations whose `destination_alert_id` is one of `ids`."""+ listed = list(ids)+ return models.Q(legacy_configuration_id__in=listed) | models.Q(+ legacy_configuration_id__isnull=True, id__in=listed+ )+def _should_log_activity_for_update(self, **kwargs: Any) -> tuple[bool, Any]:# A copy its source owns is not logged, so its writes skip the read of the row before the update.# Backfills and source edits write those copies one row at a time.diff --git a/products/alerts_platform/backend/tests/test_platform_lifecycle.py b/products/alerts_platform/backend/tests/test_platform_lifecycle.pyindex 83b2ac6b3803..cde8232b2dc9 100644--- a/products/alerts_platform/backend/tests/test_platform_lifecycle.py+++ b/products/alerts_platform/backend/tests/test_platform_lifecycle.py@@ -19,6 +19,8 @@ from products.alerts_platform.backend.facade.api import (get_configuration,give_back_ownership,record_outcomes,+ reset_broken,+ runtime_by_public_id,slot_of,take_ownership,upsert_configuration,@@ -90,6 +92,36 @@ class TestPlatformAlertLifecycle(ClickhouseTestMixin, APIBaseTest):)self.slot = (self.cutoff - timedelta(minutes=1)).isoformat()+ def test_an_alert_is_read_by_its_public_id_whether_or_not_it_has_a_source_row(self) -> None:+ legacy_id = uuid4()+ with team_scope(self.team.id):+ PlatformAlertConfiguration.objects.filter(id=self.configuration.id).update(+ legacy_configuration_id=legacy_id,+ owner=PlatformAlertOwner.PLATFORM,+ check_status=PlatformAlertConfiguration.CheckStatus.BROKEN,+ consecutive_failures=3,+ )+ native = PlatformAlertConfiguration.objects.create(+ team=self.team,+ name="Web errors",+ source_kind=PlatformAlertConfiguration.SourceKind.LOGS,+ source_config={},+ check_interval_minutes=10,+ owner=PlatformAlertOwner.PLATFORM,+ check_status=PlatformAlertConfiguration.CheckStatus.BROKEN,+ consecutive_failures=5,+ )++ # The copy's own id is not a public id, so it finds nothing.+ runtime = runtime_by_public_id(team_id=self.team.id, public_ids=[legacy_id, native.id, self.configuration.id])+ cleared = [+ reset_broken(team_id=self.team.id, public_id=public_id, at=self.cutoff)+ for public_id in (legacy_id, native.id)+ ]++ assert {public_id: r.consecutive_failures for public_id, r in runtime.items()} == {legacy_id: 3, native.id: 5}+ assert cleared == [3, 5]+def _record(self, *, at: datetime | None = None, groups: tuple[GroupOutcome, ...] | None = None, **overrides) -> None:diff --git a/products/logs/backend/platform_alert_event_history.py b/products/logs/backend/platform_alert_event_history.pyindex 3771f8c3e60c..bfd2087d6515 100644--- a/products/logs/backend/platform_alert_event_history.py+++ b/products/logs/backend/platform_alert_event_history.py@@ -11,7 +11,7 @@ from uuid import UUID, uuid5from posthog.dataclasses import frozen-from products.alerts_platform.backend.facade.api import notable_checks_by_legacy_id+from products.alerts_platform.backend.facade.api import notable_checks_by_public_idfrom products.alerts_platform.backend.facade.contracts import PlatformCheckEventfrom products.alerts_platform.backend.facade.enums import PlatformAlertStatefrom products.logs.backend.alert_source_cycle import LogsAlertCondition@@ -51,7 +51,7 @@ def platform_check_rows(*, team_id: int, alert_id: UUID, since: datetime, limit:Raises when ClickHouse fails, so the caller can fall back to the logs rows."""- page = notable_checks_by_legacy_id(team_id=team_id, legacy_configuration_id=alert_id, since=since, limit=limit)+ page = notable_checks_by_public_id(team_id=team_id, public_id=alert_id, since=since, limit=limit)if page is None:return Nonereturn PlatformCheckRows(rows=tuple(_as_row(alert_id, check) for check in page.events), total=page.total)diff --git a/products/logs/backend/presentation/views/alerts_api.py b/products/logs/backend/presentation/views/alerts_api.pyindex 22dd40f62da4..6e7c7b3b4f19 100644--- a/products/logs/backend/presentation/views/alerts_api.py+++ b/products/logs/backend/presentation/views/alerts_api.py@@ -49,10 +49,10 @@ from products.alerts.backend.facade.destinations import (validate_destination_data,)from products.alerts_platform.backend.facade.api import (- history_by_legacy_id,+ history_by_public_id,recent_destination_sends,reset_broken,- runtime_by_legacy_id,+ runtime_by_public_id,)from products.alerts_platform.backend.facade.contracts import (AlertDestinationData,@@ -241,7 +241,7 @@ def _platform_runtime_of(alerts: list[LogsAlertConfiguration]) -> dict[UUID, Plaowned = [alert for alert in alerts if alert.platform_owned]if not owned:return {}- return runtime_by_legacy_id(team_id=owned[0].team_id, legacy_configuration_ids=[alert.id for alert in owned])+ return runtime_by_public_id(team_id=owned[0].team_id, public_ids=[alert.id for alert in owned])def _platform_history_of(@@ -253,9 +253,9 @@ def _platform_history_of(if not owned:return {}try:- return history_by_legacy_id(+ return history_by_public_id(team_id=owned[0].team_id,- legacy_configuration_ids=[alert.id for alert in owned],+ public_ids=[alert.id for alert in owned],since=window[0],until=window[1],)@@ -1621,9 +1621,7 @@ class LogsAlertViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):if alert.platform_owned:# The platform skips a broken alert, so the reset has to reach its copy. Its state# decides, because the logs row stops moving once the shadow ends.- platform_failures = reset_broken(- team_id=alert.team_id, legacy_configuration_id=alert.id, at=timezone.now()- )+ platform_failures = reset_broken(team_id=alert.team_id, public_id=alert.id, at=timezone.now())if platform_failures is None:raise ValidationError({"state": "Only broken alerts can be reset."})previous_failures = platform_failuresdiff --git a/products/logs/backend/test/test_alerts_api.py b/products/logs/backend/test/test_alerts_api.pyindex d435902c1b4c..c6e9f47e212a 100644--- a/products/logs/backend/test/test_alerts_api.py+++ b/products/logs/backend/test/test_alerts_api.py@@ -3619,7 +3619,7 @@ class TestPlatformOwnedAlertHistory(ClickhouseTestMixin, APIBaseTest):def test_falls_back_to_the_logs_row_when_clickhouse_fails(self) -> None:with patch(- "products.logs.backend.presentation.views.alerts_api.history_by_legacy_id",+ "products.logs.backend.presentation.views.alerts_api.history_by_public_id",side_effect=Exception("ClickHouse is down"),):[row] = self._rows("list")