Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(clickhouse): drop precalculated warpstream kafka engine tables (#79807)

Gustavo H. Strassburger06cf6d75f9c9
diff --git a/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hcl b/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hcl
index 9fa68e5c3f17..0d25a95d3bc4 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hcl
@@ -286,39 +286,6 @@ database "posthog" {
}
}
- table "kafka_precalculated_person_properties_ws" {
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "condition" {
- type = "String"
- }
- column "matches" {
- type = "Bool"
- }
- column "source" {
- type = "String"
- }
- engine "kafka" {
- broker_list = "warpstream_calculated_events"
- topic_list = "kafka_topic_list = 'clickhouse_precalculated_person_properties'"
- group_name = "kafka_group_name = 'clickhouse_precalculated_person_properties_ws'"
- format = "kafka_format = 'JSONEachRow'"
- num_consumers = 1
- max_block_size = 1000000
- skip_broken_messages = 100
- poll_timeout_ms = 1000
- poll_max_batch_size = 100000
- flush_interval_ms = 7500
- }
- }
-
table "kafka_session_replay_features" {
column "session_id" {
type = "String"
@@ -1889,47 +1856,6 @@ SQL
}
}
- materialized_view "precalculated_person_properties_ws_mv" {
- to_table = "posthog.writable_precalculated_person_properties"
- query = <<SQL
-SELECT
- team_id,
- distinct_id,
- person_id,
- condition,
- matches,
- source,
- _timestamp,
- _offset
-FROM posthog.kafka_precalculated_person_properties_ws
-SQL
-
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "condition" {
- type = "String"
- }
- column "matches" {
- type = "Bool"
- }
- column "source" {
- type = "String"
- }
- column "_timestamp" {
- type = "Nullable(DateTime)"
- }
- column "_offset" {
- type = "UInt64"
- }
- }
-
materialized_view "session_replay_features_mv" {
to_table = "posthog.writable_session_replay_features"
query = <<SQL
diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hcl
index 13581c1886cf..c72ad6995a7c 100644
--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl
+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl
@@ -3904,39 +3904,6 @@ database "posthog" {
}
}
- table "kafka_precalculated_person_properties_ws" {
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "condition" {
- type = "String"
- }
- column "matches" {
- type = "Bool"
- }
- column "source" {
- type = "String"
- }
- engine "kafka" {
- broker_list = "warpstream_calculated_events"
- topic_list = "kafka_topic_list = 'clickhouse_precalculated_person_properties'"
- group_name = "kafka_group_name = 'clickhouse_precalculated_person_properties_ws'"
- format = "kafka_format = 'JSONEachRow'"
- num_consumers = 1
- max_block_size = 1000000
- skip_broken_messages = 100
- poll_timeout_ms = 1000
- poll_max_batch_size = 100000
- flush_interval_ms = 7500
- }
- }
-
table "kafka_property_values" {
column "team_id" {
type = "Int64"
@@ -20825,47 +20792,6 @@ SQL
}
}
- materialized_view "precalculated_person_properties_ws_mv" {
- to_table = "posthog.writable_precalculated_person_properties"
- query = <<SQL
-SELECT
- team_id,
- distinct_id,
- person_id,
- condition,
- matches,
- source,
- _timestamp,
- _offset
-FROM posthog.kafka_precalculated_person_properties_ws
-SQL
-
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "condition" {
- type = "String"
- }
- column "matches" {
- type = "Bool"
- }
- column "source" {
- type = "String"
- }
- column "_timestamp" {
- type = "Nullable(DateTime)"
- }
- column "_offset" {
- type = "UInt64"
- }
- }
-
materialized_view "property_values_mv" {
to_table = "posthog.property_values"
query = <<SQL
diff --git a/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hcl b/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hcl
index 5258fe6d7810..d9f24bcd9eaa 100644
--- a/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hcl
@@ -286,39 +286,6 @@ database "posthog" {
}
}
- table "kafka_precalculated_person_properties_ws" {
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "condition" {
- type = "String"
- }
- column "matches" {
- type = "Bool"
- }
- column "source" {
- type = "String"
- }
- engine "kafka" {
- broker_list = "warpstream_calculated_events"
- topic_list = "kafka_topic_list = 'clickhouse_precalculated_person_properties'"
- group_name = "kafka_group_name = 'clickhouse_precalculated_person_properties_ws'"
- format = "kafka_format = 'JSONEachRow'"
- num_consumers = 1
- max_block_size = 1000000
- skip_broken_messages = 100
- poll_timeout_ms = 1000
- poll_max_batch_size = 100000
- flush_interval_ms = 7500
- }
- }
-
table "kafka_session_replay_features" {
column "session_id" {
type = "String"
@@ -1540,47 +1507,6 @@ SQL
}
}
- materialized_view "precalculated_person_properties_ws_mv" {
- to_table = "posthog.writable_precalculated_person_properties"
- query = <<SQL
-SELECT
- team_id,
- distinct_id,
- person_id,
- condition,
- matches,
- source,
- _timestamp,
- _offset
-FROM posthog.kafka_precalculated_person_properties_ws
-SQL
-
- column "team_id" {
- type = "Int64"
- }
- column "distinct_id" {
- type = "String"
- }
- column "person_id" {
- type = "UUID"
- }
- column "condition" {
- type = "String"
- }
- column "matches" {
- type = "Bool"
- }
- column "source" {
- type = "String"
- }
- column "_timestamp" {
- type = "Nullable(DateTime)"
- }
- column "_offset" {
- type = "UInt64"
- }
- }
-
materialized_view "session_replay_features_mv" {
to_table = "posthog.writable_session_replay_features"
query = <<SQL
diff --git a/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sql b/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sql
index e000c9753c4d..b396f20b55b0 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sql
@@ -81,14 +81,6 @@ CREATE TABLE posthog.kafka_precalculated_person_properties (
matches Bool,
source String
) ENGINE = Kafka() SETTINGS kafka_broker_list = 'msk_cluster', kafka_flush_interval_ms = 7500, kafka_format = 'kafka_format = \'JSONEachRow\'', kafka_group_name = 'kafka_group_name = \'clickhouse_precalculated_person_properties\'', kafka_max_block_size = 1000000, kafka_num_consumers = 1, kafka_poll_max_batch_size = 100000, kafka_poll_timeout_ms = 1000, kafka_skip_broken_messages = 100, kafka_topic_list = 'kafka_topic_list = \'clickhouse_precalculated_person_properties\'';
-CREATE TABLE posthog.kafka_precalculated_person_properties_ws (
- team_id Int64,
- distinct_id String,
- person_id UUID,
- condition String,
- matches Bool,
- source String
-) ENGINE = Kafka() SETTINGS kafka_broker_list = 'warpstream_calculated_events', kafka_flush_interval_ms = 7500, kafka_format = 'kafka_format = \'JSONEachRow\'', kafka_group_name = 'kafka_group_name = \'clickhouse_precalculated_person_properties_ws\'', kafka_max_block_size = 1000000, kafka_num_consumers = 1, kafka_poll_max_batch_size = 100000, kafka_poll_timeout_ms = 1000, kafka_skip_broken_messages = 100, kafka_topic_list = 'kafka_topic_list = \'clickhouse_precalculated_person_properties\'';
CREATE TABLE posthog.kafka_session_replay_features (
session_id String,
team_id Int64,
@@ -537,16 +529,6 @@ CREATE MATERIALIZED VIEW posthog.precalculated_person_properties_mv TO posthog.w
_timestamp,
_offset
FROM posthog.kafka_precalculated_person_properties;
-CREATE MATERIALIZED VIEW posthog.precalculated_person_properties_ws_mv TO posthog.writable_precalculated_person_properties (team_id Int64, distinct_id String, person_id UUID, condition String, matches Bool, source String, _timestamp Nullable(DateTime), _offset UInt64) AS SELECT
- team_id,
- distinct_id,
- person_id,
- condition,
- matches,
- source,
- _timestamp,
- _offset
-FROM posthog.kafka_precalculated_person_properties_ws;
CREATE MATERIALIZED VIEW posthog.session_replay_features_mv TO posthog.writable_session_replay_features (session_id String, team_id Int64, distinct_id String, min_first_timestamp DateTime64(6, 'UTC'), max_last_timestamp DateTime64(6, 'UTC'), event_count Int64, mouse_position_count Int64, mouse_sum_x Float64, mouse_sum_x_squared Float64, mouse_sum_y Float64, mouse_sum_y_squared Float64, mouse_distance_traveled Float64, mouse_direction_change_count Int64, mouse_velocity_sum Float64, mouse_velocity_sum_of_squares Float64, mouse_velocity_count Int64, scroll_event_count Int64, total_scroll_magnitude Float64, scroll_direction_reversal_count Int64, rapid_scroll_reversal_count Int64, scroll_to_top_count Int64, click_count Int64, keypress_count Int64, mouse_activity_count Int64, rage_click_count Int64, dead_click_count Int64, backspace_count Int64, inter_action_gap_count Int64, inter_action_gap_sum_ms Float64, inter_action_gap_sum_of_squares_ms Float64, max_idle_gap_ms Float64, long_idle_gap_count Int64, quick_back_count Int64, page_visit_count Int64, unique_url_count AggregateFunction(uniqCombinedArray(12), Array(String)), login_path_visit_count Int64, signup_path_visit_count Int64, checkout_path_visit_count Int64, cart_path_visit_count Int64, billing_path_visit_count Int64, settings_path_visit_count Int64, account_path_visit_count Int64, error_path_visit_count Int64, not_found_path_visit_count Int64, admin_path_visit_count Int64, dashboard_path_visit_count Int64, onboarding_path_visit_count Int64, cancel_path_visit_count Int64, refund_path_visit_count Int64, console_error_count Int64, console_error_after_click_count Int64, console_warn_count Int64, network_request_count Int64, network_failed_request_count Int64, network_4xx_count Int64, network_5xx_count Int64, network_request_duration_sum Float64, network_request_duration_sum_of_squares Float64, network_request_duration_count Int64, mutation_count Int64, viewport_resize_count Int64, touch_event_count Int64, max_scroll_y Float64, unique_click_target_count AggregateFunction(uniqCombinedArray(12), Array(Int64)), unique_form_field_count AggregateFunction(uniqCombinedArray(12), Array(Int64)), text_selection_count Int64, selection_copy_count Int64, is_deleted UInt8) AS SELECT
session_id,
team_id,
diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sql
index d006b09a1d0f..c259527c8945 100644
--- a/posthog/clickhouse/hcl/sql/local-single/all.sql
+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql
@@ -695,14 +695,6 @@ CREATE TABLE posthog.kafka_precalculated_person_properties (
matches Bool,
source String
) ENGINE = Kafka() SETTINGS kafka_broker_list = 'msk_cluster', kafka_flush_interval_ms = 7500, kafka_format = 'kafka_format = \'JSONEachRow\'', kafka_group_name = 'kafka_group_name = \'clickhouse_precalculated_person_properties\'', kafka_max_block_size = 1000000, kafka_num_consumers = 1, kafka_poll_max_batch_size = 100000, kafka_poll_timeout_ms = 1000, kafka_skip_broken_messages = 100, kafka_topic_list = 'kafka_topic_list = \'clickhouse_precalculated_person_properties\'';
-CREATE TABLE posthog.kafka_precalculated_person_properties_ws (
- team_id Int64,
- distinct_id String,
- person_id UUID,
- condition String,
- matches Bool,
- source String
-) ENGINE = Kafka() SETTINGS kafka_broker_list = 'warpstream_calculated_events', kafka_flush_interval_ms = 7500, kafka_format = 'kafka_format = \'JSONEachRow\'', kafka_group_name = 'kafka_group_name = \'clickhouse_precalculated_person_properties_ws\'', kafka_max_block_size = 1000000, kafka_num_consumers = 1, kafka_poll_max_batch_size = 100000, kafka_poll_timeout_ms = 1000, kafka_skip_broken_messages = 100, kafka_topic_list = 'kafka_topic_list = \'clickhouse_precalculated_person_properties\'';
CREATE TABLE posthog.kafka_property_values (
team_id Int64,
property_type LowCardinality(String),
@@ -4835,16 +4827,6 @@ CREATE MATERIALIZED VIEW posthog.precalculated_person_properties_mv TO posthog.w
_timestamp,
_offset
FROM posthog.kafka_precalculated_person_properties;
-CREATE MATERIALIZED VIEW posthog.precalculated_person_properties_ws_mv TO posthog.writable_precalculated_person_properties (team_id Int64, distinct_id String, person_id UUID, condition String, matches Bool, source String, _timestamp Nullable(DateTime), _offset UInt64) AS SELECT
- team_id,
- distinct_id,
- person_id,
- condition,
- matches,
- source,
- _timestamp,
- _offset
-FROM posthog.kafka_precalculated_person_properties_ws;
CREATE MATERIALIZED VIEW posthog.property_values_mv TO posthog.property_values (team_id Int64, property_type LowCardinality(String), property_key String, property_value String, property_count UInt64, last_seen DateTime) AS SELECT
team_id,
property_type,
diff --git a/posthog/clickhouse/migrations/0308_drop_warpstream_calculated_events_kafka_engines.py b/posthog/clickhouse/migrations/0308_drop_warpstream_calculated_events_kafka_engines.py
new file mode 100644
index 000000000000..26db9efbcc20
--- /dev/null
+++ b/posthog/clickhouse/migrations/0308_drop_warpstream_calculated_events_kafka_engines.py
@@ -0,0 +1,56 @@
+from posthog.clickhouse.client.connection import NodeRole
+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
+from posthog.models.precalculated_events.sql import (
+ DROP_PRECALCULATED_EVENTS_WS_KAFKA_TABLE_SQL,
+ DROP_PRECALCULATED_EVENTS_WS_MV_SQL,
+)
+from posthog.models.precalculated_person_properties.sql import (
+ DROP_PRECALCULATED_PERSON_PROPERTIES_WS_KAFKA_TABLE_SQL,
+ DROP_PRECALCULATED_PERSON_PROPERTIES_WS_MV_SQL,
+)
+
+# Drop the two precalculated Kafka engine tables bound to the
+# `warpstream_calculated_events` named collection, on the way to decommissioning that
+# cluster:
+#
+# clickhouse_prefiltered_events -> kafka_precalculated_events_ws
+# clickhouse_precalculated_person_properties -> kafka_precalculated_person_properties_ws
+#
+# On cloud neither topic has a producer any more, so all four objects read nothing.
+# They have to go before the named collection is removed from the ClickHouse config: a
+# Kafka engine table whose named collection has disappeared error-loops on every poll.
+#
+# Within each pair the MV is dropped first so it stops feeding its writable table, then
+# the Kafka engine table.
+#
+# Both pairs were created unconditionally by 0229, so both drops are unconditional. 0243
+# then dropped the events pair everywhere and recreated it cloud-only, because off-cloud
+# the `warpstream_calculated_events` collection resolves to the same brokers as
+# `msk_cluster` and the pair double-writes. It left
+# `kafka_precalculated_person_properties_ws` behind, which this drop finally removes.
+#
+# `kafka_cohort_membership_ws` reads from the same collection but is deliberately left
+# in place here; it is dropped separately.
+#
+# Only the Kafka engine tables and their MVs go. The `precalculated_events` and
+# `precalculated_person_properties` data tables stay, as do the MSK-fed Kafka tables that
+# do not resolve this named collection.
+
+operations = [
+ run_sql_with_exceptions(
+ DROP_PRECALCULATED_EVENTS_WS_MV_SQL(),
+ node_roles=[NodeRole.INGESTION_MEDIUM],
+ ),
+ run_sql_with_exceptions(
+ DROP_PRECALCULATED_EVENTS_WS_KAFKA_TABLE_SQL(),
+ node_roles=[NodeRole.INGESTION_MEDIUM],
+ ),
+ run_sql_with_exceptions(
+ DROP_PRECALCULATED_PERSON_PROPERTIES_WS_MV_SQL(),
+ node_roles=[NodeRole.INGESTION_MEDIUM],
+ ),
+ run_sql_with_exceptions(
+ DROP_PRECALCULATED_PERSON_PROPERTIES_WS_KAFKA_TABLE_SQL(),
+ node_roles=[NodeRole.INGESTION_MEDIUM],
+ ),
+]
diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txt
index 8ce74c420526..28444bcdb79c 100644
--- a/posthog/clickhouse/migrations/max_migration.txt
+++ b/posthog/clickhouse/migrations/max_migration.txt
@@ -1 +1 @@
-0307_logs_pattern_kafka
+0308_drop_warpstream_calculated_events_kafka_engines