Repository navigation
feat(docker): run the all-in-one image on DocumentDB instead of MongoDB 4.0.5 - #3734
jordan-simonovski wants to merge 6 commits into
Conversation
…DB 4.0.5 MongoDB 4.0.5 is EOL, SSPL licensed, and comes from Alpine 3.9 packages that carry OpenSSL 1.1.1k critical CVEs. The all-in-one image now runs DocumentDB v1.2-0 (MIT, Postgres 18) from the same Dockerfile stage the dev, integration and e2e stacks use. Metadata stays on the /data/db mount under /data/db/pgdata; the changeset documents moving old MongoDB data.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 9e64f12 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🔴 Tier 4 — CriticalTouches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI. Why this tier:
Review process: Deep review from a domain expert. Synchronous walkthrough may be required. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
| FROM alpine:3.24 AS documentdb | ||
| COPY --from=documentdb-builder /out/ / | ||
| RUN apk add --no-cache bash openssl su-exec $(cat /etc/documentdb/apk-packages) \ | ||
| && addgroup -S -g 70 postgres && adduser -S -u 70 -G postgres -h /var/lib/postgresql postgres \ |
There was a problem hiding this comment.
🔴 P1 — Pinning postgres to UID/GID 70 breaks existing dev DocumentDB volumes
The old docker/documentdb/Dockerfile ran addgroup -S postgres && adduser -S ..., which on alpine:3.24 picks the first free system ID (100 or above), not 70. docker-compose.dev.yml:21 keeps /data/docdb on a host bind mount (.volumes/docdb_dev_<slot>), so a dev who already ran #3375 has a PGDATA full of files owned by the old UID. docker/documentdb/entrypoint.sh:9 (install -d -o postgres ...) only re-owns the top directory. The .documentdb-initialised marker skips initdb, so pg_ctl running as UID 70 gets permission denied on PG_VERSION/global/* and the db container never becomes healthy. Fix: in the root branch of the entrypoint, re-own the contents when the owner differs, e.g. [ "$(stat -c %u "$PGDATA")" = "$(id -u postgres)" ] || chown -R postgres:postgres "$PGDATA", run before the install -d.
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond
| fi | ||
|
|
||
| # Start DocumentDB (Postgres + Mongo wire-protocol gateway on :10260) | ||
| DOCDB_USER=hyperdx DOCDB_PASSWORD=hyperdx PGDATA=/data/db/pgdata \ |
There was a problem hiding this comment.
🟡 P2 — In the all-in-one image the DocumentDB entrypoint's clean-shutdown trap never fires, so Postgres is SIGKILLed on every docker stop
docker/documentdb/entrypoint.sh:51-52 relies on receiving SIGTERM to run pg_ctl stop ("so persistent volumes skip crash recovery"). In the all-in-one image, PID 1 is sh /etc/local/entry.sh, which sets no trap and does not forward signals. docker stop therefore waits out its timeout and SIGKILLs everything, and Postgres runs crash recovery on each boot. Fix: add a trap in entry.local.base.sh that forwards TERM/INT to the background DocumentDB PID (and the others) and waits for them, or run the services under a small init such as tini.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
PR Review
3 finding(s): 🔴 1 P0/P1 · 🟡 1 P2 · 🔵 1 P3 1 posted as inline comment(s) on the changed lines. 1 P3 folded at the bottom. 1 unchanged from an earlier push (already inline above). 🔵 1 P3 — no action needed before merge
Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
Deep ReviewReplaces bundled MongoDB 4.0.5 with DocumentDB (Postgres 18 + Mongo wire-protocol gateway) in the all-in-one image. 11 reviewers ran against the diff vs 🔴 P0/P1 — must fix
🟡 P2 — recommended
🔵 P3 nitpicks (4)
Reviewers (11): correctness, testing, maintainability, project-standards, agent-native, learnings, security, reliability, data-migrations, adversarial, previous-comments. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
E2E Test Results✅ All tests passed • 479 passed • 1 skipped • 1050s
Tests ran across 4 shards in parallel. |
…mentdb-aio # Conflicts: # docker/hyperdx/Dockerfile
| # Start Mongo Server | ||
| mongod --quiet --dbpath /data/db > /var/log/mongod.log 2>&1 & | ||
| # Images before DocumentDB kept MongoDB data directly in /data/db, which this image cannot read. | ||
| if [ -f /data/db/WiredTiger ] && [ ! -f /data/db/pgdata/.documentdb-initialised ]; then |
There was a problem hiding this comment.
🔴 P1 — Upgrading an auth all-in-one install silently starts with an empty database, so the first visitor can register and take over
When the container finds /data/db/WiredTiger but no .documentdb-initialised marker, it should refuse to start, for example by exiting non-zero with the migration steps, unless the user opts in with something like HYPERDX_ACCEPT_EMPTY_METADATA=1. Right now it prints a warning and carries on. With no team, POST /register/password in packages/api/src/routers/api/root.ts:94 accepts a signup again, so on an exposed auth image the first person to reach :8080 becomes the team owner. The warning also only prints once, because the marker exists after the first boot. The image ships under the floating :2 tag and the changeset is only a minor bump, so users who pull :2 will hit this without choosing to upgrade.
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond
| # Start DocumentDB (Postgres + Mongo wire-protocol gateway on :10260) | ||
| DOCDB_USER=hyperdx DOCDB_PASSWORD=hyperdx PGDATA=/data/db/pgdata \ | ||
| PATH="/usr/libexec/postgresql18:$PATH" \ | ||
| bash /usr/local/bin/documentdb-entrypoint.sh > /var/log/documentdb.log 2>&1 & |
There was a problem hiding this comment.
Postgres killed uncleanly on container stop
Medium Severity
The DocumentDB entrypoint trap that runs pg_ctl -m fast stop never runs in the all-in-one image. The script is started in the background, and PID 1 (entry.local.base.sh) does not forward SIGTERM. docker stop therefore SIGKILLs Postgres, so the /data/db/pgdata volume needs crash recovery on every restart and can be left inconsistent if a write was in flight.
Reviewed by Cursor Bugbot for commit 8b60457. Configure here.
…ld dev PGDATA An auth all-in-one image upgraded onto a /data/db volume with MongoDB data started empty, so the first visitor could register as team owner. It now exits unless HYPERDX_ACCEPT_EMPTY_METADATA=true. Dev DocumentDB volumes created before postgres was pinned to UID 70 now get their files re-owned on start instead of failing permission checks.
| @@ -0,0 +1,24 @@ | |||
| --- | |||
| '@hyperdx/api': minor | |||
There was a problem hiding this comment.
🔴 P1 — Breaking all-in-one change ships as a minor bump, so the floating :2 and latest tags pick it up
release.yml (around lines 859–864 and 1052–1057) retags every release as ${IMAGE}:${MAJOR} and latest. The PR description's own repro uses clickstack-all-in-one:2. With a minor changeset, anyone tracking :2 who pulls or restarts gets an image that exits at boot (because of the WiredTiger gate) or, with the opt-in set, starts with an empty metadata database. Either mark this major or publish it under a new image major tag, so existing :2 deployments don't hit the breaking upgrade unannounced.
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond
A hardlink to a root-owned file planted in PGDATA would otherwise be chowned to postgres on the next boot.
| adduser -S -u ${USER_UID} -G otel otel && \ | ||
| addgroup -S -g 70 postgres && adduser -S -u 70 -G postgres -h /var/lib/postgresql postgres && \ | ||
| mkdir -p /data/db && \ | ||
| ! ldd /usr/libexec/postgresql18/postgres /usr/bin/documentdb-gateway /usr/lib/postgresql18/*.so 2>&1 | grep 'Error loading shared library' && \ |
There was a problem hiding this comment.
🟡 P2 — The ldd guard catches missing libraries but not symbol mismatches from an older base Alpine
musl ldd reports a library that exists but is too old as Error relocating ...: symbol not found, the same drift this Dockerfile's own comment at line 233 describes. That output does not contain Error loading shared library, so a ClickHouse base on an older Alpine point release than the 3.24 builder passes the guard and Postgres or the gateway fails at runtime. Match both messages: grep -E 'Error (loading shared library|relocating)'.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
|
still no perms :/ |
Should this be a major version? Also, thoughts on automatically migrating in a minor version then remove the migrator in a few releases? |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
There are 3 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9e64f12. Configure here.
| @@ -0,0 +1,24 @@ | |||
| --- | |||
| '@hyperdx/api': minor | |||
| --- | |||
There was a problem hiding this comment.
Breaking change shipped as minor bump
High Severity
The changeset marks this as a minor bump of @hyperdx/api, but the all-in-one image now refuses to boot on an existing /data/db volume (or starts empty if HYPERDX_ACCEPT_EMPTY_METADATA=true). Release tagging still promotes every release to :2 and latest, so anyone tracking those tags who pulls or restarts gets a crash loop or an empty metadata database (users, sources, dashboards, alerts).
Reviewed by Cursor Bugbot for commit 9e64f12. Configure here.
| # Start DocumentDB (Postgres + Mongo wire-protocol gateway on :10260) | ||
| DOCDB_USER=hyperdx DOCDB_PASSWORD=hyperdx PGDATA=/data/db/pgdata \ | ||
| PATH="/usr/libexec/postgresql18:$PATH" \ | ||
| bash /usr/local/bin/documentdb-entrypoint.sh > /var/log/documentdb.log 2>&1 & |
There was a problem hiding this comment.
App starts before DocumentDB is ready
Medium Severity
The entrypoint waits for ClickHouse, then starts the API, app, and alert task, but never waits for the DocumentDB gateway on :10260. First-boot initdb plus CREATE EXTENSION documentdb is much slower than the old mongod, so those processes can run while the gateway is still down. Mongoose retries; connect-mongo (session store) and the alert task may not, so first boot can break sessions or take down concurrently via --kill-others-on-fail.
Reviewed by Cursor Bugbot for commit 9e64f12. Configure here.


Summary
The all-in-one image now runs DocumentDB (MIT, Postgres 18) in place of MongoDB 4.0.5. That removes the SSPL licence and the four critical OpenSSL 1.1.1k CVEs that came with the Alpine 3.9 MongoDB packages. It uses the same DocumentDB build that local dev, integration and e2e have run on since #3375.
/data/dbmount the docs tell people to use, now under/data/db/pgdata.hyperdx:hyperdxcredentials are fixed. The old mongod was also localhost-only.Breaking changes
/data/dband are not read. The container logs a warning on first boot when it finds them.mongodumpwith the 4.0 tools, thenmongorestoreinto the new container. They were tested from an image built onmainto this branch, and every document and index came across.Implementation detail
docker/documentdb/Dockerfileinto stages ofdocker/hyperdx/Dockerfile. The composedbservice builds thedocumentdbtarget and the all-in-one copies from the same builder, so the two can't drift.apk audit --systemis clean in both images.lddover Postgres, the gateway and the extensions, and fails if the base image's Alpine release is missing a library.scripts/ci/smoke-all-in-one.shpasses, and the migration was run end to end. amd64 and the auth image were not built locally.How to reproduce
Starting point: a checkout of this branch with Docker.
On
main:docker run --rm --entrypoint mongod docker.clickhouse.com/clickhouse/clickstack-all-in-one:2 --versionprints MongoDB 4.0.5.On this branch:
docker buildx build . -f docker/hyperdx/Dockerfile --target all-in-one-noauth --build-context clickhouse=./docker/clickhouse --build-context otel-collector=./docker/otel-collector --build-context hyperdx=./docker/hyperdx --build-context api=./packages/api --build-context app=./packages/app -t aio:local --loadscripts/ci/smoke-all-in-one.sh aio:local. It should printcanary ingested end-to-end.mainimage with-v vol:/data/db, then follow the steps in.changeset/aio-documentdb.md.References
Note
High Risk
Breaking storage and bootstrap behavior for all-in-one upgrades (metadata loss or mandatory migration), plus changes to how the container starts its primary metadata database.
Overview
The all-in-one image replaces bundled MongoDB 4.0.5 with DocumentDB (Postgres 18 + Mongo wire-protocol gateway). Metadata still mounts at
/data/db, but Postgres data lives under/data/db/pgdata. The API keeps using Mongoose via a newMONGO_URI(TLS + SCRAM on port 10260), and the gateway is forced to localhost-only in the production bundle.Breaking for existing volume users: startup fails if legacy Mongo files (
WiredTiger) are present unlessHYPERDX_ACCEPT_EMPTY_METADATA=true; the changeset documents a one-time mongodump / mongorestore migration path.Build/CI: DocumentDB moves from
docker/documentdb/Dockerfileintodocker/hyperdx/Dockerfile(documentdb-builder/documentdbstages) so dev, CI, E2E, and all-in-one share one build; shared libs are installed via apk package lists (avoids cross-Alpine.sooverwrites). The OpenSSL–MongoDB VEX file is removed.entrypoint.shpins postgres UID 70 and fixes volume ownership on boot.Reviewed by Cursor Bugbot for commit 9e64f12. Bugbot is set up for automated code reviews on this repo. Configure here.