fix(migrations): honor clickhouse.selfManaged in the snowplow and Service Ping schema

What

This MR adds support for clickhouse.selfManaged: true on a replicated ClickHouse cluster for the snowplow tables, the Service Ping exporter schema and the goose version table. When the flag is set, platform migrate creates the database, the tables, the view, the user, the role and the grants ON CLUSTER '{cluster}', and the tables use Replicated*MergeTree under /clickhouse/{cluster}/tables/{shard}/<db>.<table>. This is the pattern the analytics bundle already uses. The goose version table uses the same path, so each database keeps its own versions and no keeper_map_path_prefix is needed on the server.

Two guards come with it. Before any ON CLUSTER statement, the command checks that no table in the target databases is still a single-node one and refuses to run if it finds any, naming them, so a cluster that ran an older release with the flag set is never converted half way. The operator drops those tables on that node and runs the migration again. The user statements on a cluster carry a salted SHA-256 of the exporter password instead of the password, because ClickHouse keeps every ON CLUSTER statement as written in the Keeper DDL queue for days.

With selfManaged: false the rendered SQL stays as it is today. Unit tests pin the single-node rendering of both templates and every Service Ping statement, in full for the short ones and by their opening and engine lines for the long ones. A binary from main and from this branch produce identical SHOW CREATE output and grants on fresh single nodes. The prober asks for the single-node engines explicitly, which is what it runs today. The testcontainers helper now gets a replicated goose table instead of a KeeperMap one, since it already asked for the on-cluster store.

Verification

On a two-node ClickHouse cluster with Keeper, one migrate run against node 1 created all tables with replicated engines, the view, the user, the role and the grants on both nodes. A row inserted on node 1 appeared on node 2 and flowed through the view into serviceping.events on both. Runs from either node, a second run, and the cleanup toggle changed nothing unexpected and the query log shows no failed DDL. The Keeper DDL queue holds no password literal, and the exporter logs in with the plain password on both nodes. The Service Ping exporter's integration suite passes against node 2, and every statement it runs in production works as the exporter user there. A cluster first migrated with the main binary is refused by the guard with the single-node tables named, and passes after those tables are dropped. go test ./... and golangci-lint v2.4.0 pass.

Related: https://gitlab.com/gitlab-org/analytics-section/analytics-instrumentation/internal/-/work_items/1020

🤖 Generated with Claude Code

Edited by Neha Yadav

Merge request reports

Loading
Loading