: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): add a source_detail column to platform_alert_events (#120017)
Jimmy Zhu9b69bb184e16
diff --git a/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl b/posthog/clickhouse/hcl/golden/dev/auxiliary.hclindex 0416f21366b5..e96c12c64e2a 100644--- a/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl@@ -1638,6 +1638,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}@@ -3175,6 +3178,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}diff --git a/posthog/clickhouse/hcl/golden/dev/data.hcl b/posthog/clickhouse/hcl/golden/dev/data.hclindex b0cac6ba7592..b93250599d6e 100644--- a/posthog/clickhouse/hcl/golden/dev/data.hcl+++ b/posthog/clickhouse/hcl/golden/dev/data.hcl@@ -3035,6 +3035,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}diff --git a/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl b/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hclindex 10e438eb3e01..4f13b043f4ec 100644--- a/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl@@ -1681,6 +1681,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}@@ -3182,6 +3185,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}diff --git a/posthog/clickhouse/hcl/golden/local-multi/data.hcl b/posthog/clickhouse/hcl/golden/local-multi/data.hclindex 6d1fcf799797..105dbffa2b7c 100644--- a/posthog/clickhouse/hcl/golden/local-multi/data.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/data.hcl@@ -3464,6 +3464,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hclindex 3aab051ed27a..35f1737d59a6 100644--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl@@ -8524,6 +8524,9 @@ SQLcolumn "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}@@ -12449,6 +12452,9 @@ SQLcolumn "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}diff --git a/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl b/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hclindex 73454ad49905..b51afa6a1e03 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl@@ -1638,6 +1638,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}@@ -3175,6 +3178,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}diff --git a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl b/posthog/clickhouse/hcl/golden/prod-eu/data.hclindex 0eeaee62f7ae..1c11d1eb7086 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl@@ -3796,6 +3796,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}diff --git a/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl b/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hclindex 5e1ee7e3bc88..cea262562a94 100644--- a/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl@@ -1676,6 +1676,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}@@ -3213,6 +3216,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}diff --git a/posthog/clickhouse/hcl/golden/prod-us/data.hcl b/posthog/clickhouse/hcl/golden/prod-us/data.hclindex f1519e148c17..3797607f6b09 100644--- a/posthog/clickhouse/hcl/golden/prod-us/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/data.hcl@@ -3587,6 +3587,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}diff --git a/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hclindex 24a74eed16cb..715c23703fa1 100644--- a/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hcl+++ b/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hcl@@ -368,6 +368,9 @@ database "posthog" {column "source_config_snapshot" {type = "String"}+ column "source_detail" {+ type = "String"+ }column "query_duration_ms" {type = "Nullable(UInt32)"}diff --git a/posthog/clickhouse/hcl/sql/dev/auxiliary.sql b/posthog/clickhouse/hcl/sql/dev/auxiliary.sqlindex 17bd75512892..c1f22726c62b 100644--- a/posthog/clickhouse/hcl/sql/dev/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/dev/auxiliary.sql@@ -701,6 +701,7 @@ CREATE TABLE posthog.sharded_platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,@@ -1794,6 +1795,7 @@ CREATE TABLE posthog.platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,diff --git a/posthog/clickhouse/hcl/sql/dev/data.sql b/posthog/clickhouse/hcl/sql/dev/data.sqlindex 8095ad5d8960..1001d6eff399 100644--- a/posthog/clickhouse/hcl/sql/dev/data.sql+++ b/posthog/clickhouse/hcl/sql/dev/data.sql@@ -636,6 +636,7 @@ CREATE TABLE posthog.platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,diff --git a/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql b/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sqlindex 9af2e644031d..32aa1b140308 100644--- a/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql@@ -705,6 +705,7 @@ CREATE TABLE posthog.sharded_platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,@@ -1815,6 +1816,7 @@ CREATE TABLE posthog.platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,diff --git a/posthog/clickhouse/hcl/sql/local-multi/data.sql b/posthog/clickhouse/hcl/sql/local-multi/data.sqlindex 4cec1bc8320e..ffcf570a0518 100644--- a/posthog/clickhouse/hcl/sql/local-multi/data.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/data.sql@@ -660,6 +660,7 @@ CREATE TABLE posthog.platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sqlindex b81269a30ee7..d629557d57da 100644--- a/posthog/clickhouse/hcl/sql/local-single/all.sql+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql@@ -2334,6 +2334,7 @@ CREATE TABLE posthog.sharded_platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,@@ -6895,6 +6896,7 @@ CREATE TABLE posthog.platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql b/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sqlindex b96c78e0ce8e..950b2f0d12bc 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql@@ -701,6 +701,7 @@ CREATE TABLE posthog.sharded_platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,@@ -1794,6 +1795,7 @@ CREATE TABLE posthog.platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/data.sql b/posthog/clickhouse/hcl/sql/prod-eu/data.sqlindex ec37a35a227a..ffed8bbe7e8f 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/data.sql@@ -909,6 +909,7 @@ CREATE TABLE posthog.platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,diff --git a/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql b/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sqlindex 028106f3ffef..829357461413 100644--- a/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql@@ -701,6 +701,7 @@ CREATE TABLE posthog.sharded_platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,@@ -1804,6 +1805,7 @@ CREATE TABLE posthog.platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,diff --git a/posthog/clickhouse/hcl/sql/prod-us/data.sql b/posthog/clickhouse/hcl/sql/prod-us/data.sqlindex a47f998b8575..d1633d606d7d 100644--- a/posthog/clickhouse/hcl/sql/prod-us/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/data.sql@@ -778,6 +778,7 @@ CREATE TABLE posthog.platform_alert_events (labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,diff --git a/posthog/clickhouse/migrations/0358_platform_alert_events_source_detail.py b/posthog/clickhouse/migrations/0358_platform_alert_events_source_detail.pynew file mode 100644index 000000000000..eea1d35be9a5--- /dev/null+++ b/posthog/clickhouse/migrations/0358_platform_alert_events_source_detail.py@@ -0,0 +1,28 @@+"""Store what the source said about each check, so a message can quote it without reading Postgres."""++from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions++from products.alerts_platform.backend.facade.clickhouse import (+ PLATFORM_ALERT_EVENTS_TABLE,+ SHARDED_PLATFORM_ALERT_EVENTS_TABLE,+)++# Unqualified, as in 0346, so the ALTER reaches the tables in the configured database. Positioned+# rather than appended, so the column order matches the declarative schema.+ADD_SOURCE_DETAIL = "ADD COLUMN IF NOT EXISTS source_detail String AFTER source_config_snapshot"++operations = [+ run_sql_with_exceptions(+ f"ALTER TABLE {SHARDED_PLATFORM_ALERT_EVENTS_TABLE} {ADD_SOURCE_DETAIL}",+ node_roles=[NodeRole.AUX],+ sharded=False,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ f"ALTER TABLE {PLATFORM_ALERT_EVENTS_TABLE} {ADD_SOURCE_DETAIL}",+ node_roles=[NodeRole.DATA, NodeRole.AUX],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex 9617b5833727..774f2a7b49ed 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0357_sharded_events_inserted_at_minmax_index+0358_platform_alert_events_source_detaildiff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex 078b4baccd5a..881d5b5e61a1 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -5955,6 +5955,7 @@labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,@@ -8443,6 +8444,7 @@labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,@@ -14293,6 +14295,7 @@labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,diff --git a/products/alerts_platform/backend/models/platform_alert_events_sql.py b/products/alerts_platform/backend/models/platform_alert_events_sql.pyindex e956268cc410..34a4ad35ab45 100644--- a/products/alerts_platform/backend/models/platform_alert_events_sql.py+++ b/products/alerts_platform/backend/models/platform_alert_events_sql.py@@ -29,6 +29,7 @@ BASE_PLATFORM_ALERT_EVENTS_COLUMNS = f"""labels Map(String, String),condition_snapshot String,source_config_snapshot String,+ source_detail String,query_duration_ms Nullable(UInt32),error_message String,consecutive_failures UInt32,