Skip to content

feat(docker): run the all-in-one image on DocumentDB instead of MongoDB 4.0.5 - #3734

Open
jordan-simonovski wants to merge 2 commits into
mainfrom
jordansimonovski/documentdb-aio
Open

jordan-simonovski wants to merge 2 commits into
mainfrom
jordansimonovski/documentdb-aio

Conversation

@jordan-simonovski

Copy link
Copy Markdown
Contributor

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.

  • Metadata stays on the /data/db mount the docs tell people to use, now under /data/db/pgdata.
  • The gateway listens on localhost only, because its hyperdx:hyperdx credentials are fixed. The old mongod was also localhost-only.
  • Image size is about the same: 2.47 GB, against 2.49 GB with MongoDB.

Breaking changes

  • Existing all-in-one users start with an empty metadata database after upgrading: users, sources, dashboards, alerts and webhooks. The old MongoDB files stay in /data/db and are not read. The container logs a warning on first boot when it finds them.
  • The changeset carries the one-off migration steps: mongodump with the 4.0 tools, then mongorestore into the new container. They were tested from an image built on main to this branch, and every document and index came across.
  • Helm and Docker Compose deployments are unaffected; they bring their own MongoDB.
Implementation detail
  • The DocumentDB build moves from docker/documentdb/Dockerfile into stages of docker/hyperdx/Dockerfile. The compose db service builds the documentdb target and the all-in-one copies from the same builder, so the two can't drift.
  • Shared libraries are installed with apk from a package list the builder writes, instead of being copied. Copying overwrote the ClickHouse base's musl and libssl with files from another Alpine point release, the same bug as fix(docker): stop clobbering the base image's /usr/lib, and build images on main #3157. apk audit --system is clean in both images.
  • The build runs ldd over Postgres, the gateway and the extensions, and fails if the base image's Alpine release is missing a library.
  • The postgres user is pinned to UID/GID 70, so files on a volume keep the right owner across upgrades.
  • The MongoDB VEX file is gone, since nothing it covered ships any more.
  • Tested locally on arm64: scripts/ci/smoke-all-in-one.sh passes, 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:

  1. docker run --rm --entrypoint mongod docker.clickhouse.com/clickhouse/clickstack-all-in-one:2 --version prints MongoDB 4.0.5.

On this branch:

  1. Build the image: 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 --load
  2. Run scripts/ci/smoke-all-in-one.sh aio:local. It should print canary ingested end-to-end.
  3. To test the upgrade, run the main image with -v vol:/data/db, then follow the steps in .changeset/aio-documentdb.md.

References

…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.
@jordan-simonovski
jordan-simonovski requested a review from a team as a code owner November 19, 2026 23:03
@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 24, 2026 6:33am UTC
hyperdx-storybook Ready Ready Preview Nov 24, 2026 6:33am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9353406

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/api Minor
@hyperdx/app Minor
@hyperdx/otel-collector Minor

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

@github-actions github-actions Bot added the review/tier-4 Critical — deep review + domain expert sign-off label Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🔴 Tier 4 — Critical

Touches 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:

  • Background tasks or delivery pipeline substantially modified — 100 lines (bar: 30):
    • docker/hyperdx/Dockerfile
    • docker/hyperdx/entry.local.base.sh

Review process: Deep review from a domain expert. Synchronous walkthrough may be required.
SLA: Schedule synchronous review within 2 business days.

Stats
  • Production files changed: 7
  • Production lines changed: 310 (+ 5 in test files, excluded from tier calculation)
  • Critical-path lines changed: 100
  • Branch: jordansimonovski/documentdb-aio
  • Author: jordan-simonovski

