Repository navigation
fix(clickhouse): cap the system log tables - #13872
Conversation
ClickHouse's own system logs ship without a TTL -- every `<ttl>` in the image's config.xml sits inside a comment -- and metric_log, histogram_metric_log, query_metric_log and error_log each collect a row per second regardless of traffic. On an install with ~1.5GB of usage data they filled a 10GB volume in two weeks. Mount a config.d override that gives each of them a retention window: 3 days for the chatty text/trace logs, 7 for the metric and query logs, 14 for error_log. ClickHouse applies the TTL when it creates a log table and issues the ALTER on restart when the configured window differs, so existing installs shrink on upgrade without a manual TRUNCATE.
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
An idle container writes ~500MiB of system logs a day, and metric_log is half of that on its own: it samples every second and carries a column per profile event. Retention alone leaves 7 days of that on disk, so sample it, histogram_metric_log and query_metric_log every 10 seconds instead -- fine grained enough to read an incident from, and it takes metric_log from 252 to 80 MiB/day on an otherwise idle instance. Also ship the override the way the Mongo sidecars are shipped. The installer reads config files from /usr/src/code or /usr/local/share/appwrite, so without both COPY lines the copy next to the generated compose file silently skips it and Docker creates the bind target as a directory. crash_log keeps every row: it is tiny and worth having.
testLeavesNoRelativeBindMountOnPublishedVersions already fails, with the mount named in the message, when a bind is missing from HOST_PATH_REWRITABLE_BINDS -- checked by removing the entry -- so the two assertions repeating the literal mount only restated docker-compose.yml.
Committed by accident while running the unit test against the vendor directory of another checkout. .gitignore lists /vendor/, which does not match a symlink of that name.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
🟢 Tier S · Ready to mergeAdds retention windows to ClickHouse system logs and reduces sampling frequency for three metric collectors. Bundles and mounts the override through Docker and generated Compose installations. The installer now copies the configuration alongside Compose while skipping copies when source and destination resolve to the same file. Latest changes: The newest commit skips config-file copying when source and destination resolve to the same file, fixing local installs that write into the project root.
📂 Walkthrough · 5
Reviewed the commits since |
What does this PR do?
Caps ClickHouse's own
system.*log tables, which grow without bound today.A self-hosted 2.x report: a 10GB ClickHouse volume filled in two weeks on an install whose Appwrite data was ~1.5GB. The cause is not our schema —
utopia-php/usagealready applies a retention TTL to the usage tables (_APP_MAINTENANCE_RETENTION_USAGE_TTL, 180 days by default, wired inapp/init/resources.php). It is ClickHouse's own system logs, which nothing on our side touches.Two defaults combine badly:
Nothing has retention. Every
<ttl>element in the image's shippedconfig.xmlsits inside an XML comment, including the 30-day one that reads like a default forquery_log:The metric collectors write regardless of traffic.
metric_log,histogram_metric_logandquery_metric_logeach sample every second (collect_interval_milliseconds= 1000), andmetric_logcarries a column per profile event, so its rows are wide. Measured on a stock container serving nothing at all, over 490s:metric_logtrace_logtext_logasynchronous_metric_logpart_log,histogram_metric_log,query_log,processors_profile_log≈510 MiB/day on an idle instance, forever. (Projections come from early-boot unmerged parts, so they read high, but the shape is what the report describes.)
This adds
clickhouse-config.xml, bind-mounted into/etc/clickhouse-server/config.d/appwrite.xml, which:text_log/trace_log/asynchronous_insert_log, 7 days for the metric and query logs pluspart_log/processors_profile_log/background_schedule_pool_log, 14 days forerror_logso a late report is still covered.crash_logis deliberately left alone: tiny, and worth keeping.metric_logand a small one.Measured with the override, same image, same idle workload, 510s:
metric_log53 rows instead of 492 (10x fewer, one per 10s as configured) and 80 MiB/day instead of 252;histogram_metric_log1.2 instead of 5.8. Idle total drops to ≈330 MiB/day, and with the windows above the steady-state ceiling is roughly 1.3GB rather than unbounded.trace_logis the biggest remaining writer at ~140 MiB/day idle, capped at 3 days here. Trimming it further means turning down the query profiler in ausers.dprofile, which costs real debuggability — deliberately out of scope.Existing installs need no manual cleanup: ClickHouse applies the configured
<ttl>when it creates a log table, and on restart issues theALTER TABLE … MODIFY TTLitself when the configured window differs from the table's. Old rows past the window are then dropped by TTL merges, so noTRUNCATEstep is required.The file ships like the existing Mongo sidecars —
COPY'd into both/usr/src/codeand/usr/local/share/appwrite(the two rootsInstall::buildFromProjectPath()searches), copied next to the generated compose file at install time, and listed inGenerator::HOST_PATH_REWRITABLE_BINDSso the relative bind becomes an absolute host path in generated compose files.copyMongoFilesIfNeeded()becamecopyConfigFiles(array $files)to carry both sets.One caveat for reviewers: an upgrade run against an existing compose file (
--use-existing-config) keeps that file, so it will not pick up the mount. Those installs need the bind added by hand, or theALTER TABLE system.<log> MODIFY TTL …statements run once.Test Plan
1. ClickHouse applies the windows to tables that already exist without one — the upgrade path. Start the pinned image on a volume with no override, confirm no TTL, then restart the same volume with the override mounted:
No
<Error>lines in the server log on either boot.2. Both settings merge onto the base
<metric_log>block rather than replacing it — TTL and interval together, table still where it belongs:3. Growth, with and without — the two measurements above, same image, same idle container, comparable uptime (490s stock vs 510s capped).
4. Fresh start with the compose service's environment (
CLICKHOUSE_DB/USER/PASSWORD/DEFAULT_ACCESS_MANAGEMENT) — windows present on first creation, server log clean.5. Compose generation —
docker compose -f docker-compose.yml config --quietpasses, andtests/unit/Docker/Compose/GeneratorTest.phpis green (11 tests, 108 assertions). No new assertions:testLeavesNoRelativeBindMountOnPublishedVersionsalready covers the change, and it fails naming the mount when the entry is dropped fromHOST_PATH_REWRITABLE_BINDS:6.
query_metric_loghonours the interval —query_metric_log_intervaldefaults to-1, meaning "usecollect_interval_millisecondsfrom thequery_metric_logconfig". Same 25s query on both: stock samples 26 rows over 24s, with the override 3 rows over 15s.7. Static analysis — Pint and PHPStan clean on the changed PHP files.
Related PRs and Issues
Checklist