: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
chore(clickhouse): drop COORDINATOR node role (#59365)
Paweł Szczur083833aaffb3
diff --git a/posthog/clickhouse/client/connection.py b/posthog/clickhouse/client/connection.pyindex e41698171c4f..02c05105a35c 100644--- a/posthog/clickhouse/client/connection.py+++ b/posthog/clickhouse/client/connection.py@@ -24,7 +24,6 @@ class NodeRole(StrEnum):# Roles of nodes for a particular NodeType. These are meant to# match the CH macro hostClusterRoleALL = "all"- COORDINATOR = "coordinator"DATA = "data"INGESTION_EVENTS = "events"INGESTION_SMALL = "small"diff --git a/posthog/clickhouse/test/test_cluster.py b/posthog/clickhouse/test/test_cluster.pyindex 9cffa52f876f..67d25a0bbf5d 100644--- a/posthog/clickhouse/test/test_cluster.py+++ b/posthog/clickhouse/test/test_cluster.py@@ -377,7 +377,7 @@ def test_map_hosts_by_role() -> None:("host1", "9000", "1", "1", "online", "data"),("host2", "9000", "1", "2", "online", "data"),("host3", "9000", "1", "3", "offline", "data"),- ("host4", "9000", "1", "4", "online", "coordinator"),+ ("host4", "9000", "1", "4", "online", "endpoints"),]cluster = ClickhouseCluster(bootstrap_client_mock)@@ -387,41 +387,41 @@ def test_map_hosts_by_role() -> None:def mock_get_task_function(_, host: HostInfo, fn: Callable[[Client], T]) -> Callable[[], T]:if host.host_cluster_role == NodeRole.DATA.value.lower():times_called[NodeRole.DATA] += 1- elif host.host_cluster_role == NodeRole.COORDINATOR.value.lower():- times_called[NodeRole.COORDINATOR] += 1+ elif host.host_cluster_role == NodeRole.ENDPOINTS.value.lower():+ times_called[NodeRole.ENDPOINTS] += 1return lambda: fn(Mock())with patch.object(ClickhouseCluster, "_ClickhouseCluster__get_task_function", mock_get_task_function):cluster.map_hosts_by_role(lambda _: (), node_role=NodeRole.DATA).result()assert times_called[NodeRole.DATA] == 3- assert times_called[NodeRole.COORDINATOR] == 0+ assert times_called[NodeRole.ENDPOINTS] == 0times_called.clear()- cluster.map_hosts_by_role(lambda _: (), node_role=NodeRole.COORDINATOR).result()+ cluster.map_hosts_by_role(lambda _: (), node_role=NodeRole.ENDPOINTS).result()assert times_called[NodeRole.DATA] == 0- assert times_called[NodeRole.COORDINATOR] == 1+ assert times_called[NodeRole.ENDPOINTS] == 1times_called.clear()cluster.map_hosts_by_role(lambda _: (), node_role=NodeRole.ALL).result()assert times_called[NodeRole.DATA] == 3- assert times_called[NodeRole.COORDINATOR] == 1+ assert times_called[NodeRole.ENDPOINTS] == 1times_called.clear()cluster.map_hosts_by_role(lambda _: (), node_role=NodeRole.ALL, workload=Workload.OFFLINE).result()assert times_called[NodeRole.DATA] == 1- assert times_called[NodeRole.COORDINATOR] == 0+ assert times_called[NodeRole.ENDPOINTS] == 0times_called.clear()cluster.map_hosts_by_role(lambda _: (), node_role=NodeRole.DATA, workload=Workload.ONLINE).result()assert times_called[NodeRole.DATA] == 2- assert times_called[NodeRole.COORDINATOR] == 0+ assert times_called[NodeRole.ENDPOINTS] == 0times_called.clear()def test_map_hosts_with_satellite_clusters() -> None:main_cluster_hosts = [("host1", "9000", "1", "1", "online", "data"),- ("host2", "9000", "1", "2", "online", "coordinator"),+ ("host2", "9000", "1", "2", "online", "endpoints"),]aux_cluster_hosts = [("aux-host1", "9000", "1", "1", "online", "aux"),@@ -470,7 +470,7 @@ def test_map_hosts_with_satellite_clusters() -> None:cluster.map_hosts_by_role(lambda _: (), node_role=NodeRole.ALL).result()assert times_called["data"] == 1- assert times_called["coordinator"] == 1+ assert times_called["endpoints"] == 1assert times_called["aux"] == 2assert times_called["sessions"] == 1times_called.clear()@@ -511,7 +511,7 @@ def test_data_cluster_overrides_migrations_cluster_data_nodes() -> None:# posthog_migrations has incomplete DATA — only 1 shardmigrations_cluster_hosts = [("data-partial", "9000", "1", "1", "online", "data"),- ("coordinator-1", "9000", "1", "2", "online", "coordinator"),+ ("endpoints-1", "9000", "1", "2", "online", "endpoints"),]# posthog has the full topology — 3 shardsdata_cluster_hosts = [@@ -540,7 +540,7 @@ def test_data_cluster_overrides_migrations_cluster_data_nodes() -> None:# Should have 3 shards from posthog, not 1 from posthog_migrationsassert cluster.num_shards == 3- # Coordinator from posthog_migrations should still be in extra_hosts+ # Host only present in posthog_migrations should still be in extra_hostsexecuted_roles: list[str] = []def mock_get_task_function(_, host: HostInfo, fn: Callable[[Client], T]) -> Callable[[], T]:@@ -552,8 +552,8 @@ def test_data_cluster_overrides_migrations_cluster_data_nodes() -> None:assert executed_roles.count("data") == 4 # all 4 DATA nodes from posthogexecuted_roles.clear()- cluster.map_hosts_by_role(lambda _: (), node_role=NodeRole.COORDINATOR).result()- assert executed_roles.count("coordinator") == 1 # still from posthog_migrations+ cluster.map_hosts_by_role(lambda _: (), node_role=NodeRole.ENDPOINTS).result()+ assert executed_roles.count("endpoints") == 1 # still from posthog_migrationsdef test_data_cluster_same_as_migrations_cluster_is_noop() -> None:diff --git a/posthog/models/raw_sessions/migrations.py b/posthog/models/raw_sessions/migrations.pyindex ff2d978b9a9b..581862ec4741 100644--- a/posthog/models/raw_sessions/migrations.py+++ b/posthog/models/raw_sessions/migrations.py@@ -39,7 +39,7 @@ def update_raw_sessions_table(migration: str):table_name=TABLE_BASE_NAME,on_cluster_clause=ON_CLUSTER_CLAUSE(on_cluster=False),),- node_roles=[NodeRole.DATA, NodeRole.COORDINATOR],+ node_roles=[NodeRole.DATA],),# recreate the viewrun_sql_with_exceptions(RAW_SESSIONS_CREATE_OR_REPLACE_VIEW_SQL()),diff --git a/products/web_analytics/dags/web_preaggregated_utils.py b/products/web_analytics/dags/web_preaggregated_utils.pyindex 017b40575f12..cc6a50e329e8 100644--- a/products/web_analytics/dags/web_preaggregated_utils.py+++ b/products/web_analytics/dags/web_preaggregated_utils.py@@ -75,7 +75,7 @@ def get_partitions(partition_query += f" AND partition >= '{start_partition}' AND partition < '{end_partition}'"partitions_result = cluster.any_host_by_roles(- lambda client: client.execute(partition_query), node_roles=[NodeRole.DATA, NodeRole.COORDINATOR]+ lambda client: client.execute(partition_query), node_roles=[NodeRole.DATA]).result()context.log.info(f"Found {len(partitions_result)} partitions for {table_name}: {partitions_result}")return sorted([partition_row[0] for partition_row in partitions_result if partition_row and len(partition_row) > 0])@@ -94,9 +94,7 @@ def drop_partitions_for_date_range(return client.execute(f"ALTER TABLE {table_name} DROP PARTITION '{pid}'")try:- cluster.any_host_by_roles(- partial(drop_partition, pid=partition_id), node_roles=[NodeRole.DATA, NodeRole.COORDINATOR]- ).result()+ cluster.any_host_by_roles(partial(drop_partition, pid=partition_id), node_roles=[NodeRole.DATA]).result()context.log.info(f"Dropped partition {partition_id} from {table_name}")except Exception as e:context.log.info(f"Partition {partition_id} doesn't exist or couldn't be dropped: {e}")@@ -110,7 +108,7 @@ def sync_partitions_on_replicas(context.log.info(f"Syncing replicas for {target_table} on all hosts")cluster.map_hosts_by_roles(lambda client: client.execute(f"SYSTEM SYNC REPLICA {target_table}"),- node_roles=[NodeRole.DATA, NodeRole.COORDINATOR],+ node_roles=[NodeRole.DATA],).result()@@ -124,9 +122,7 @@ def swap_partitions_from_staging(return client.execute(f"ALTER TABLE {target_table} REPLACE PARTITION '{pid}' FROM {staging_table}")for partition_id in staging_partitions:- cluster.any_host_by_roles(- partial(replace_partition, pid=partition_id), node_roles=[NodeRole.DATA, NodeRole.COORDINATOR]- ).result()+ cluster.any_host_by_roles(partial(replace_partition, pid=partition_id), node_roles=[NodeRole.DATA]).result()def clear_all_staging_partitions(@@ -145,9 +141,7 @@ def clear_all_staging_partitions(for partition_id in all_partitions:try:- cluster.any_host_by_roles(- partial(drop_partition, pid=partition_id), node_roles=[NodeRole.DATA, NodeRole.COORDINATOR]- ).result()+ cluster.any_host_by_roles(partial(drop_partition, pid=partition_id), node_roles=[NodeRole.DATA]).result()context.log.info(f"Dropped partition {partition_id} from {staging_table}")except Exception as e:context.log.warning(f"Failed to drop partition {partition_id} from {staging_table}: {e}")@@ -166,9 +160,7 @@ def recreate_staging_table(# exact command on each host, otherwise we would get a new uuid per host and replication# woudn't kick in.sql_statement = replace_sql_func()- cluster.map_hosts_by_roles(- lambda client: client.execute(sql_statement), node_roles=[NodeRole.DATA, NodeRole.COORDINATOR]- ).result()+ cluster.map_hosts_by_roles(lambda client: client.execute(sql_statement), node_roles=[NodeRole.DATA]).result()# Shared config schema for daily processing