: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(cdp): deflake rerun-paginator clickhouse seed race (#73548)
Raúl Negrón-Otero30087fb06bd9
diff --git a/nodejs/src/cdp/rerun/rerun-e2e.test.ts b/nodejs/src/cdp/rerun/rerun-e2e.test.tsindex e19d5c030253..3405f0104047 100644--- a/nodejs/src/cdp/rerun/rerun-e2e.test.ts+++ b/nodejs/src/cdp/rerun/rerun-e2e.test.ts@@ -13,6 +13,7 @@ import { closeHub, createHub } from '~/common/utils/db/hub'import { createCdpConsumerDeps } from '~/tests/helpers/cdp'import { Clickhouse } from '~/tests/helpers/clickhouse'import { waitForExpect } from '~/tests/helpers/expectations'+import { waitForHogInvocationResultsMvReady } from '~/tests/helpers/hog-invocation-results'import { TEST_KAFKA_TOPICS, ensureKafkaTopics } from '~/tests/helpers/kafka'import { getFirstTeam, resetTestDatabase } from '~/tests/helpers/sql'@@ -51,59 +52,6 @@ interface PersistedRow {invocation_globals: string}-/**- * Probe the ClickHouse Kafka MV for our topic in particular. With- * auto.offset.reset=latest, anything produced before the MV's internal consumer- * has attached is silently dropped. Send probe rows until one lands in CH so we- * know the MV is live before the test produces real rows.- */-const waitForHogInvocationResultsMvReady = async (clickhouse: Clickhouse): Promise<void> => {- const producer = await ActualKafkaProducerWrapper.create(undefined)- const probeTeamId = -999_999- try {- await waitForExpect(async () => {- await producer.queueMessages({- topic: KAFKA_HOG_INVOCATION_RESULTS,- messages: [- {- key: 'probe',- value: JSON.stringify({- team_id: probeTeamId,- function_kind: 'hog_function',- function_id: 'probe',- invocation_id: 'probe',- parent_run_id: '',- status: 'running',- attempts: 0,- is_retry: 0,- scheduled_at: DateTime.utc().toFormat("yyyy-MM-dd HH:mm:ss.SSS'000'"),- started_at: null,- finished_at: null,- duration_ms: null,- error_kind: '',- error_message: '',- event_uuid: '',- distinct_id: '',- person_id: '',- invocation_globals: '{}',- version: String(BigInt(Date.now()) * 1000n),- is_deleted: 0,- }),- },- ],- })- await producer.flush()-- const result = await clickhouse.query<{ c: number }>(- `SELECT count() AS c FROM hog_invocation_results WHERE team_id = ${probeTeamId}`- )- expect(Number(result[0]?.c ?? 0)).toBeGreaterThan(0)- }, 30_000)- } finally {- await producer.disconnect()- }-}-/*** End-to-end exercise of the runs/rerun pipeline.*diff --git a/nodejs/src/cdp/rerun/rerun-paginator.service.test.ts b/nodejs/src/cdp/rerun/rerun-paginator.service.test.tsindex acace17d7b84..4e069e62010d 100644--- a/nodejs/src/cdp/rerun/rerun-paginator.service.test.ts+++ b/nodejs/src/cdp/rerun/rerun-paginator.service.test.ts@@ -10,7 +10,8 @@ import { UUIDT } from '~/common/utils/utils'import { createCdpConsumerDeps } from '~/tests/helpers/cdp'import { Clickhouse } from '~/tests/helpers/clickhouse'import { waitForExpect } from '~/tests/helpers/expectations'-import { ensureKafkaTopics, resetKafka } from '~/tests/helpers/kafka'+import { waitForHogInvocationResultsMvReady } from '~/tests/helpers/hog-invocation-results'+import { TEST_KAFKA_TOPICS, ensureKafkaTopics } from '~/tests/helpers/kafka'import { getFirstTeam, resetTestDatabase } from '~/tests/helpers/sql'import { Hub, Team } from '../../types'@@ -188,9 +189,12 @@ describe('RerunPaginatorService integration', () => {beforeAll(async () => {MockKafkaProducerWrapper.create = jest.fn((...args: any[]) => ActualKafkaProducerWrapper.create(...args))- await resetKafka()- await ensureKafkaTopics([KAFKA_HOG_INVOCATION_RESULTS])+ // Ensure all topics exist (idempotently, without deleting) so the ClickHouse Kafka engine+ // consumers keep their connections. Includes KAFKA_HOG_INVOCATION_RESULTS, which this test's+ // MV needs but the shared set does not cover.+ await ensureKafkaTopics([...TEST_KAFKA_TOPICS, KAFKA_HOG_INVOCATION_RESULTS])await clickhouse.truncate('hog_invocation_results_data')+ await waitForHogInvocationResultsMvReady(clickhouse)})beforeEach(async () => {diff --git a/nodejs/tests/helpers/hog-invocation-results.ts b/nodejs/tests/helpers/hog-invocation-results.tsnew file mode 100644index 000000000000..becdd070133c--- /dev/null+++ b/nodejs/tests/helpers/hog-invocation-results.ts@@ -0,0 +1,62 @@+import { DateTime } from 'luxon'++import { KAFKA_HOG_INVOCATION_RESULTS } from '~/common/config/kafka-topics'+import { KafkaProducerWrapper } from '~/common/kafka/producer'+import { Clickhouse } from '~/tests/helpers/clickhouse'+import { waitForExpect } from '~/tests/helpers/expectations'++// `~/common/kafka/producer` is auto-mocked in these tests; use the real wrapper to push probe rows.+const ActualKafkaProducerWrapper: typeof KafkaProducerWrapper =+ jest.requireActual('~/common/kafka/producer').KafkaProducerWrapper++/**+ * Probe hog_invocation_results until a row lands, proving the ClickHouse Kafka engine's consumer has+ * attached. Its `auto.offset.reset=latest` drops rows produced before attach, so a seed right after+ * topic (re)creation can lose rows and never satisfy a count poll. Mirrors waitForClickHouseKafkaConsumer.+ */+export const waitForHogInvocationResultsMvReady = async (clickhouse: Clickhouse): Promise<void> => {+ const producer = await ActualKafkaProducerWrapper.create(undefined)+ const probeTeamId = -999_999+ try {+ await waitForExpect(async () => {+ await producer.queueMessages({+ topic: KAFKA_HOG_INVOCATION_RESULTS,+ messages: [+ {+ key: 'probe',+ value: JSON.stringify({+ team_id: probeTeamId,+ function_kind: 'hog_function',+ function_id: 'probe',+ invocation_id: 'probe',+ parent_run_id: '',+ status: 'running',+ attempts: 0,+ is_retry: 0,+ scheduled_at: DateTime.utc().toFormat("yyyy-MM-dd HH:mm:ss.SSS'000'"),+ started_at: null,+ finished_at: null,+ duration_ms: null,+ error_kind: '',+ error_message: '',+ event_uuid: '',+ distinct_id: '',+ person_id: '',+ invocation_globals: '{}',+ version: String(BigInt(Date.now()) * 1000n),+ is_deleted: 0,+ }),+ },+ ],+ })+ await producer.flush()++ const result = await clickhouse.query<{ c: number }>(+ `SELECT count() AS c FROM hog_invocation_results WHERE team_id = ${probeTeamId}`+ )+ expect(Number(result[0]?.c ?? 0)).toBeGreaterThan(0)+ }, 30_000)+ } finally {+ await producer.disconnect()+ }+}