Skip to content

chore(clickhouse): bring the ai_events satellite under declarative HCL#67281

Merged
orian merged 1 commit into
masterfrom
pawel/chore/ai-events-hcl-schema
Jul 1, 2026
Merged

chore(clickhouse): bring the ai_events satellite under declarative HCL#67281
orian merged 1 commit into
masterfrom
pawel/chore/ai-events-hcl-schema

Conversation

@orian

@orian orian commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Problem

The declarative ClickHouse HCL (posthog/clickhouse/hcl/) manages the OPS and LOGS satellite roles, and the live convergence gate verifies migrations reproduce them. ai_events (LLM analytics) is the next satellite — this brings it under HCL and under the gate.

Changes

  • Model the ai_events role: roles/ai_events/{shared,local,prod} layers, nodes lines, per-env goldens + build SQL.
  • The data table has one column/index set everywhere (only name + zoo_path differ), so it's an abstract _ai_events_data base that sharded_ai_events (local) and ai_events (prod) extend.
  • Wire ai_events (:9100) into dump-live.sh / check-live.sh so the multinode convergence gate introspects and diffs it too.

Detail:

  • Env layering matches the real topology: local/hobby run the MSK ingest variant (kafka_ai_events_json + ai_events_json_mv) with a sharded data table + distributed reader; US/EU run WarpStream (kafka_ai_events_json_ws + ai_events_json_ws_mv, MSK dropped by migration 0248) writing into a single ai_events data table (US and EU identical — the mid-migration per-EU sharded_ai_events has since been dropped in prod).
  • person / person_distinct_id2 are env-uniform Distributed shims (0240), modeled in roles/ai_events/shared; check.sh skips validation of these cross-cluster proxies. dev has only the top-level shared objects.
  • The abstract base resolves away, so the generated goldens/SQL are the flat schema (no change vs. inlining).

How did you test this code?

I'm an agent. Automated checks I ran:

  • check.sh green — every ai_events golden reproduces from its layers, cross-object refs validate, sql/ fresh (11 goldens: ops 4 + logs 3 + ai_events 4).
  • Live-verified the gate: booted the multinode stack, ran dump-live.sh + check-live.sh (enforcing) — local/ai_events: no differences against the live node (person shims and MSK ingest matched).
  • Confirmed the abstract+extend refactor is behavior-preserving: git diff on golden/ + sql/ is empty.
  • prod-us/prod-eu goldens are authored from the captured prod dumps (not live-verifiable in CI; the deploy-time dump pipeline covers those).

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Authored with Claude Code, following the OPS/LOGS pilot pattern. Built on the merged convergence gate (#67134). Key decisions surfaced during review: model the real current prod (EU dropped its transitional sharded_ai_events, so prod-us == prod-eu now) rather than the mid-migration dump; keep person/person_distinct_id2 modeled rather than excluded; and DRY the data table via an abstract base + extend. Layers were derived from a live local introspection + the prod dumps.

@orian orian self-assigned this Jul 1, 2026
@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (1)

  1. posthog/clickhouse/hcl/nodes, line 21-25 (link)

    P2 Stale scope comment now contradicts the live manifest

    The comment on lines 21–25 explicitly names ai_events as one of the roles "intentionally left out for now," but the lines immediately below in this same commit add ai_events as an active entry. Anyone reading this block later will be misled into thinking ai_events is still unmanaged. The comment should be updated to reflect that ai_events is now under management, and only data, endpoints, aux, and sessions remain outside scope.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "chore(clickhouse): bring the AI_EVENTS s..." | Re-trigger Greptile

Comment thread posthog/clickhouse/hcl/roles/ai_events/prod-eu/tables.hcl
@orian orian requested a review from a team July 1, 2026 08:23
@orian orian force-pushed the pawel/chore/ai-events-hcl-schema branch from 8eb6b88 to 1ef4e3b Compare July 1, 2026 08:24
@orian orian force-pushed the pawel/chore/ai-events-hcl-schema branch 4 times, most recently from 9c79675 to 33b6eac Compare July 1, 2026 12:56
@orian orian marked this pull request as ready for review July 1, 2026 13:09
@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "chore(clickhouse): bring the AI_EVENTS s..." | Re-trigger Greptile

Model the AI_EVENTS role in posthog/clickhouse/hcl/ (the third managed role
after OPS and LOGS) and wire it into both the offline guard and the live gate.

The ai_events column set is identical across every table. Factor it into two
abstract bases in roles/ai_events/shared and extend them:
- _ai_events_columns (columns only) -> the distributed ai_events reader (local);
- _ai_events_data (extends _ai_events_columns, adds order_by/partition/ttl +
  indexes) -> the data tables sharded_ai_events (local) and ai_events (US/EU),
  which then only set their own engine (zoo_path differs).

Env layering follows the actual topology:
- local/hobby run the MSK ingest variant (kafka_ai_events_json + ai_events_json_mv)
  with sharded_ai_events + a distributed ai_events reader;
- US/EU run WarpStream (kafka_ai_events_json_ws + ai_events_json_ws_mv, MSK dropped
  by migration 0248) writing into a single ai_events data table (US and EU
  identical; the earlier per-EU sharded_ai_events has been dropped in prod);
- person / person_distinct_id2 are env-uniform Distributed shims (0240), also in
  roles/ai_events/shared; dev has only the top-level shared objects.

- nodes: local/dev/prod-us/prod-eu ai_events lines.
- dump-live.sh / check-live.sh: add ai_events (:9100) so the convergence gate
  introspects and diffs it too.
- check.sh: skip validation of the person / cross-cluster Distributed proxies.

Goldens are generated from the layers (abstract bases resolve away, so the flat
schema is unchanged). Verified against a live multinode ai_events node: dump-live
+ check-live report no drift for local/ai_events; prod goldens are authored from
the captured prod dumps.
@orian orian force-pushed the pawel/chore/ai-events-hcl-schema branch from 33b6eac to 99871b3 Compare July 1, 2026 13:46
@orian orian merged commit db5ec71 into master Jul 1, 2026
255 of 260 checks passed
@orian orian deleted the pawel/chore/ai-events-hcl-schema branch July 1, 2026 15:18
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 1, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-01 15:48 UTC Run
prod-us ✅ Deployed 2026-07-01 16:01 UTC Run
prod-eu ✅ Deployed 2026-07-01 15:58 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants