Give ClickHouse its own lifecycle
The Helm chart’s bundled ClickHouse is one replica with ZooKeeper: a single point of failure, no
backups, and images from Bitnami’s legacy registry. We moved it to the Altinity operator, with one
shard, two replicas and three ClickHouse Keeper members, and pointed Langfuse’s web and worker
deployments at it. PostgreSQL, the Redis-compatible queue (we use Dragonfly) and S3 stay separate.
That is a lot of systems, and two replicas give you availability, not backups.
The cutover order that worked:
- Stop new ingestion, and decide what clients do with events sent meanwhile.
- Let the worker finish outstanding jobs. An empty queue is not enough; check active work too.
- Stop the writer.
- Run the schema migrations on the new cluster.
- Copy history across.
- Point web and worker at the new cluster.
In chart v2 values the connection looks like this, with credentials from a Kubernetes Secret:
clickhouse:
deploy: false
host: clickhouse-langfuse-clickhouse
httpPort: 8123
nativePort: 9000
database: default
cluster:
enabled: true
Older values used a flat clusterEnabled key, so check the chart’s schema. When we moved an
existing release into Helmfile, we captured its live values first and got to a no-op diff before
upgrading anything. Changing who owns the config and changing the app in separate steps made both
easier to debug.
Three ClickHouse surprises
Bound the internal logs. After the 288 GiB day we set query_log, part_log and trace_log to seven days’ retention. Adding a TTL element alone failed with the operator, because its
generated engine definition already had the table settings; we replaced the whole per-log engine
definition, TTL included, in an override loaded after the generated files. Keep watching disk and
ClickHouse’s own metrics too: at a high enough write rate even a day of logs is too much, and pod
health will not tell you.
Migrations may ignore your cluster name. In v3.150.0 the clustered migrations hardcoded ON CLUSTER default, and CLICKHOUSE_CLUSTER_NAME did not change that. Naming the operator’s
cluster default was the simplest fix. If a correct-looking connection fails only in migrations,
look for this.
Backfills need more memory than steady state. The v4 migration produced merges of about 3.1 GiB,
against about 500 MiB before. One replica kept running out of memory repeating a merge the other had
already finished. Raising the memory request from 2 GiB to 4 GiB (limit 8 GiB) and setting
merge_tree/prefer_fetch_merged_part_size_threshold: "104857600"
made merges over 100 MiB prefer fetching the finished part from the other replica, which stopped
the loop. It is one input to ClickHouse’s merge selection, not a guarantee, but it was enough here.
Upgrading to v4
Cross-replica queries failed authentication during the v4 backfill, a path ordinary v3 traffic never
used. The operator’s cluster needed an interserver secret for distributed queries, which secret.auto: "true" provides.
We ran dual writes, backfilled, and reconciled counts before switching to events_only on
16 October: 29,162 historical traces became root spans and 604,111 observations became events.
Matching counts is the gate, but spot-check trace structure and recent ingestion as well.
Clients have to move with the server. v4 retires the legacy ingestion and read endpoints and needs
Python SDK 4 or JavaScript SDK 5, so the v3-to-v4 upgrade guide belongs in the plan for every script and service that reads or writes traces, not just the
deployment.
Backups are daily fulls and four-hourly incrementals to S3, on an s3_plain disk so a restore does
not depend on the original pod’s local object index. The test that counts: seed a table, back it up,
drop it, restore it across the cluster and check both replicas. A successful upload proves much
less.
Make sure the workers actually export spans
Our agents set workflow names and metadata, but deployed workers sent no traces. The Langfuse client
was only initialised on a CLI start-up path, so workers never registered the exporter. We moved
initialisation into the shared runtime bootstrap, made it idempotent, and log whether tracing is on.
Our wrapper also maps LANGFUSE_BASE_URL to whatever host setting the installed SDK reads: a host
setting that is silently ignored falls back to Langfuse’s hosted service, not your instance.
Shutdown is the other trap. KEDA scales the workers, and OpenTelemetry batches spans, so a worker
can finish its queue and get SIGTERM with spans still buffered. Flush after each job and on graceful
shutdown, or the last model call of a successful job goes missing.
To test an integration, follow one identifiable job end to end: the worker’s start-up log, the
trace, its generation and guardrail spans, then the same again while the worker scales down. An
authentication check tells you much less than one complete trace.