: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(ingestion): consume the ai topic in combined mode and create it locally (#79506)
Paweł Ledwońb606ba1ed90a
diff --git a/bin/mprocs.yaml b/bin/mprocs.yamlindex dac4dce315ee..b6d8536cca1a 100755--- a/bin/mprocs.yaml+++ b/bin/mprocs.yaml@@ -142,6 +142,11 @@ procs:groups:layer: Ingestion pipelinetech: Node+ env:+ # The combined-mode AI consumer reads persons through PersonHog; the+ # event_ingestion capability pulls the personhog services in.+ PERSONHOG_ENABLED: 'true'+ PERSONHOG_ADDR: '127.0.0.1:50052'ingestion-sessionreplay:sandbox: truediff --git a/devenv/intent-map.yaml b/devenv/intent-map.yamlindex e725e7e76304..9c164dcde0db 100644--- a/devenv/intent-map.yaml+++ b/devenv/intent-map.yaml@@ -20,7 +20,8 @@ capabilities:event_ingestion:description: 'Kafka-based event pipeline for event capture'- requires: [core_infra]+ # The combined-mode ingestion server's AI consumer reads persons through PersonHog+ requires: [core_infra, personhog]docker_profiles: []property_definitions:diff --git a/docker-compose.dev.yml b/docker-compose.dev.ymlindex 779e45e4bcd1..186cbe8a0d20 100644--- a/docker-compose.dev.yml+++ b/docker-compose.dev.yml@@ -228,6 +228,9 @@ services:DATABASE_URL: postgres://posthog:posthog@db:5432/${POSTHOG_DB_NAME:-posthog}PERSONS_DATABASE_URL: postgres://posthog:posthog@db:5432/${POSTHOG_PERSONS_DB_NAME:-posthog}CLICKHOUSE_DATABASE: ${CLICKHOUSE_DATABASE:-posthog}+ # The combined-mode AI consumer reads persons through PersonHog+ PERSONHOG_ADDR: 'personhog-router:50052'+ PERSONHOG_ENABLED: 'true'depends_on:kafka:condition: service_started@@ -235,6 +238,8 @@ services:condition: service_healthydb:condition: service_healthy+ personhog-router:+ condition: service_startedhealthcheck:test: ['CMD', 'curl', '-f', 'http://localhost:6738/_ready']interval: 5s@@ -602,6 +607,7 @@ services:clickhouse_heatmap_events \clickhouse_flag_evaluations \clickhouse_ingestion_warnings \+ events_plugin_ingestion_ai \events_plugin_ingestion_dlq \events_plugin_ingestion_overflow \events_plugin_ingestion_async \diff --git a/docker-compose.hobby.yml b/docker-compose.hobby.ymlindex fb57bf294aa0..6c50766c9c0a 100644--- a/docker-compose.hobby.yml+++ b/docker-compose.hobby.yml@@ -234,11 +234,15 @@ services:PERSONS_DATABASE_URL: 'postgres://posthog:posthog@db:5432/posthog'BEHAVIORAL_COHORTS_DATABASE_URL: 'postgres://posthog:posthog@db:5432/posthog'ENCRYPTION_SALT_KEYS: $ENCRYPTION_SALT_KEYS+ # The combined-mode AI consumer reads persons through PersonHog+ PERSONHOG_ADDR: 'personhog-router:50052'+ PERSONHOG_ENABLED: 'true'depends_on:- db- redis7- clickhouse- kafka+ - personhog-routeringestion-sessionreplay:extends:@@ -597,6 +601,7 @@ services:clickhouse_heatmap_events \clickhouse_flag_evaluations \clickhouse_ingestion_warnings \+ events_plugin_ingestion_ai \events_plugin_ingestion_dlq \events_plugin_ingestion_overflow \events_plugin_ingestion_async \diff --git a/nodejs/src/common/config/kafka-topics.ts b/nodejs/src/common/config/kafka-topics.tsindex 52607ad7353e..9ff9db30182c 100644--- a/nodejs/src/common/config/kafka-topics.ts+++ b/nodejs/src/common/config/kafka-topics.ts@@ -16,6 +16,7 @@ export const KAFKA_PERSON_DISTINCT_ID2 = `${prefix}clickhouse_person_distinct_idexport const KAFKA_EVENTS_PLUGIN_INGESTION = `${prefix}events_plugin_ingestion${suffix}`export const KAFKA_EVENTS_PLUGIN_INGESTION_DLQ = `${prefix}events_plugin_ingestion_dlq${suffix}`export const KAFKA_EVENTS_PLUGIN_INGESTION_OVERFLOW = `${prefix}events_plugin_ingestion_overflow${suffix}`+export const KAFKA_EVENTS_PLUGIN_INGESTION_AI = `${prefix}events_plugin_ingestion_ai${suffix}`export const KAFKA_EVENTS_PLUGIN_INGESTION_ASYNC = `${prefix}events_plugin_ingestion_async${suffix}`export const KAFKA_EVENTS_PLUGIN_INGESTION_HISTORICAL = `${prefix}events_plugin_ingestion_historical${suffix}`export const KAFKA_PLUGIN_LOG_ENTRIES = `${prefix}plugin_log_entries${suffix}`diff --git a/nodejs/src/servers/ingestion-general-server.ts b/nodejs/src/servers/ingestion-general-server.tsindex 8bce90d912bd..2c2882875d9f 100644--- a/nodejs/src/servers/ingestion-general-server.ts+++ b/nodejs/src/servers/ingestion-general-server.ts@@ -3,6 +3,7 @@ import { initializePrometheusLabels } from '~/common/api/router'import { defaultConfig, overrideConfigWithEnv } from '~/common/config/config'import {KAFKA_EVENTS_PLUGIN_INGESTION,+ KAFKA_EVENTS_PLUGIN_INGESTION_AI,KAFKA_EVENTS_PLUGIN_INGESTION_HISTORICAL,KAFKA_EVENTS_PLUGIN_INGESTION_OVERFLOW,} from '~/common/config/kafka-topics'@@ -374,15 +375,20 @@ export class IngestionGeneralServer implements NodeServer {topic: 'heatmaps_ingestion',groupId: 'heatmaps_ingestion',})++ // Capture routes $ai_* events to the dedicated AI topic on every+ // deployment shape, so combined mode needs the AI consumer too.+ startAi({+ topic: KAFKA_EVENTS_PLUGIN_INGESTION_AI,+ groupId: 'clickhouse-ingestion-ai',+ })} else if (this.config.INGESTION_PIPELINE === 'clientwarnings') {startClientWarnings()} else if (this.config.INGESTION_PIPELINE === 'heatmaps') {startHeatmaps()} else if (this.config.INGESTION_PIPELINE === 'ai') {- // Dedicated AI pipeline deployment. Not started in combined mode: the- // combined analytics consumers already process AI events on the shared- // topic, so running this in parallel there would double-process them.- // Switchover to this pipeline is driven by capture-side routing.+ // Dedicated AI pipeline deployment, consuming the topic capture's+ // AI routing produces to (config-provided in production).startAi()} else {// Production ingestion-v2: single consumer using config-provided topicdiff --git a/nodejs/tests/ingestion-general-server.test.ts b/nodejs/tests/ingestion-general-server.test.tsindex 704fc33a95dc..f51592b683a4 100644--- a/nodejs/tests/ingestion-general-server.test.ts+++ b/nodejs/tests/ingestion-general-server.test.ts@@ -57,6 +57,10 @@ describe('ingestion general server', () => {server = new IngestionGeneralServer({LOG_LEVEL: 'debug',PLUGIN_SERVER_MODE: PluginServerMode.ingestion_v2_combined,+ // The AI consumer requires a personhog client; the gRPC connection+ // is lazy, so startup doesn't need a live router.+ PERSONHOG_ENABLED: true,+ PERSONHOG_ADDR: 'localhost:50052',})await server.start()expect(process.exit).not.toHaveBeenCalledWith(1)