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(ci): bump ClickHouse to 26.6.2 and fix temporal log tests (#80749)

Tommy Gilmore6af0de525668
diff --git a/.github/clickhouse-versions.json b/.github/clickhouse-versions.json
index 7cb03bb5d0af..26c78d0b849a 100644
--- a/.github/clickhouse-versions.json
+++ b/.github/clickhouse-versions.json
@@ -1,6 +1,6 @@
{
- "production_eu": "clickhouse/clickhouse-server:26.3.10",
- "production_us": "clickhouse/clickhouse-server:26.3.10",
+ "production_eu": "clickhouse/clickhouse-server:26.6.2",
+ "production_us": "clickhouse/clickhouse-server:26.6.2",
"local": "clickhouse/clickhouse-server:26.6.2",
- "oldest_supported": "clickhouse/clickhouse-server:26.3.10"
+ "oldest_supported": "clickhouse/clickhouse-server:26.6.2"
}
diff --git a/posthog/clickhouse/log_entries.py b/posthog/clickhouse/log_entries.py
index 3776e87fc778..1d45ce7c9e27 100644
--- a/posthog/clickhouse/log_entries.py
+++ b/posthog/clickhouse/log_entries.py
@@ -68,11 +68,11 @@ SETTINGS index_granularity=512
)
-def KAFKA_LOG_ENTRIES_TABLE_SQL(on_cluster=True):
+def KAFKA_LOG_ENTRIES_TABLE_SQL(on_cluster=True, group: str = "group1"):
return LOG_ENTRIES_TABLE_BASE_SQL.format(
table_name="kafka_" + LOG_ENTRIES_TABLE,
on_cluster_clause=ON_CLUSTER_CLAUSE(on_cluster),
- engine=kafka_engine(topic=KAFKA_LOG_ENTRIES),
+ engine=kafka_engine(topic=KAFKA_LOG_ENTRIES, group=group),
extra_fields="",
)
diff --git a/posthog/models/usage_report_events_preagg/test/test_usage_report_events_preagg_mv.py b/posthog/models/usage_report_events_preagg/test/test_usage_report_events_preagg_mv.py
index d8f025a03bbf..361532fe1dcb 100644
--- a/posthog/models/usage_report_events_preagg/test/test_usage_report_events_preagg_mv.py
+++ b/posthog/models/usage_report_events_preagg/test/test_usage_report_events_preagg_mv.py
@@ -52,13 +52,19 @@ def _make_event_payload(distinct_id: str, event: str, lib: str) -> dict:
def _wait_for_team_row(
- team_id: int, expected_unique: int, expected_total: int, timeout_seconds: int = 15
+ team_id: int, expected_unique: int, expected_total: int, timeout_seconds: int = 90
) -> tuple[int, int]:
"""Poll usage_report_events_preagg until BOTH uniqExactMerge >= expected_unique AND
sumMerge >= expected_total. Both conditions are required because in a replay scenario
`unique_count` saturates at 1 after the first message lands while `total_count` is
still climbing — returning early on `unique_count` alone races the second message.
+ The timeout has to outlast a consumer group rebalance. setUp and tearDown recreate the
+ Kafka table for every test, and ClickHouse leaves the previous test's consumer registered
+ with the broker until its session.timeout.ms elapses, so every test after the first reads
+ nothing until the broker evicts that stale member. Polling stops as soon as both counts
+ are satisfied, so a healthy run does not pay for this headroom.
+
Returns (unique_count, total_count) once both observed, or raises AssertionError on timeout.
"""
deadline = time.monotonic() + timeout_seconds
diff --git a/posthog/temporal/tests/common/test_logger.py b/posthog/temporal/tests/common/test_logger.py
index 0c7a99a1ab55..f7ddf3e8dc26 100644
--- a/posthog/temporal/tests/common/test_logger.py
+++ b/posthog/temporal/tests/common/test_logger.py
@@ -475,7 +475,11 @@ async def test_logger_produces_to_log_queue_from_activity(activity_environment,
@pytest.fixture
def log_entries_table():
"""Manage log_entries table for testing."""
- sync_execute(KAFKA_LOG_ENTRIES_TABLE_SQL())
+ # Each test gets its own consumer group because ClickHouse leaves a dropped table's
+ # consumer registered with the broker until its session.timeout.ms elapses. Sharing
+ # one group would make every test after the first wait out that stale member's
+ # rebalance before its own messages are assigned to it.
+ sync_execute(KAFKA_LOG_ENTRIES_TABLE_SQL(group=f"test_log_entries_{uuid.uuid4().hex}"))
sync_execute(LOG_ENTRIES_TABLE_MV_SQL)
sync_execute(TRUNCATE_LOG_ENTRIES_TABLE_SQL)
@@ -743,24 +747,29 @@ async def test_logger_produces_to_kafka_from_workflow(producer, queue, log_entri
assert log_dict["team_id"] == FIRST_WORKFLOW_TEAM_ID + i
assert log_dict["timestamp"] == "2024-01-01 00:00:00.000000"
- results = sync_execute(
- f"SELECT instance_id, level, log_source, log_source_id, message, team_id, timestamp FROM {log_entries_table} ORDER BY team_id ASC"
+ # The fixture's consumer group is new, so it replays the topic from the start and
+ # ingests rows produced by earlier tests. Scope the query to this workflow's own
+ # rows instead of counting everything in the table.
+ instance_id = log_dict["instance_id"]
+ query = (
+ f"SELECT instance_id, level, log_source, log_source_id, message, team_id, timestamp "
+ f"FROM {log_entries_table} WHERE instance_id = '{instance_id}' ORDER BY team_id ASC"
)
+ results = sync_execute(query)
+
iterations = 0
while not len(results) == entries_captured:
# It may take a bit for CH to ingest.
await asyncio.sleep(1)
- results = sync_execute(
- f"SELECT instance_id, level, log_source, log_source_id, message, team_id, timestamp FROM {log_entries_table} ORDER BY team_id ASC"
- )
+ results = sync_execute(query)
iterations += 1
if iterations > 10:
raise TimeoutError("Timedout waiting for logs")
for index, row in enumerate(results):
- assert row[0] == log_dict["instance_id"]
+ assert row[0] == instance_id
assert row[1] == "info"
assert row[2] == log_source
assert row[3] == log_source_id