fix(chart): apply ClickHouse gold-view migrations on deploy (external CH) - #1477
fix(chart): apply ClickHouse gold-view migrations on deploy (external CH)#1477mitasovr wants to merge 1 commit into
Conversation
… CH) The ClickHouse gold-view migrations (scripts/migrations/*.sql — insight.* VIEWs the analytics-api reads: collab_bullet_rows, git_bullet_rows, people, …) were only ever applied by scripts/init.sh via `kubectl exec` into a *bundled* statefulset/insight-clickhouse pod, run manually (run-init.sh) — never on deploy, and not by the reconcile-loop. When ClickHouse is external/layered (dev moved CH to a separate `clickhouse` release in insight-infra), there is no in-namespace pod to exec into and the toolbox ships no clickhouse-client binary, so init.sh can't reach the live CH. Result: no CH gold-view migration has landed since the move — every newly-released view change (e.g. the Zulip collab_bullet_rows branch) silently never applied; the metric only worked after applying the SQL by hand. Fix — a Helm post-install/post-upgrade Hook Job that applies the migrations to `clickhouse.host` over the HTTP interface via a new host-driven `scripts/apply_ch_migrations.py`, using the toolbox image's bundled clickhouse-connect (a dbt-clickhouse dep — no new binary, no Dockerfile change, no init.sh change). Same transport + statement-split the e2e rig already uses for these exact files. Idempotent: every migration is DROP [VIEW|TABLE] IF EXISTS + CREATE / CREATE … IF NOT EXISTS / ALTER … IF EXISTS; the one data table (jira_closed_tasks) is DROP+CREATE+INSERT (rebuilt empty, no dup). No version-tracking table by design — re-applied in full each run, exactly as the e2e applies AND re-applies all 27 files (204 stmts) every session. Validated against the live dev external CH in the deployed toolbox image: clickhouse-connect connects over HTTP and applies the collab migration (gold has_zulip=1). Gated by clickhouse.applyMigrations (default true). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Roman Mitasov <Roman.Mitasov@constructor.tech>
|
Warning Review limit reached
More reviews will be available in 4 minutes and 45 seconds. Learn how PR review limits work. To continue reviewing without waiting, enable usage-based billing in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
The ClickHouse gold-view migrations (
src/ingestion/scripts/migrations/*.sql— theinsight.*VIEWs analytics-api reads:collab_bullet_rows,git_bullet_rows,people,wiki_bullet_rows, …) are applied only byscripts/init.shviakubectl execinto a bundledstatefulset/insight-clickhousepod, invoked manually fromrun-init.sh. They are not applied on deploy, and the reconcile-loop (reconcile-connectors/main.sh) doesn't touch them.When ClickHouse is external/layered — dev moved CH to a separate
clickhouseHelm release ininsight-infra— there is no in-namespace pod tokubectl execinto, and the toolbox image ships noclickhouse-clientbinary. Soinit.shcan't reach the live CH and no CH gold-view migration has landed since the move: every newly-released view change (e.g. the Zulipcollab_bullet_rowsbranch from #1466) silently never applied, and the metric only worked after applying the SQL by hand.This is broad — it affects all gold-view changes, not just Zulip.
Fix
A Helm
post-install,post-upgradeHook Job (clickhouse-migrate) that applies the migrations toclickhouse.hostover the HTTP interface via a new host-drivenscripts/apply_ch_migrations.py, using the toolbox image's bundledclickhouse-connect(adbt-clickhousedependency).init.shchange — fully additive.--strip, split on;) the e2e rig already uses to apply these exact files (tests/e2e/e2e_lib/migration_applier.py).clickhouse-init-svcdbsHook (which already dialsclickhouse.hostover HTTP forCREATE DATABASE).clickhouse.applyMigrations(defaulttrue).Idempotency / no dupes
No version-tracking table — by design; migrations are re-applied in full each run and are written idempotently:
DROP VIEW IF EXISTS+CREATE VIEW(e.g.gold-views.sqlhas 29DROP VIEW IF EXISTS).CREATE … IF NOT EXISTS;ALTER … DROP COLUMN IF EXISTS.insight.jira_closed_tasks, isDROP TABLE IF EXISTS→CREATE→INSERT(rebuilt empty each run → no row duplication).This is the same set the e2e applies and re-applies (204 statements × 27 files) every session.
Validation
clickhouse-connectconnects over HTTP and applies the collab migration →collab_bullet_rowsgains the zulip branch (has_zulip=1), idempotent on re-run.helm installfrom here; the template mirrors the workingclickhouse-init-svcdbsJob).Note
Dev gitops already points
clickhouse.hostatclickhouse.insight-infra.svc.cluster.local, so no gitops change is needed — this PR makes the umbrella actually apply migrations there.🤖 Generated with Claude Code