To override this classification, remove the review/tier-4 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 107 in total (1.12%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

Comment thread docker/hyperdx/Dockerfile
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 \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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 \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

4 finding(s): 🔴 1 P0/P1 · 🟡 1 P2 · 🔵 2 P3

1 posted as inline comment(s) on the changed lines. 1 listed below. 2 P3 folded at the bottom.

Findings outside the changed lines

  • 🟡 P2 docker/documentdb/entrypoint.sh:15 — Postgres log now goes to the persistent /data/db volume with no rotation → In the all-in-one image, pg_ctl -l "$PGDATA/postgresql.log" writes to /data/db/pgdata/postgresql.log, which is the user's persistent volume. Nothing rotates or truncates it, so it grows across restarts for the life of the volume. The old mongod logged with --quiet to /var/log, inside the container. Write the log under /var/log, or turn on logging_collector with log_rotation_size and log_truncate_on_rotation in the config appended at first boot.
🔵 2 P3 — no action needed before merge
  • 🔵 P3 README.md:48 — README and DEPLOY.md still say the all-in-one and local images bundle MongoDB → Change README.md:47-48 and DEPLOY.md:96 (the Local Development Mode section, which uses the same image) to say DocumentDB. Also update the stale "adds ClickHouse, MongoDB" comment in .github/workflows/docker-build.yml:168. These docs are what users will check when their metadata disappears after the upgrade.
  • 🔵 P3 docker/hyperdx/Dockerfile:264 — The DocumentDB runtime setup is written out twice, in the documentdb and all-in-one-base stages → Both stages repeat apk add bash openssl su-exec $(cat /etc/documentdb/apk-packages), the UID/GID 70 postgres addgroup/adduser, and the entrypoint COPY. A change to one (a new runtime package, a different UID) can be missed in the other, which undercuts the PR's claim that the two "can't drift". Move these steps into a small script in the builder output, for example /out/usr/local/sbin/documentdb-setup.sh, and run it from both stages.

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.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

This infrastructure PR swaps the all-in-one image's metadata store from MongoDB 4.0.5 to DocumentDB (Postgres 18), folding the DocumentDB build into docker/hyperdx/Dockerfile and rewiring the dev/ci/e2e compose files to the new documentdb target. The build-level design is solid: the ldd gate, the apk-package list approach (avoiding the libssl/musl overwrite bug), and the UID/GID 70 pinning are all defensible. The findings below are operational and test-coverage gaps, not build defects.

🟡 P2 -- recommended

  • docker/hyperdx/entry.local.base.sh:64 -- On upgrade, the all-in-one image starts with an empty metadata database (users, sources, dashboards, alerts); for the auth image this silently drops all user accounts and stops alerting, with the only runtime signal being a stdout WARNING gated on /data/db/WiredTiger and a manual mongodump/mongorestore path.
    • Fix: Add a more durable first-boot safeguard than a single log line — surface the stale-data condition in the UI or health output, or gate startup behind an explicit opt-in env var when legacy MongoDB files are detected.
    • ce-correctness-reviewer, ce-reliability-reviewer, ce-data-migrations-reviewer
  • .github/workflows/docker-build.yml:267 -- CI builds the all-in-one-auth target but only boots the noauth target in smoke-all-in-one.sh, so the DocumentDB-backed auth boot and the INGESTION_API_KEY bootstrap write path are never exercised, even though the smoke script already ships a --health-only mode written for exactly that image.
    • Fix: Add a smoke step that boots the built all-in-one-auth image with --health-only so the auth DocumentDB startup path is covered in CI.
    • ce-testing-reviewer, ce-reliability-reviewer
🔵 P3 nitpicks (2)
  • docker/documentdb/entrypoint.sh:50 -- The TERM/INT trap that cleanly stops Postgres so volumes skip crash recovery never fires in the all-in-one, because PID 1 (entry.local.base.sh) does not forward SIGTERM to the backgrounded entrypoint, so every docker stop forces WAL crash recovery on next boot.
    • Fix: Forward signals from the entry script to the DocumentDB child, or document that the clean-shutdown path only applies to the standalone compose service.
  • docker/hyperdx/entry.local.base.sh:69 -- DocumentDB is backgrounded and the app is launched under concurrently --kill-others-on-fail without a readiness gate, unlike ClickHouse which has an explicit wait loop; on slow first-boot initialization the API relies entirely on Mongoose connection retries.
    • Fix: Add a readiness wait on 127.0.0.1:10260 before starting the app, mirroring the existing ClickHouse wait loop.

Reviewers (8): ce-correctness-reviewer, ce-reliability-reviewer, ce-testing-reviewer, ce-maintainability-reviewer, ce-security-reviewer, ce-data-migrations-reviewer, ce-project-standards-reviewer, ce-previous-comments-reviewer.

Testing gaps:

  • Auth all-in-one image boot path (DocumentDB startup + user bootstrap) is not booted in CI.
  • No automated test covers the MongoDB→DocumentDB upgrade/migration scenario; it was validated manually only.
  • Prior PR comments were all bot-generated (Vercel, changeset-bot, triage, jscpd, e2e) — no substantive human feedback existed to verify.

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

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 472 passed • 1 skipped • 1080s

Status Count
✅ Passed 472
❌ Failed 0
⚠️ Flaky 13
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

…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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 93534066 Deployed Nov 24, 2026 by vercel[bot]
Preview – hyperdx-storybook — 93534066 Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-4 Critical — deep review + domain expert sign-off

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants