: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
feat(alerts): record which stack owns a logs alert (#116594)
Jimmy Zhu8c8097b06674
diff --git a/products/alerts_platform/backend/facade/enums.py b/products/alerts_platform/backend/facade/enums.pyindex b63c6a421e68..a133f704de9b 100644--- a/products/alerts_platform/backend/facade/enums.py+++ b/products/alerts_platform/backend/facade/enums.py@@ -15,6 +15,13 @@ class PlatformAlertConfigurationSourceKind(LabeledStrEnum):INSIGHT = "insight", "Insight"+class PlatformAlertOwner(LabeledStrEnum):+ """The one stack that evaluates and delivers an alert, and the only one that writes it."""++ SOURCE = "source", "Source"+ PLATFORM = "platform", "Platform"++class PlatformAlertState(LabeledStrEnum):"""Where one alert instance stands."""diff --git a/products/alerts_platform/backend/migrations/0008_platformalertconfiguration_owner.py b/products/alerts_platform/backend/migrations/0008_platformalertconfiguration_owner.pynew file mode 100644index 000000000000..6790403ec52c--- /dev/null+++ b/products/alerts_platform/backend/migrations/0008_platformalertconfiguration_owner.py@@ -0,0 +1,27 @@+# Generated by Django 5.2.18 on 2026-10-13 20:21++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("alerts_platform", "0007_platformalertthread_root_message"),+ ]++ operations = [+ migrations.AddField(+ model_name="platformalertconfiguration",+ name="owner",+ field=models.CharField(+ choices=[("source", "Source"), ("platform", "Platform")],+ db_default="source",+ default="source",+ max_length=16,+ ),+ ),+ migrations.AddField(+ model_name="platformalertconfiguration",+ name="owner_changed_at",+ field=models.DateTimeField(blank=True, null=True),+ ),+ ]diff --git a/products/alerts_platform/backend/migrations/max_migration.txt b/products/alerts_platform/backend/migrations/max_migration.txtindex 86815eeac496..f59b38c76b53 100644--- a/products/alerts_platform/backend/migrations/max_migration.txt+++ b/products/alerts_platform/backend/migrations/max_migration.txt@@ -1 +1 @@-0007_platformalertthread_root_message+0008_platformalertconfiguration_ownerdiff --git a/products/alerts_platform/backend/models/platform_alert.py b/products/alerts_platform/backend/models/platform_alert.pyindex c800c5cbf3c0..cd099c0e8763 100644--- a/products/alerts_platform/backend/models/platform_alert.py+++ b/products/alerts_platform/backend/models/platform_alert.py@@ -16,6 +16,7 @@ from posthog.models.utils import UUIDModelfrom products.alerts_platform.backend.facade.enums import (PlatformAlertConfigurationRecurrenceUnit,PlatformAlertConfigurationSourceKind,+ PlatformAlertOwner,PlatformAlertState,)@@ -38,6 +39,7 @@ class PlatformAlertConfiguration(TeamScopedRootMixin, UUIDModel):# the way every other model in the repo does.SourceKind = PlatformAlertConfigurationSourceKindRecurrenceUnit = PlatformAlertConfigurationRecurrenceUnit+ Owner = PlatformAlertOwner# No database constraint: creating one takes a lock on `posthog_team` that queues behind# live writes. Django still cascades in Python, which is the only path that deletes a team.@@ -78,6 +80,14 @@ class PlatformAlertConfiguration(TeamScopedRootMixin, UUIDModel):# an evaluation up against the one the source's own stack produced.legacy_configuration_id = models.UUIDField(null=True, blank=True, unique=True)+ # The source's own row records the same owner. Only the cutover and rollback commands write+ # the two, in one transaction, so each stack can decide from its own row without reading the+ # other product's table.+ owner = models.CharField(+ max_length=16, choices=Owner.choices, default=Owner.SOURCE.value, db_default=Owner.SOURCE.value+ )+ owner_changed_at = models.DateTimeField(null=True, blank=True)+class Meta:# Pinned: the name predates this app, and removing this renames a live table.db_table = "alerts_platformalertconfiguration"diff --git a/products/logs/backend/migrations/0026_logsalertconfiguration_owner.py b/products/logs/backend/migrations/0026_logsalertconfiguration_owner.pynew file mode 100644index 000000000000..f4977ae4e9f8--- /dev/null+++ b/products/logs/backend/migrations/0026_logsalertconfiguration_owner.py@@ -0,0 +1,27 @@+# Generated by Django 5.2.18 on 2026-10-13 20:22++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("logs", "0025_alter_logsalertconfiguration_team_and_more"),+ ]++ operations = [+ migrations.AddField(+ model_name="logsalertconfiguration",+ name="owner",+ field=models.CharField(+ choices=[("source", "Source"), ("platform", "Platform")],+ db_default="source",+ default="source",+ max_length=16,+ ),+ ),+ migrations.AddField(+ model_name="logsalertconfiguration",+ name="owner_changed_at",+ field=models.DateTimeField(blank=True, null=True),+ ),+ ]diff --git a/products/logs/backend/migrations/max_migration.txt b/products/logs/backend/migrations/max_migration.txtindex e6592b2c84b6..b26ac163d0cb 100644--- a/products/logs/backend/migrations/max_migration.txt+++ b/products/logs/backend/migrations/max_migration.txt@@ -1 +1 @@-0025_alter_logsalertconfiguration_team_and_more+0026_logsalertconfiguration_ownerdiff --git a/products/logs/backend/models.py b/products/logs/backend/models.pyindex 5d4ea98b81c5..d0fab9cb8f19 100644--- a/products/logs/backend/models.py+++ b/products/logs/backend/models.py@@ -13,6 +13,8 @@ from posthog.models.scoping.root_mixin import TeamScopedRootMixinfrom posthog.models.utils import CreatedMetaFields, UpdatedMetaFields, UUIDModelfrom posthog.utils import generate_short_id+from products.alerts_platform.backend.facade.enums import PlatformAlertOwner+if TYPE_CHECKING:from products.logs.backend.alert_state_machine import AlertSnapshot@@ -250,6 +252,17 @@ class LogsAlertConfiguration(ModelActivityMixin, CreatedMetaFields, UpdatedMetaFconsecutive_failures = models.PositiveIntegerField(default=0)first_enabled_at = models.DateTimeField(null=True, blank=True)+ # Which stack evaluates and delivers this alert. The platform's copy records the same owner,+ # and only the cutover and rollback commands write the two. After a cutover the logs stack+ # keeps evaluating the alert for a shadow window from `owner_changed_at`, and sends nothing.+ owner = models.CharField(+ max_length=16,+ choices=PlatformAlertOwner.choices,+ default=PlatformAlertOwner.SOURCE.value,+ db_default=PlatformAlertOwner.SOURCE.value,+ )+ owner_changed_at = models.DateTimeField(null=True, blank=True)+class Meta:db_table = "logs_logsalertconfiguration"indexes = [