: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 the platform alert events table on the aux cluster (#107167)
Jimmy Zhu300f3cad578e
diff --git a/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl b/posthog/clickhouse/hcl/golden/dev/auxiliary.hclindex d5c6e23ce68d..4f63aa0bd560 100644--- a/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl@@ -1082,6 +1082,76 @@ database "posthog" {}}+ table "platform_alert_events" {+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_platform_alert_events"+ sharding_key = "cityHash64(team_id)"+ }+ }+table "property_values" {order_by = ["team_id", "property_type", "property_key", "property_value"]ttl = "last_seen + toIntervalDay(30)"@@ -2199,6 +2269,82 @@ database "posthog" {}}+ table "sharded_platform_alert_events" {+ primary_key = ["team_id", "configuration_id", "alert_id", "occurred_at"]+ order_by = ["team_id", "configuration_id", "alert_id", "occurred_at", "evaluation_key"]+ partition_by = "toYYYYMM(occurred_at)"+ ttl = "expires_at"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "replicated_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.platform_alert_events"+ replica_name = "{replica}-{shard}"+ }+ }+table "sharded_session_replay_features" {order_by = ["team_id", "session_id"]partition_by = "toYYYYMM(min_first_timestamp)"diff --git a/posthog/clickhouse/hcl/golden/dev/data.hcl b/posthog/clickhouse/hcl/golden/dev/data.hclindex daff69ead61b..2362a619da77 100644--- a/posthog/clickhouse/hcl/golden/dev/data.hcl+++ b/posthog/clickhouse/hcl/golden/dev/data.hcl@@ -2928,6 +2928,76 @@ database "posthog" {}}+ table "platform_alert_events" {+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_platform_alert_events"+ sharding_key = "cityHash64(team_id)"+ }+ }+table "plugin_log_entries" {order_by = ["team_id", "id"]partition_by = "plugin_id"diff --git a/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl b/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hclindex 2258bab23f1f..19c7a65d2c53 100644--- a/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl@@ -1125,6 +1125,76 @@ database "posthog" {}}+ table "platform_alert_events" {+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_platform_alert_events"+ sharding_key = "cityHash64(team_id)"+ }+ }+table "property_values" {order_by = ["team_id", "property_type", "property_key", "property_value"]ttl = "last_seen + toIntervalDay(30)"@@ -2206,6 +2276,82 @@ database "posthog" {}}+ table "sharded_platform_alert_events" {+ primary_key = ["team_id", "configuration_id", "alert_id", "occurred_at"]+ order_by = ["team_id", "configuration_id", "alert_id", "occurred_at", "evaluation_key"]+ partition_by = "toYYYYMM(occurred_at)"+ ttl = "expires_at"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "replicated_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.platform_alert_events"+ replica_name = "{replica}-{shard}"+ }+ }+table "sharded_session_replay_features" {order_by = ["team_id", "session_id"]partition_by = "toYYYYMM(min_first_timestamp)"diff --git a/posthog/clickhouse/hcl/golden/local-multi/data.hcl b/posthog/clickhouse/hcl/golden/local-multi/data.hclindex 46d8d2f38854..6f8d1c57f317 100644--- a/posthog/clickhouse/hcl/golden/local-multi/data.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/data.hcl@@ -3380,6 +3380,76 @@ database "posthog" {}}+ table "platform_alert_events" {+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_platform_alert_events"+ sharding_key = "cityHash64(team_id)"+ }+ }+table "plugin_log_entries" {order_by = ["team_id", "plugin_id", "plugin_config_id", "timestamp"]partition_by = "toYYYYMMDD(timestamp)"diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hclindex 69f1ddf7d752..2eebf020de57 100644--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl@@ -8614,6 +8614,76 @@ SQL}}+ table "platform_alert_events" {+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_platform_alert_events"+ sharding_key = "cityHash64(team_id)"+ }+ }+table "plugin_log_entries" {order_by = ["team_id", "plugin_id", "plugin_config_id", "timestamp"]partition_by = "toYYYYMMDD(timestamp)"@@ -12374,6 +12444,82 @@ SQL}}+ table "sharded_platform_alert_events" {+ primary_key = ["team_id", "configuration_id", "alert_id", "occurred_at"]+ order_by = ["team_id", "configuration_id", "alert_id", "occurred_at", "evaluation_key"]+ partition_by = "toYYYYMM(occurred_at)"+ ttl = "expires_at"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "replicated_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.platform_alert_events"+ replica_name = "{replica}-{shard}"+ }+ }+table "sharded_posthog_document_embeddings_buffer" {order_by = ["inserted_at", "model_name", "cityHash64(document_id)"]partition_by = "toDate(inserted_at)"diff --git a/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl b/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hclindex 593db5dfcb4f..47adb199dac0 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl@@ -1082,6 +1082,76 @@ database "posthog" {}}+ table "platform_alert_events" {+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_platform_alert_events"+ sharding_key = "cityHash64(team_id)"+ }+ }+table "property_values" {order_by = ["team_id", "property_type", "property_key", "property_value"]ttl = "last_seen + toIntervalDay(30)"@@ -2199,6 +2269,82 @@ database "posthog" {}}+ table "sharded_platform_alert_events" {+ primary_key = ["team_id", "configuration_id", "alert_id", "occurred_at"]+ order_by = ["team_id", "configuration_id", "alert_id", "occurred_at", "evaluation_key"]+ partition_by = "toYYYYMM(occurred_at)"+ ttl = "expires_at"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "replicated_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.platform_alert_events"+ replica_name = "{replica}-{shard}"+ }+ }+table "sharded_session_replay_features" {order_by = ["team_id", "session_id"]partition_by = "toYYYYMM(min_first_timestamp)"diff --git a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl b/posthog/clickhouse/hcl/golden/prod-eu/data.hclindex 6e29389aa76b..3395ee31f2b8 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl@@ -3689,6 +3689,76 @@ database "posthog" {}}+ table "platform_alert_events" {+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_platform_alert_events"+ sharding_key = "cityHash64(team_id)"+ }+ }+table "plugin_log_entries" {order_by = ["team_id", "plugin_id", "plugin_config_id", "timestamp"]partition_by = "toYYYYMMDD(timestamp)"diff --git a/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl b/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hclindex 8ed038f4545a..67837fb73f4b 100644--- a/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl@@ -1120,6 +1120,76 @@ database "posthog" {}}+ table "platform_alert_events" {+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_platform_alert_events"+ sharding_key = "cityHash64(team_id)"+ }+ }+table "property_values" {order_by = ["team_id", "property_type", "property_key", "property_value"]ttl = "last_seen + toIntervalDay(30)"@@ -2237,6 +2307,82 @@ database "posthog" {}}+ table "sharded_platform_alert_events" {+ primary_key = ["team_id", "configuration_id", "alert_id", "occurred_at"]+ order_by = ["team_id", "configuration_id", "alert_id", "occurred_at", "evaluation_key"]+ partition_by = "toYYYYMM(occurred_at)"+ ttl = "expires_at"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "replicated_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.platform_alert_events"+ replica_name = "{replica}-{shard}"+ }+ }+table "sharded_session_replay_features" {order_by = ["team_id", "session_id"]partition_by = "toYYYYMM(min_first_timestamp)"diff --git a/posthog/clickhouse/hcl/golden/prod-us/data.hcl b/posthog/clickhouse/hcl/golden/prod-us/data.hclindex 91bf08854756..ae59d2566f11 100644--- a/posthog/clickhouse/hcl/golden/prod-us/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/data.hcl@@ -3480,6 +3480,76 @@ database "posthog" {}}+ table "platform_alert_events" {+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_platform_alert_events"+ sharding_key = "cityHash64(team_id)"+ }+ }+table "plugin_log_entries" {order_by = ["team_id", "plugin_id", "plugin_config_id", "timestamp"]partition_by = "toYYYYMMDD(timestamp)"diff --git a/posthog/clickhouse/hcl/roles/auxiliary/shared/tables.hcl b/posthog/clickhouse/hcl/roles/auxiliary/shared/tables.hclindex 209ca10c6378..504572a42bd2 100644--- a/posthog/clickhouse/hcl/roles/auxiliary/shared/tables.hcl+++ b/posthog/clickhouse/hcl/roles/auxiliary/shared/tables.hcl@@ -382,6 +382,33 @@ database "posthog" {version_column = "computed_at"}}+ # A plain MergeTree because every row is a distinct check and nothing supersedes anything. The one+ # duplicate this table can see is a retried insert of an identical batch, which the replicated+ # engine drops through its own insert deduplication; the writer keys that explicitly. A+ # ReplacingMergeTree would instead make every count over the table wrong on any part a merge has+ # not reached, and ClickHouse never promises a merge will run.+ #+ # The sort key serves a source rebuilding an N-of-M window from the last rows of one alert, a+ # comparison scanning a team over a time range, and delivery resolving one evaluation under the+ # (team, configuration, alert) prefix plus the time bound it already holds.+ #+ # `expires_at` is insert time rather than `occurred_at` plus 90 days, so a backfill of old checks+ # does not land rows that are already expired.+ table "sharded_platform_alert_events" {+ order_by = ["team_id", "configuration_id", "alert_id", "occurred_at", "evaluation_key"]+ primary_key = ["team_id", "configuration_id", "alert_id", "occurred_at"]+ partition_by = "toYYYYMM(occurred_at)"+ ttl = "expires_at"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ extend = "_platform_alert_events_columns"+ engine "replicated_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.platform_alert_events"+ replica_name = "{replica}-{shard}"+ }+ }table "sharded_session_replay_features" {order_by = ["team_id", "session_id"]partition_by = "toYYYYMM(min_first_timestamp)"diff --git a/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hclindex 0de825bec977..17914b011b94 100644--- a/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hcl+++ b/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hcl@@ -324,6 +324,70 @@ database "posthog" {default = "today() + toIntervalDay(7)"}}+ table "_platform_alert_events_columns" {+ abstract = true+ column "team_id" {+ type = "Int64"+ }+ column "configuration_id" {+ type = "UUID"+ }+ column "alert_id" {+ type = "UUID"+ }+ column "grouping_key" {+ type = "String"+ }+ column "evaluation_key" {+ type = "String"+ }+ column "kind" {+ type = "LowCardinality(String)"+ }+ column "alert_name" {+ type = "String"+ }+ column "previous_state" {+ type = "LowCardinality(String)"+ }+ column "state" {+ type = "LowCardinality(String)"+ }+ column "episode_started_at" {+ type = "Nullable(DateTime64(6, 'UTC'))"+ }+ column "value" {+ type = "Nullable(Float64)"+ }+ column "labels" {+ type = "Map(String, String)"+ }+ column "condition_snapshot" {+ type = "String"+ }+ column "source_config_snapshot" {+ type = "String"+ }+ column "query_duration_ms" {+ type = "Nullable(UInt32)"+ }+ column "error_message" {+ type = "String"+ }+ column "consecutive_failures" {+ type = "UInt32"+ }+ column "muted_notification" {+ type = "LowCardinality(String)"+ }+ column "occurred_at" {+ type = "DateTime64(6, 'UTC')"+ }+ column "expires_at" {+ type = "Date"+ default = "today() + toIntervalDay(90)"+ }+ }table "_session_replay_features_columns" {abstract = truecolumn "session_id" {@@ -1196,6 +1260,15 @@ database "posthog" {remote_table = "message_assets_data"}}+ table "platform_alert_events" {+ extend = "_platform_alert_events_columns"+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_platform_alert_events"+ sharding_key = "cityHash64(team_id)"+ }+ }table "property_values_distributed" {column "team_id" {type = "Int64"diff --git a/posthog/clickhouse/hcl/sql/dev/auxiliary.sql b/posthog/clickhouse/hcl/sql/dev/auxiliary.sqlindex 6cfc9a9ec514..46acdebecd9c 100644--- a/posthog/clickhouse/hcl/sql/dev/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/dev/auxiliary.sql@@ -415,6 +415,28 @@ CREATE TABLE posthog.sharded_marketing_touchpoints_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at Date DEFAULT today() + toIntervalDay(7)) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.marketing_touchpoints_preaggregated', '{replica}-{shard}', computed_at) ORDER BY (team_id, job_id, person_id, touchpoint_timestamp) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.sharded_platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.platform_alert_events', '{replica}-{shard}') PRIMARY KEY (team_id, configuration_id, alert_id, occurred_at) ORDER BY (team_id, configuration_id, alert_id, occurred_at, evaluation_key) PARTITION BY toYYYYMM(occurred_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;CREATE TABLE posthog.sharded_session_replay_features (session_id String,team_id Int64,@@ -1222,6 +1244,28 @@ CREATE TABLE posthog.message_assets (_offset UInt64,_partition UInt64) ENGINE = Distributed('aux', 'posthog', 'message_assets_data');+CREATE TABLE posthog.platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = Distributed('aux', 'posthog', 'sharded_platform_alert_events', cityHash64(team_id));CREATE TABLE posthog.session_replay_features (session_id String,team_id Int64,diff --git a/posthog/clickhouse/hcl/sql/dev/data.sql b/posthog/clickhouse/hcl/sql/dev/data.sqlindex 5cee1830570d..7b8c36ddb5c2 100644--- a/posthog/clickhouse/hcl/sql/dev/data.sql+++ b/posthog/clickhouse/hcl/sql/dev/data.sql@@ -607,6 +607,28 @@ CREATE TABLE posthog.pg_embeddings (timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),is_deleted UInt8) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.pg_embeddings', '{replica}-{shard}', timestamp, is_deleted) ORDER BY (team_id, domain, id) SETTINGS index_granularity = 512;+CREATE TABLE posthog.platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = Distributed('aux', 'posthog', 'sharded_platform_alert_events', cityHash64(team_id));CREATE TABLE posthog.plugin_log_entries (id UUID,team_id Int64,diff --git a/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql b/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sqlindex 7d0caf9e65e1..615247d89815 100644--- a/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql@@ -419,6 +419,28 @@ CREATE TABLE posthog.sharded_marketing_touchpoints_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at Date DEFAULT today() + toIntervalDay(7)) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.marketing_touchpoints_preaggregated', '{replica}-{shard}', computed_at) ORDER BY (team_id, job_id, person_id, touchpoint_timestamp) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.sharded_platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.platform_alert_events', '{replica}-{shard}') PRIMARY KEY (team_id, configuration_id, alert_id, occurred_at) ORDER BY (team_id, configuration_id, alert_id, occurred_at, evaluation_key) PARTITION BY toYYYYMM(occurred_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;CREATE TABLE posthog.sharded_session_replay_features (session_id String,team_id Int64,@@ -1243,6 +1265,28 @@ CREATE TABLE posthog.message_assets (_offset UInt64,_partition UInt64) ENGINE = Distributed('aux', 'posthog', 'message_assets_data');+CREATE TABLE posthog.platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = Distributed('aux', 'posthog', 'sharded_platform_alert_events', cityHash64(team_id));CREATE TABLE posthog.session_replay_features (session_id String,team_id Int64,diff --git a/posthog/clickhouse/hcl/sql/local-multi/data.sql b/posthog/clickhouse/hcl/sql/local-multi/data.sqlindex d5bc2b3fbafe..1cd8fc33a520 100644--- a/posthog/clickhouse/hcl/sql/local-multi/data.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/data.sql@@ -631,6 +631,28 @@ CREATE TABLE posthog.pg_embeddings (timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),is_deleted UInt8) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.pg_embeddings', '{replica}-{shard}', timestamp, is_deleted) ORDER BY (team_id, domain, id) SETTINGS index_granularity = 512;+CREATE TABLE posthog.platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = Distributed('aux', 'posthog', 'sharded_platform_alert_events', cityHash64(team_id));CREATE TABLE posthog.plugin_log_entries (id UUID,team_id Int64,diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sqlindex b5ea01d5ba07..793dedb85673 100644--- a/posthog/clickhouse/hcl/sql/local-single/all.sql+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql@@ -2453,6 +2453,28 @@ CREATE TABLE posthog.sharded_performance_events (_offset UInt64,_partition UInt64) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/posthog.performance_events', '{replica}') ORDER BY (team_id, toDate(timestamp), session_id, pageview_id, timestamp) PARTITION BY toYYYYMM(timestamp) TTL toDate(timestamp) + toIntervalWeek(3) SETTINGS index_granularity = 8192;+CREATE TABLE posthog.sharded_platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.platform_alert_events', '{replica}-{shard}') PRIMARY KEY (team_id, configuration_id, alert_id, occurred_at) ORDER BY (team_id, configuration_id, alert_id, occurred_at, evaluation_key) PARTITION BY toYYYYMM(occurred_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;CREATE TABLE posthog.sharded_posthog_document_embeddings_buffer (team_id Int64,product LowCardinality(String),@@ -7128,6 +7150,28 @@ CREATE TABLE posthog.performance_events (_offset UInt64,_partition UInt64) ENGINE = Distributed('posthog', 'posthog', 'sharded_performance_events', sipHash64(session_id));+CREATE TABLE posthog.platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = Distributed('aux', 'posthog', 'sharded_platform_alert_events', cityHash64(team_id));CREATE TABLE posthog.preaggregation_results (team_id Int64,job_id UUID,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql b/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sqlindex e5a4d456a442..56447ae470df 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql@@ -415,6 +415,28 @@ CREATE TABLE posthog.sharded_marketing_touchpoints_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at Date DEFAULT today() + toIntervalDay(7)) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.marketing_touchpoints_preaggregated', '{replica}-{shard}', computed_at) ORDER BY (team_id, job_id, person_id, touchpoint_timestamp) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.sharded_platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.platform_alert_events', '{replica}-{shard}') PRIMARY KEY (team_id, configuration_id, alert_id, occurred_at) ORDER BY (team_id, configuration_id, alert_id, occurred_at, evaluation_key) PARTITION BY toYYYYMM(occurred_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;CREATE TABLE posthog.sharded_session_replay_features (session_id String,team_id Int64,@@ -1222,6 +1244,28 @@ CREATE TABLE posthog.message_assets (_offset UInt64,_partition UInt64) ENGINE = Distributed('aux', 'posthog', 'message_assets_data');+CREATE TABLE posthog.platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = Distributed('aux', 'posthog', 'sharded_platform_alert_events', cityHash64(team_id));CREATE TABLE posthog.session_replay_features (session_id String,team_id Int64,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/data.sql b/posthog/clickhouse/hcl/sql/prod-eu/data.sqlindex 67e0455564db..5b5c148e3a64 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/data.sql@@ -880,6 +880,28 @@ CREATE TABLE posthog.pg_embeddings (timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),is_deleted UInt8) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.pg_embeddings', '{replica}-{shard}', timestamp, is_deleted) ORDER BY (team_id, domain, id) SETTINGS index_granularity = 512;+CREATE TABLE posthog.platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = Distributed('aux', 'posthog', 'sharded_platform_alert_events', cityHash64(team_id));CREATE TABLE posthog.plugin_log_entries (id UUID,team_id Int64,diff --git a/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql b/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sqlindex 4e4f867005ee..7439b2059495 100644--- a/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql@@ -415,6 +415,28 @@ CREATE TABLE posthog.sharded_marketing_touchpoints_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at Date DEFAULT today() + toIntervalDay(7)) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.marketing_touchpoints_preaggregated', '{replica}-{shard}', computed_at) ORDER BY (team_id, job_id, person_id, touchpoint_timestamp) PARTITION BY toYYYYMMDD(expires_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.sharded_platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.platform_alert_events', '{replica}-{shard}') PRIMARY KEY (team_id, configuration_id, alert_id, occurred_at) ORDER BY (team_id, configuration_id, alert_id, occurred_at, evaluation_key) PARTITION BY toYYYYMM(occurred_at) TTL expires_at SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;CREATE TABLE posthog.sharded_session_replay_features (session_id String,team_id Int64,@@ -1232,6 +1254,28 @@ CREATE TABLE posthog.message_assets (_offset UInt64,_partition UInt64) ENGINE = Distributed('aux', 'posthog', 'message_assets_data');+CREATE TABLE posthog.platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = Distributed('aux', 'posthog', 'sharded_platform_alert_events', cityHash64(team_id));CREATE TABLE posthog.session_replay_features (session_id String,team_id Int64,diff --git a/posthog/clickhouse/hcl/sql/prod-us/data.sql b/posthog/clickhouse/hcl/sql/prod-us/data.sqlindex fe4478e6ba78..e8399202c44b 100644--- a/posthog/clickhouse/hcl/sql/prod-us/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/data.sql@@ -749,6 +749,28 @@ CREATE TABLE posthog.pg_embeddings (timestamp DateTime64(6, 'UTC') DEFAULT now('UTC'),is_deleted UInt8) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.pg_embeddings', '{replica}-{shard}', timestamp, is_deleted) ORDER BY (team_id, domain, id) SETTINGS default_compression_codec = 'lz4', index_granularity = 512;+CREATE TABLE posthog.platform_alert_events (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+) ENGINE = Distributed('aux', 'posthog', 'sharded_platform_alert_events', cityHash64(team_id));CREATE TABLE posthog.plugin_log_entries (id UUID,team_id Int64,diff --git a/posthog/clickhouse/migrations/0339_platform_alert_events.py b/posthog/clickhouse/migrations/0339_platform_alert_events.pynew file mode 100644index 000000000000..37b69b48621f--- /dev/null+++ b/posthog/clickhouse/migrations/0339_platform_alert_events.py@@ -0,0 +1,20 @@+"""AUTO-GENERATED from the declarative HCL by posthog/clickhouse/hcl/codegen/gen_migration.py.+Placement (node_roles) is derived from the node composition manifest; review before committing.++Edited after generation to build the DDL from the Python definitions rather than the literal SQL+the generator emits. The generator qualifies every name with the database the HCL declares, which+is `posthog` on the aux role, and a test or local ClickHouse runs under a different database.+"""++from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions++from products.alerts.backend.models.platform_alert_events_sql import (+ DISTRIBUTED_PLATFORM_ALERT_EVENTS_TABLE_SQL,+ SHARDED_PLATFORM_ALERT_EVENTS_TABLE_SQL,+)++operations = [+ run_sql_with_exceptions(SHARDED_PLATFORM_ALERT_EVENTS_TABLE_SQL(), node_roles=[NodeRole.AUX]),+ run_sql_with_exceptions(DISTRIBUTED_PLATFORM_ALERT_EVENTS_TABLE_SQL(), node_roles=[NodeRole.DATA, NodeRole.AUX]),+]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex 2ca49bab44b4..a59999076869 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0338_drop_person_property_mutation_log+0339_platform_alert_eventsdiff --git a/posthog/clickhouse/schema.py b/posthog/clickhouse/schema.pyindex 20790058ed29..cf2393391fd7 100644--- a/posthog/clickhouse/schema.py+++ b/posthog/clickhouse/schema.py@@ -381,6 +381,10 @@ from posthog.session_recordings.sql.session_replay_feature_sql import (WRITABLE_SESSION_REPLAY_FEATURES_TABLE_SQL,)+from products.alerts.backend.models.platform_alert_events_sql import (+ DISTRIBUTED_PLATFORM_ALERT_EVENTS_TABLE_SQL,+ SHARDED_PLATFORM_ALERT_EVENTS_TABLE_SQL,+)from products.cohorts.backend.models.sql import CREATE_COHORTPEOPLE_TABLE_SQLfrom products.error_tracking.backend.embedding import (DISTRIBUTED_DOCUMENT_EMBEDDINGS_TABLE_SQL,@@ -411,6 +415,7 @@ from products.event_definitions.backend.models.property_definition import PROPER# Queries to create tables, you must pass function, otherwise the table is created before# objects are mocked and the ambr will go into infinite loop update.CREATE_MERGETREE_TABLE_QUERIES = (+ SHARDED_PLATFORM_ALERT_EVENTS_TABLE_SQL,LOG_ENTRIES_TABLE_SQL,LOG_ENTRIES_DATA_TABLE_SQL,CREATE_COHORTPEOPLE_TABLE_SQL,@@ -509,6 +514,7 @@ CREATE_MERGETREE_TABLE_QUERIES = (DMAT_SLOT_ASSIGNMENTS_TABLE_SQL,)CREATE_DISTRIBUTED_TABLE_QUERIES = (+ DISTRIBUTED_PLATFORM_ALERT_EVENTS_TABLE_SQL,LOG_ENTRIES_AUX_DISTRIBUTED_TABLE_SQL,LOG_ENTRIES_AUX_WRITABLE_TABLE_SQL,WRITABLE_EVENTS_TABLE_SQL,diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex 21abc1611246..c759eb0c725d 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -5895,6 +5895,36 @@'''# ---+# name: test_create_table_query[platform_alert_events]+ '''++ CREATE TABLE IF NOT EXISTS platform_alert_events+ (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+ )+ ENGINE = Distributed('aux', 'posthog_test', 'sharded_platform_alert_events', cityHash64(team_id))++ '''+# ---# name: test_create_table_query[plugin_log_entries]'''@@ -8330,6 +8360,41 @@+ '''+# ---+# name: test_create_table_query[sharded_platform_alert_events]+ '''++ CREATE TABLE IF NOT EXISTS sharded_platform_alert_events+ (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+ )+ ENGINE = ReplicatedMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.platform_alert_events', '{replica}-{shard}')+ ORDER BY (team_id, configuration_id, alert_id, occurred_at, evaluation_key)+ PRIMARY KEY (team_id, configuration_id, alert_id, occurred_at)+ PARTITION BY toYYYYMM(occurred_at)+ TTL expires_at+ SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1+'''# ---# name: test_create_table_query[sharded_posthog_document_embeddings_buffer]@@ -13988,6 +14053,41 @@'''# ---+# name: test_create_table_query_replicated_and_storage[sharded_platform_alert_events]+ '''++ CREATE TABLE IF NOT EXISTS sharded_platform_alert_events+ (+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay(90)+ )+ ENGINE = ReplicatedMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.platform_alert_events', '{replica}-{shard}')+ ORDER BY (team_id, configuration_id, alert_id, occurred_at, evaluation_key)+ PRIMARY KEY (team_id, configuration_id, alert_id, occurred_at)+ PARTITION BY toYYYYMM(occurred_at)+ TTL expires_at+ SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1++ '''+# ---# name: test_create_table_query_replicated_and_storage[sharded_posthog_document_embeddings_buffer]'''diff --git a/products/alerts/backend/models/platform_alert_events_sql.py b/products/alerts/backend/models/platform_alert_events_sql.pynew file mode 100644index 000000000000..a46ce604afd8--- /dev/null+++ b/products/alerts/backend/models/platform_alert_events_sql.py@@ -0,0 +1,90 @@+"""ClickHouse schema for the shared alerts platform's check history.++One row per check, written by the platform's record activity. The Python definitions here mirror+the declarative schema in `posthog/clickhouse/hcl/`, which is the source of truth; these exist so+`posthog/clickhouse/schema.py` can build the table in a local or test ClickHouse.+"""++from django.conf import settings++from posthog.clickhouse.table_engines import Distributed, MergeTreeEngine, ReplicationScheme++PLATFORM_ALERT_EVENTS_TABLE = "platform_alert_events"+SHARDED_PLATFORM_ALERT_EVENTS_TABLE = f"sharded_{PLATFORM_ALERT_EVENTS_TABLE}"++PLATFORM_ALERT_EVENTS_TTL_DAYS = 90++BASE_PLATFORM_ALERT_EVENTS_COLUMNS = f"""+ team_id Int64,+ configuration_id UUID,+ alert_id UUID,+ grouping_key String,+ evaluation_key String,+ kind LowCardinality(String),+ alert_name String,+ previous_state LowCardinality(String),+ state LowCardinality(String),+ episode_started_at Nullable(DateTime64(6, 'UTC')),+ value Nullable(Float64),+ labels Map(String, String),+ condition_snapshot String,+ source_config_snapshot String,+ query_duration_ms Nullable(UInt32),+ error_message String,+ consecutive_failures UInt32,+ muted_notification LowCardinality(String),+ occurred_at DateTime64(6, 'UTC'),+ expires_at Date DEFAULT today() + toIntervalDay({PLATFORM_ALERT_EVENTS_TTL_DAYS})+""".strip()+++def platform_alert_events_table_engine() -> MergeTreeEngine:+ # REPLICATED, not SHARDED: aux is a single shard with replicas, and this is the scheme whose+ # ZooKeeper path matches what the declarative schema declares for this table.+ return MergeTreeEngine(+ PLATFORM_ALERT_EVENTS_TABLE,+ replication_scheme=ReplicationScheme.REPLICATED,+ )+++def SHARDED_PLATFORM_ALERT_EVENTS_TABLE_SQL() -> str:+ # A plain MergeTree because every row is a distinct check and nothing supersedes anything. The+ # one duplicate this table can see is a retried insert of an identical batch, which the+ # replicated engine drops through its own insert deduplication; the writer keys that+ # explicitly. A ReplacingMergeTree would instead make every count over the table wrong on any+ # part a merge has not reached, and ClickHouse never promises a merge will run.+ #+ # `expires_at` is insert time rather than `occurred_at` plus the TTL, so a backfill of old+ # checks does not land rows that are already expired. Rows in one part then expire together,+ # which is what makes `ttl_only_drop_parts` a part drop rather than a rewrite of every column.+ #+ # The sort key is declared in the HCL, which is the source of truth; the rationale for its+ # shape lives there.+ return f"""+CREATE TABLE IF NOT EXISTS {SHARDED_PLATFORM_ALERT_EVENTS_TABLE}+(+ {BASE_PLATFORM_ALERT_EVENTS_COLUMNS}+)+ENGINE = {platform_alert_events_table_engine()}+ORDER BY (team_id, configuration_id, alert_id, occurred_at, evaluation_key)+PRIMARY KEY (team_id, configuration_id, alert_id, occurred_at)+PARTITION BY toYYYYMM(occurred_at)+TTL expires_at+SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1+"""+++def DISTRIBUTED_PLATFORM_ALERT_EVENTS_TABLE_SQL() -> str:+ return f"""+CREATE TABLE IF NOT EXISTS {PLATFORM_ALERT_EVENTS_TABLE}+(+ {BASE_PLATFORM_ALERT_EVENTS_COLUMNS}+)+ENGINE = {+ Distributed(+ data_table=SHARDED_PLATFORM_ALERT_EVENTS_TABLE,+ sharding_key="cityHash64(team_id)",+ cluster=settings.CLICKHOUSE_AUX_CLUSTER,+ )+ }+"""