Repository navigation
Conversation
Run every statement through clickhouse-format (24.8), the layout SHOW CREATE and production's DDL use, so the per-table commits that follow show only real changes. Comments are kept. No statement changes: formatting the old and new files gives identical output.
Move each statement next to the others of its table, tables by name, ALTERs after their CREATE. Only the order changes.
Add the columns production has: top_{dns,tcp,tls}_rule_id, probe_id and
analysis_rules_version, and its minmax indexes on measurement_start_time,
probe_cc and probe_asn.
Like every table from here on, it's now created as ooni.<table> with IF NOT
EXISTS, as production reports it.
Replicated at /clickhouse/{cluster}/tables/ooni/asnmeta on every replica,
as ooni/data#190 made it (and OOPRIV-181 restored on data1).
No change but the explicit index_granularity production reports.
Production's path has no /{shard} suffix. A replica created with the old path
wouldn't join production's table.
Production doesn't have it. Only the legacy citizenlab updater used it, and ooni/data's updater (ooni/data#190) swaps citizenlab without it.
Production has none of the 17 *_obs_w_sum, *_w_sum, *_s_pos, *_s_neg, last_ts and current_mean columns, and no partitioning. It has current_state, and block_type in the CREATE instead of a later ALTER. float is now spelled Float32, the same type.
Production's table is a plain ReplacingMergeTree(ts), not replicated or partitioned, with *_current_state instead of *_obs_w_sum and *_w_sum. The *_last_change and *_last_ts columns are data1's, the only replica with rows.
No change but the explicit index_granularity production reports.
anomaly, confirmed and msm_failure are LowCardinality(String) (ooni/backend#1279), input has a bloom filter index (ooni/backend#1292), and is_verified is in the CREATE. The ALTERs that added and then dropped nym, zkp_request, age_range and msm_range are gone. data1 and data3's definition: data2 alone also has deduplicate_merge_projection_mode = 'rebuild'.
No change but the explicit index_granularity production reports.
An EmbeddedRocksDB table, so it isn't replicated: production has it on data1 and data2 only, and ON CLUSTER creates it, empty, on every node.
An EmbeddedRocksDB table, not replicated, like fingerprints_dns.
No change but IF NOT EXISTS.
A local MergeTree. data1's definition, the only replica with rows and with failed_fastpath.
Replicated at production's path, msmt_feedback_new.
Replicated at production's path, obs_web_repl.
A Join table, local to each node.
Its inner table keeps production's Keeper path, so a new replica joins the existing one. Production has the view on data1 and data3.
A header with the dump date, which replica's definition is used where they differ, and what's left out: the updaters' *_tmp tables, msmt_feedback_old, session_expunge (unused since ooni/backend#972) and the leftover inner table of the dropped counters_test_list view. Also CREATE DATABASE, which the ooni. names need on a new cluster.
ClickHouse fills in {database} when it creates a table, so in production
the paths are unchanged: /clickhouse/{cluster}/tables/ooni/<table>/{shard}.
A second database on the same cluster, e.g. a scratch or CI one, now gets
paths of its own instead of joining production's replicas.
counters_asn_test_list's path keeps production's name for its hidden table,
.inner_id.6a72ceec-…, with a comment saying why: a replica added later joins
production's table whatever UUID its view gets. With {table} there, it
would start a separate, empty path unless its CREATE copied the view's UUID.
Table names are unqualified, so clickhouse-client --database decides where the file loads, and CREATE DATABASE moves to the header's instructions: it has to exist on every node first, or the nodes without it fail with UNKNOWN_DATABASE while the others create the table. Tested on a two-node 24.8.6.70 cluster with Keeper. The node that receives an ON CLUSTER query qualifies its names with the client's database before passing it on, so every node uses that database, not its own default. Loaded into ooni, this file gives exactly the definitions and Keeper paths of the previous commit's file on both nodes; loaded again into ooni_test on the same cluster, it shares no path with ooni, and its view reads ooni_test's tables.
schema.sql stays the schema as it is now. A change to an existing cluster goes in a numbered file in migrations/, applied once, in order, on one node. 000_baseline.sql is schema.sql as of this PR and is never edited; the README says how to run, document and record a migration. schema.sql's header points to it.
test/check.sh starts a one-node oonidata_cluster with Keeper at production's version (24.8.6.70), loads schema.sql into one database and every migration, in order, into another, and compares each table's definition and Keeper path with the database name and UUIDs blanked. It takes about 10 seconds. CI runs it when schema.sql, the migrations, the test or the workflow change. It fails when a migration is missing, and when schema.sql changes without one: both checked by hand before this commit.
The view kept its rows in a hidden table, .inner_id.<uuid>, sorted by
(probe_cc, probe_asn, input). It's a SummingMergeTree, so merges add up the
weeks of each key and keep one arbitrary week. Its reader, ooniprobe's
test-list/urls (common/prio.py), sums the current and previous week, so it
misses every count whose merged row says an older week, which in production
is most of them. Tested on 24.8: 2 rows from last week and 5 from this one
merge into one row of 7 that says last week.
The view now writes TO counters_asn_test_list_data, sorted by (probe_cc,
probe_asn, input, week), with a plain {database} Keeper path. It keeps its
name and column types, so the reader's query doesn't change. The table is
backed up and restored by name, like any other table, by the
clickhouse_backup role's "*" job; the view's backup holds only its
definition. Restore the table before the view: a view restored without its
table makes every insert into fastpath fail.
Migration 001 does it in production. The old rows are wrong, so it doesn't
copy them: it counts the two weeks the reader uses again from fastpath, from
the rows inserted before the new view existed (fastpath's update_time), and
the new view counts the rest. That also counts uploads that came more than
8 days late, which the view leaves out. It isn't a mutation. Queries on the
view fail between the DROP and the RENAME, for about a second; from then on
test-list/urls gets the corrected counts.
Tested on a two-node 24.8.6.70 cluster set up like production (the view on
one node, its rows already merged): the weeks come out right, a late upload
is counted once, later inserts are counted once on both nodes, and
test/check.sh passes.
tests/run.sh, also run in CI when the role or group_vars/clickhouse/vars.yml change, checks what the role's README says it does, against ClickHouse 24.8.6.70 with the real vars (secrets replaced by test values) and a users.xml rendered from the role's template: - test_sql_objects.py runs the role's SQL tasks on an empty node and three nodes seeded like production's data1-3, and checks that every node ends up like the empty one; that each user logs in with its password from vars (an old one is refused), can do what its grants allow and nothing else (including on a database no one is granted), and has its settings, CONST ones fixed; that ids, quota assignments, roles granted by hand and objects not in vars are kept, and that users and quotas not in vars are dropped when clickhouse_sql_objects_drop_unlisted is set; that a second run changes nothing; that the role sends no REVOKE, and queries running during the role never fail; and that the output, at default verbosity, shows errors but no password or hash. - apt_pin.sh checks on Debian 12, against packages.clickhouse.com, that with the role's pin file apt installs the pinned version and not the newest release (and with an older pin too, when clickhouse_version is the newest).
…chema.sql On a cluster member (a host with a replica macro in clickhouse_macros) that has no ooni database, a new replica or a re-imaged one, the role creates the database and loads scripts/cluster-migration/schema.sql on that host only, with its ON CLUSTER removed. The replicated tables then fetch their data from the other replicas; the tables that aren't replicated start empty. A host that has the database is left alone: changes to it are migrations. Hosts that aren't replicas, like notebook1, are skipped. If loading schema.sql fails, the deploy stops with ClickHouse's error and the database is left as it is, for an operator to repair; nothing is dropped. The runbook says how to add and remove a replica: edit the cluster in vars, deploy one host at a time, and drop a removed replica from Keeper; how to finish a failed schema load by hand; and, as replicated tables need a Keeper quorum, to deploy a new cluster with --skip-tags clickhouse_schema first.
tests/run.sh, also run in CI, follows the runbook on one ClickHouse 24.8.6.70 container per production host, named like it, with the real group and host vars (secrets replaced by test values) and the configs the clickhouse role renders from them: - data1-3 form the Keeper ensemble and oonidata_cluster, and the schema step creates the ooni database on each, but not on notebook1, and leaves existing databases alone; - with data4 added to clickhouse_remote_servers and clickhouse_macros and data1-3 restarted one at a time, every node sees four replicas, data4 gets the database and catches up, and inserts and ON CLUSTER DDL reach it; - with data4 removed and dropped from Keeper, every node sees three replicas, Keeper has no trace of it, ON CLUSTER DDL doesn't wait for it, and data1-3 still replicate; - a re-imaged data4 (empty disk, same replica name) can be added again.
…back apt doesn't restart a running clickhouse-server: after a version bump the role installed the new packages and left the old version running, until something else restarted it (tested on Debian 12: 25.3.14.14 installed, 24.8.6.70 still running under the same PID). The package install now notifies Restart-clickhouse, as a changed unit file does (upstream only reloaded, which doesn't apply a changed unit), and the service step restarts right after daemon-reload instead of at the end of the play. It then fails unless the server answers SELECT version() with clickhouse_version, and waits until none of its replicated tables is read-only, i.e. until it's back in Keeper. With serial: 1 or --limit, a host is back on its new version before the next one is deployed. The admin client config the checks use is now written before the service step, in --check too; the version comparison is skipped in --check, where nothing is restarted.
tests/upgrade/run.sh installs FROM_VERSION with the role on three Debian 12 hosts with systemd, named like the production replicas, with the real vars and the apt source line the role's upstream version left, then sets clickhouse_version to TO_VERSION (by default tests/upgrade/next_version, the next hop of the plan in #477) and deploys each host with --limit in turn, while a writer inserts throughout. After each host it checks that the role succeeded, that ClickHouse is active under systemd on the new version with its packages pinned, and that every node answers and reaches Keeper, and it reports each node's version, Keeper role and the inserts that failed meanwhile. At the end every node must run TO_VERSION, take inserts, have no read-only or stuck replicated tables, and have every row whose insert succeeded. 24.8.6.70 -> 25.3.14.14 and 25.3.14.14 -> 25.8.29.51 pass; one insert failed in all, to the node that was restarting. CI runs it when a PR changes clickhouse_version (from the base's version to the PR's) or the role, other than its README and other tests, and by hand with any two versions; not for other vars changes. The runbook says how to upgrade.
A quota's TO names users, so the test's order failed once a quota in vars had one.
notebook.ooni.org isn't in [clickhouse], so the cluster deploy would have installed the role's default version there. notebook1 stays in the group for its vars (clickhouse_version, the cluster's remote_servers and Keeper), with SQL quotas off like users and grants.
The role's config listens on "::" only, as in production. Docker turns IPv6 off in containers on an IPv4-only network, so on GitHub Actions ClickHouse couldn't listen and exited (code 210).
At 700 MB, ClickHouse's server-wide limit (90% of it) failed some of the queries the test runs during the role on GitHub Actions.
The testlists service SELECTs url_priorities (FINAL, in its admin routes) and citizenlab (its /health), but oonitestlists could only INSERT into url_priorities. Every denied SELECT also counts against its quota's 100 errors an hour, after which the quota refuses its INSERTs too: the editor would stop saving priorities.
data2, the API's node, has oonimeasurements with a 4 GiB memory limit and nothing else (set by hand: upstream's role never altered existing users). The vars had 1 GB, 30 s, 51000 result rows, 5 billion rows and 500 GB read, all CONST: the first deploy of this role would have put them in force on every node, where the API never ran under them, and aggregations with more than 51000 rows would fail. Now the user gets data2's 4 GiB limit, not CONST, as there. The oonimeasurements quota stays unassigned, as on data2.
The admin client config, users.xml's plaintext passwords, and config.xml's interserver password, cluster secret and replica passwords were written into XML as they are. A secret with & or < made the file invalid: tried on 24.8.6.70 and 25.3.14.14 with a&b<c>d"e'f, ClickHouse refused to start (exit 232) for users.xml and remote_servers, and the role's admin client couldn't log in. They're now escaped, and an empty value stays empty (None | e would render "None", the default user's password). With production's vars the rendered files are unchanged, so this restarts nothing; with that secret, ClickHouse starts, the admin client and a plaintext user log in, and a query over the cluster authenticates with the secret, on both versions. The role's tests pass.
…ether
During the rolling upgrade one node carries the load of two: the API, and
every writer that falls back to it (fastpath2 with alt_hosts). In data2's
query_log for the past week, API bursts of 1000-1500 queries a minute ran
3.4-8.2 at once with 16-29 threads each, roughly 70-200 threads on 16
cores. But the API is quiet most of the time: in the median minute 0.84
of its queries were running, and in 62% of minutes fewer than one. A
per-user max_threads cap would slow its heavy queries in those quiet
minutes, and wouldn't limit anyone else.
concurrent_threads_soft_limit_ratio_to_cores limits query processing
threads on the server, across all users: a query alone still gets
max_threads, a burst shares the limit, and every query gets at least one
thread. 2 is the value in ClickHouse's stock config.xml; the role's
template didn't render the setting, so production has had no limit.
On a ClickHouse 25.3.14.14 container (16 cores) running 8 CPU-bound
queries at once, next to 24 single-row inserts/s from 10 workers with a
connection each (fastpath's shape):
no limit ratio 2
query alone 1.76 s 1.58 s
8 at once, average 10.52 s 8.29 s (88 thread requests delayed)
inserts p50/p90/p99 28/52/87 ms 13/22/33 ms
inserts, no burst 6/8/78 ms 6/8/89 ms
Each insert is one single-threaded query, and every query gets at least
one thread, so the limit never blocks fastpath's workers.
clickhouse: limit query threads per node to 2 per core (merging into PR #528)
…ts, oonirun) #528 gave every SQL user readonly = 0. For users with only SELECT grants that changes nothing a query can do today (tested on 24.8 and 25.3: a readonly = 0 user with SELECT on ooni.* and oonitest.* is refused INSERT, ALTER, TRUNCATE, CREATE, DROP, temporary tables, url()/file(), SYSTEM and KILL with ACCESS_DENIED), but it drops the second lock: with readonly = 2 a grant added by mistake still can't make the user write. The ooniapi services that use these users never write to ClickHouse: oonimeasurements and oonirun call only query_click (ooni/backend ooniapi/services/*/src; oonirun reads url_priorities and runs a health check). Every ooniapi query carries a log_comment (common/dependencies.py, backend #1305), which readonly = 1 refuses (code 164); readonly = 2 allows it, and still refuses INSERT and SETTINGS readonly = 0. Production (SHOW ACCESS and system.settings_profile_elements on 2026-11-10): oonimeasurements data1: no profile, so readonly 2 from the default profile; data2: the same; data3: PROFILE readonly, so readonly 1, which refuses log_comment oonirun PROFILE write (readonly 0) on all three nodes So oonimeasurements gets what data1 and data2 have, and oonirun is tighter than production. Memory limits are unchanged (4 GiB and 61 GB). Tested with the role's tests (tests/run.sh, 24.8.6.70, nodes seeded like production): 1082 checks passed, among them, on every node, both users have readonly = 2, can set log_comment, can SELECT and cannot INSERT.
clickhouse: readonly = 2 for the read-only users. This is tested to work with log_comment, unlike readonly = 1
ubuntu-latest moves to 26.04 this month; pin it explicitly so a runner change doesn't change CI without a commit. Tested on ubuntu:26.04 (Python 3.14.4, pipx ansible-core 2.17.7, docker compose 2.40): sql-objects, replicas and the 24.8.6.70 -> 25.3.14.14 upgrade all pass. ansible-core 2.17 lists Python up to 3.12 but ran cleanly on 3.14. In one of three runs under nested podman, the replicas test's data1 didn't answer within 120 s of a restart; watch for that flake on the runner.
schema.yml runs clickhouse-client with clickhouse_admin_client_config, a default of the clickhouse role. include_role keeps a role's defaults private unless it's public, so a deploy stopped at "Check whether the ooni database exists" with the variable undefined. The tests set it at play level, which hid this.
…sets The clickhouse role sets each user's password from /oonidevops/secrets/clickhouse_<user>_password (prod account). The Ansible-deployed services build their DSN from the same parameter, but the API services deployed by Terraform read whole DSNs from other parameters (clickhouse_write_url, clickhouse_oonimeasurements_url, clickhouse_oonirun_url in prod; clickhouse_ooniprobe_url, clickhouse_oonirun_url, clickhouse_oonimeasurements_test_url in the dev account), with the password typed in by hand. Upstream's role never altered existing users, so they could differ unnoticed; this role does, and would lock such a service out. scripts/clickhouse_credentials_check.py compares each of those DSNs' passwords with the parameter the role uses for its user, and prints MATCH or MISMATCH per DSN, never a secret. Run it before deploying. Note that prod's ooniprobe connects with clickhouse_write_url (the XML user write), not as the ooniprobe user.
The role's unit replaces the one the package installs, and left out its TimeoutStopSec=infinity: systemd's default is 90 s, after which it SIGKILLs the server. A busy production node, with merges, inserts and the embedded Keeper, can take longer than that to shut down, and the role restarts every node on a version change. Checked against the unit in the 24.8.6.70 and 25.3.14.14 packages.
The first LTS hop of the plan in #477 (24.8.6.70 -> 25.3.14.14 -> 25.8.29.51 -> 26.3.17.110 -> 26.8.9.10). Production's config needs no changes for it: with group_vars/clickhouse as they are, 25.3 starts without warnings beyond 24.8's, and the API's queries return the same results (tests/upgrade/live). The role's tests now run against 25.3.14.14, and the upgrade test's next hop is 25.8.29.51. Deploy the role at 24.8.6.70 first, then this, one host at a time with --limit: data3, data2, data1, the node fastpath writes to, last.
tests/upgrade/live/run.sh starts from what production runs today - main's galaxy role and vars at main's clickhouse_version, production's schema.sql, production's SQL users as tests/seed records them - loads a window of real measurements from a local ClickHouse (SAMPLE_CLIENT), and then, one host at a time in the order data3, data2, data1: A. deploys this branch's role at main's version: the role change alone; B. deploys this branch's clickhouse_version: the hop; C. deploys main's version again: the rollback. Throughout, fastpath-style inserts go to data1 as the fastpath user and API reads to data1 and data2 as oonimeasurements, as in production. After each host it checks Keeper (a leader and both followers synced) and runs ON CLUSTER DDL on a new replicated table, and it records how long the role took, how long ClickHouse was down and the longest gap in data1's inserts. After each phase it compares every table's rows (a checksum of each row), the results of API-shaped queries, logins, users, grants, the settings each user gets, config files and table definitions with the phase before, and fails if data, a query result or a login changes. out/report.md lists the rest. 24.8.6.70 -> 25.3.14.14 -> 24.8.6.70 with 5.1 million real rows: 584 checks passed. Each node was down 1-21 s per restart; fastpath's longest write gap was 6.8 s on the hop and 11.5 s on the rollback.
…eal data tests/upgrade/services/run.sh runs the published images of the six ooniapi services, fastpath's daemon, Postgres and Valkey against a ClickHouse holding OONI data, and checks them before and after that ClickHouse is upgraded: 55 requests to their ClickHouse-backed endpoints, recorded and compared (same, reordered, varies on its own, or CHANGED); measurements submitted the way the probe does, through ooniprobe and fastpath, followed into ClickHouse and back out of the API; and fastpath's S3 feeder writing a real day of one country. Run on the local copy of real data (360 GB) for 24.8.6.70 -> 25.3.14.14: no endpoint broke, and every difference was timings, ids, row order, or aggregation/analysis's approximate quantile(0.95). See README.md.
The config directory is mounted read-only, and 25.3's entrypoint exits when it can't write users.d/default-user.xml there (24.8's didn't). The clickhouse role's tests already set CLICKHOUSE_SKIP_USER_SETUP.
Once, on 25.3.14.14, SYSTEM DROP REPLICA '04' right after stopping data4 refused with "because it's active": Keeper still had data4's session. The rerun stopped data4 in 2 s and dropped it at once, so it's a race, not a change in 25.3. The test now gives data4 two minutes to stop cleanly (compose kills after 10 s, which would leave the session until it times out) and retries the drop for up to two minutes, printing how long each took; the runbook says to retry too.
clickhouse_version_settings adds merge_tree, Keeper coordination and top-level server settings once clickhouse_version reaches the version that knows them. An older server refuses to start with a setting it doesn't know, so a pin for the next version can't be deployed before its binary, and has to come out again on a rollback: tying it to clickhouse_version does both. Keeper coordination_settings are now rendered from all the keys in clickhouse_keeper.coordination_settings. config.xml is unchanged for the current vars.
From the review in #477, for each hop of #437: - 25.8: write_marks_for_substreams_in_compact_parts = 0, or 25.3 replicas stop replicating 25.8's compact parts - 26.3: serialization_info_version, string_serialization_version and propagate_types_serialization_versions_to_nested_types, or 25.8 detaches 26.3's parts as broken on a rollback - 26.8: packed_skip_index_max_bytes = 0 (skip indexes on older replicas), Keeper write_snapshot_version = 6 (snapshots older Keepers can load), asynchronous_metrics_key_values_mode = both (metric names the dashboards use), and enable_webterminal = false (26.6) and in the default and write profiles, today's defaults for async_insert (on by default from 26.3, about 6 times slower for fastpath's one-row inserts) and deduplicate_blocks_in_dependent_materialized_views (on from 26.2). Removing the merge_tree and Keeper pins is the point of no return of the upgrade, a separate decision at the end.
aagbsn
force-pushed
the
vendor_clickhouse_role
branch
from
November 25, 2026 10:17
e5b196d to
d747e11
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the compatibility pins required for rollback from clickhouse 25.8, 26.3, 26.6, 26.8