ADR-0044: ClickHouse, a profile of its own, and portalr's analytics users¶
Status: Accepted, amended by ADR-0048 Date: 2026-10-22 Deciders: Alex Nodeland
Amends ADR-0031 for lattice RFC-0008 (portalr product analytics, #361). ADR-0031 made ClickHouse's users stackr's own, with admin and langfuse, and ran ClickHouse only for Langfuse. This record lets analytics run without Langfuse, adds portalr's analytics database and its users, and has the backups take that database.
Context¶
- ClickHouse runs only with Langfuse. The service is under
profiles: [langfuse]incompose.yaml, so analytics could only be on where Langfuse is. - ClickHouse has two users, set in
deploy/clickhouse/users.xml:admin, for operators, from inside the container, andlangfuse, limited todefaultand six system tables. - The backups don't cover a new database. The single host's and the state host's take
BACKUP DATABASE default, DATABASE stackr_drill(ADR-0027, ADR-0037), and nothing else. - Grafana can't read ClickHouse. It has no ClickHouse datasource.
The owner decided on 2026-10-22 that ClickHouse gets a profile of its own, pulled in by both langfuse and analytics, so that analytics works without Langfuse.
Decision¶
- ClickHouse is listed under
profiles: [clickhouse, langfuse, analytics]. Compose starts a service when any of its profiles is active, asdb-init's[langfuse, gateway, auth]already does, so:langfusealone still starts ClickHouse, and Langfuse is unchanged;analyticsalone starts it without Langfuse's containers;clickhousealone is there for an operator.
CLICKHOUSE_PASSWORD, Langfuse's password, is asked for only where Langfuse runs, and thelangfuseuser is never left with an empty password.langfusesigns in from::/0, so an empty password would open ClickHouse to the stack's network. The invariant: where Langfuse is off, either thelangfuseuser isn't made, or it has a generated password no one is given; never an empty one. The first slice picks the Compose expression that keeps it, and the smoke test signs in aslangfusewith an empty password and is refused, with and without Langfuse.- Two users join ADR-0031's, in
users.xml:portalr_analytics_writer:INSERTonanalytics.events, and nothing else: noSELECT, no other database, no system table;- its password is
CLICKHOUSE_ANALYTICS_WRITER_PASSWORD, whichmake envgenerates.
portalr_analytics:SELECTonanalytics.events, behind a row policy on the tenant, which RFC-0008's P4 describes and whose pattern phase 0 verifies;- a readonly profile;
- its password is
CLICKHOUSE_ANALYTICS_PASSWORD.
- Like ADR-0031's, both passwords are marked
hide_in_preprocessed, and each user has a quota, so a heavy read can't starve Langfuse. - Both sign in only from the stack's internal network, where the application runs: the Compose network's range locally, the state host's private subnet on AWS. Not
::/0, aslangfusedoes.
langfusestill reaches onlydefault. It has no grant onanalytics, and the analytics users have none ondefault.- The
analyticsdatabase and its table are made by the first slice, asadmin, from an init step that runs before portalr's application starts. portalr's users can't make or alter a table. - The backups take
analytics:BACKUP DATABASE default, DATABASE analytics, DATABASE stackr_drill, on the single host and the state host. A database that doesn't exist yet, where analytics is off, is made empty first, so one statement serves both. - The
backupuser's grants grow, indeploy/host/clickhouse/backup-user.xml, which the state host mounts too:SELECT, BACKUP ON analytics.*beside today'sSELECT, BACKUP ON default.*, or the backup statement is refused. That is part of the first slice. - The drill restores
analyticsand checks a row count. Today the drill backs up and restores onlystackr_drill(deploy/host/restore-drill). Restoringanalyticsfrom the nightly backup into a scratch database needsbackupto haveALLon that scratch database (as it has onrestore_drillandrestore_sentinel), andSELECTthere to count. langfusekeepsSELECTonsystem.query_log, which ADR-0031 gave it, so it could read analytics' query text.query_masking_rulesredact, in any statement that is logged, the tenant setting's value and the literals compared withtenant_idordistinct_id(one, or anINlist), and portalr sends inserts' rows in the request body, not the query text. A test readssystem.query_logaslangfuseafter an analytics read and insert, and finds no tenant id and nodistinct_id.- Grafana's ClickHouse datasource is a later phase (RFC-0008, phase 3). Whether the plugin is baked into the image or installed at start is still open there. When it lands, it reads as a
grafana_analyticsuser withSELECTonanalytics.eventsand no row policy, since operators read across tenants (portalr ADR-0005). - The smoke test grows:
langfusewith an empty password is refused, with Langfuse on and off;- with
analyticsalone, ClickHouse starts and Langfuse's containers don't; - the writer can insert and can't select;
- the reader can't read without its tenant setting;
langfuseis refusedanalytics.
Options considered¶
| Option | For | Against |
|---|---|---|
A clickhouse profile that langfuse and analytics pull in (chosen) |
Analytics without Langfuse; Langfuse's profile unchanged | One more profile name |
| Analytics needs Langfuse | Nothing to change in Compose | A tenant's adoption depends on an LLM-tracing tool being on |
| A second ClickHouse for analytics | Langfuse's load and analytics' kept apart | Twice the memory, and two of everything to back up |
| Separate writer and reader users (chosen) | The relay can't read, and the reader can't write | Two passwords |
| One analytics user | One password | A bug in the relay could read across tenants |
Consequences¶
- An operator can run
analyticswithoutlangfuse. make envgenerates two more passwords, and a deployment upgrading to this record needs them in its.env, whichmake envadds.- The backups grow by the analytics database's size, small next to Langfuse's.
- ADR-0031's smoke test and users file change, and its statement that ClickHouse is Langfuse's alone no longer holds.
- As built (the first slice, lattice RFC-0008's "First slice as built"):
- The two users are in a file of their own,
deploy/clickhouse/analytics-users.xml, with their profiles and quota. Their row policy is a user-level<filter>there. Without the setting, a read fails withUnknown settingrather than seeing nothing. - The server's settings are in
deploy/clickhouse/analytics.xml. - The reader is
readonly = 1, withSQL_portalr_tenantits onlychangeable_in_readonlysetting, and fixed limits: it can't liftmax_memory_usageormax_execution_time, so the quota protecting Langfuse holds. langfusesees only its own rows ofsystem.query_logandsystem.processes, by a row policy inusers.xml.- Analytics' queries aren't logged:
log_queries = 0in both profiles, which the reader can't change and the writer can't by a constraint. The masking rules cover what an operator's statements log. - The empty-password invariant holds by what exists:
make envmakesCLICKHOUSE_PASSWORDwhether or not Langfuse runs, andcompose.yamlkeeps requiring it (:?), solangfusenever has an empty one. The smoke test checks it. - ClickHouse's HTTP interface is published on
127.0.0.1alone, whateverSTACKR_BINDsays, for an application on this machine: Langfuse's user signs in from any address, so ClickHouse is never published beyond the loopback. This amends ADR-0006, which published nothing of ClickHouse's. The single host's overlay keeps it, on the loopback, as every service there is but Caddy, for the smoke test's own reader. - The drill checks
restore_analyticshas as many tables asanalytics; rows written since the backup would make a row count differ. - The AWS recipe's state host doesn't run analytics yet. Its ClickHouse leaves out the two users and the settings, which
scripts/check-confignames, and its backups are unchanged.
- The two users are in a file of their own,
- With the relay (lattice RFC-0008's relay slice), the writer may also delete (
GRANT ALTER DELETE ON analytics.events), for a person's deletion when they take back their yes. That grant lets it delete any row ofanalytics.events, in any tenant: portalr deletes only by a person's hash, but a compromised writer could delete every tenant's events, though never read them. Langfuse's user sees onlydefault's rows ofsystem.mutations, since that mutation names the person's hash. - Deletions owed, in the background. The template's portal settles the deletions owed in a background pass about every five minutes, from its start, as
portalr_analytics_writer: each replica does, so a person's events may be deleted twice, which is harmless; and a person who says yes and sends events while their old deletion runs loses those events (lattice RFC-0008, the relay's slice).