Skip to content

chore(dev): run local dev, integration and e2e on DocumentDB - #3375

Open
jordan-simonovski wants to merge 5 commits into
mainfrom
jordansimonovski/documentdb-local-dev
Open

jordan-simonovski wants to merge 5 commits into
mainfrom
jordansimonovski/documentdb-local-dev

Conversation

@jordan-simonovski

Copy link
Copy Markdown
Contributor

Summary

Local development, integration tests and e2e tests now run against open-source DocumentDB (Postgres extensions plus a Mongo wire-protocol gateway, MIT) instead of MongoDB 5.0 (SSPL, end of life). The API is unchanged and still uses Mongoose. Running DocumentDB everywhere internally first surfaces compatibility problems before anything we ship to users changes.

What changed

  • yarn dev, make dev-int, make dev-e2e and the CI integration and e2e jobs all use one DocumentDB image built from docker/documentdb. It is 176 MB, against about 700 MB for mongo:5.0.32-focal.
  • The e2e database helpers use the Node driver instead of docker exec mongosh, because the image doesn't ship mongosh.
  • CI builds the image with the GHA cache and waits on its healthcheck before tests start.
  • Integration teardown retries DocumentDB's intermittent dropDatabase failure (codes 112 and 1, while index builds are running).

Key decisions

  • The image is built from source at a pinned commit, because upstream only ships Ubuntu and EL9 packages. Alpine 3.24 matches the all-in-one image's base, so the same build can be reused there later.
  • The env var names (HDX_*_MONGO_PORT) and the db service name are unchanged, to limit churn across scripts, slots and the dev portal.

Impact

  • Dev data moves to .volumes/docdb_dev_<slot>. Existing local MongoDB data isn't migrated, so the dev stack starts empty after this lands.
  • The first yarn dev builds the image, which takes a few minutes. It is cached after that.
  • To browse the dev database with Compass or mongosh, use the connection string in agent_docs/development.md. Everything works except Compass's Performance tab.
  • Shipped images and the user-facing docker-compose.yml are unchanged.
Implementation detail
  • Image. Postgres 18 with the DocumentDB extensions and gateway. It copies only what those link against: no GDAL, JIT, or PostGIS raster or topology.
  • Alpine build fixes: GNU tar, serial make, and a one-line patch to an upstream symbol check that miscounts musl's _init/_fini.
  • Entrypoint behaviour:
    • it fixes ownership on root-owned volumes, and works on volumes containing lost+found
    • it re-initialises after an interrupted first boot
    • it stops Postgres cleanly on docker stop
    • it exits non-zero if the gateway crashes
  • Healthcheck: probes both the gateway port and Postgres.
  • Testing:
    • make dev-int passes 2273/2273.
    • Full e2e on DocumentDB: 368 passed, 13 failed, 32 flaky. The same suite on main with MongoDB: 380 passed, 9 failed, 28 flaky.
    • On both databases, the failures are Next.js dev-mode page compiles (18 to 30 s) outlasting test timeouts, not database errors. The API logged no database errors.
    • Every test that failed only on DocumentDB passed or was flaky when re-run.
  • API compatibility: checked separately against DocumentDB, including a restore of real MongoDB 4.0.5 data with all 19 indexes (HDX-5709).
  • dropDatabase race: fails in 3 to 5% of drops under a stress test, the same on PG17, PG18 and the Alpine build. HyperDX never drops databases outside tests.

How to reproduce

Starting point: local yarn dev (needs the API and the metadata database).

On main:

  1. Run yarn dev.
  2. docker ps shows the db container running mongo:5.0.32-focal.

On this branch:

  1. Run yarn dev. The first run builds hyperdx/documentdb:local.
  2. docker ps shows the db container running hyperdx/documentdb:local as healthy, and the startup banner lists DocumentDB.
  3. Open the app, register an account, then create a saved search, a dashboard and an alert. All of them persist across a reload.
  4. Run make dev-int. All suites pass.

How to test on Vercel preview

N/A, non-UI change.

References

  • Linear Issue: HDX-5709 (parent HDX-5707)
  • Related PRs:

…of MongoDB

Local development and CI now use open-source DocumentDB (Postgres plus a
Mongo wire-protocol gateway, MIT) in place of MongoDB 5.0 (SSPL, EOL). The
API still talks to it through Mongoose, so this is the first step towards
dropping MongoDB from what we ship, tested daily by every developer and CI
run before users see it. HDX-5709.

- One image, built from source in docker/documentdb and shared by the dev,
  integration and e2e stacks; it handles root-owned volumes, interrupted
  first boots and clean shutdown, and pins the upstream commit.
- e2e database helpers use the Node driver instead of mongosh, which the
  image doesn't ship; CI builds the image with the GHA cache and waits on
  its healthcheck.
- Test teardown retries DocumentDB's intermittent dropDatabase failure.
- Dev data moves to .volumes/docdb_dev_<slot>; old MongoDB volumes are not
  migrated.
@vercel

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

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

2 Skipped Deployments
Project Deployment Actions Updated
hyperdx-oss Ignored Ignored Preview Nov 5, 2026 5:27am UTC
hyperdx-storybook Ignored Ignored Preview Nov 5, 2026 5:27am UTC

Request Review

@github-actions github-actions Bot added the review/tier-3 Standard — full human review required label Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Tier 3 — Standard

Introduces new logic, modifies core functionality, or touches areas with non-trivial risk.

Why this tier:

  • Diff size: 275 production lines changed (Tier 2 max: < 250)
  • Cross-layer change: touches frontend (packages/app) + backend (packages/api)

Additional context: touches background tasks or the delivery pipeline lightly (10 lines, under the 30-line bar for Tier 4)

Review process: Full human review — logic, architecture, edge cases.
SLA: First-pass feedback within 1 business day.

Stats
  • Production files changed: 16
  • Production lines changed: 275 (+ 301 in test files, excluded from tier calculation)
  • Branch: jordansimonovski/documentdb-local-dev
  • Author: jordan-simonovski

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

@github-actions

github-actions Bot commented Oct 15, 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 114 in total (1.37%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Oct 15, 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:

  • 🔴 critical or 🟠 major in code this PR adds or changes: fix before asking for review.
  • 🔵 minor in code this PR changes: your call. Fix if small, otherwise reply.
  • 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
    severity. Reply with one sentence; if it is critical, 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.

2 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 2 minor

None could be anchored to changed lines; they are listed below.

Findings outside the changed lines

2 minor
  • 🔵 packages/app/tests/e2e/utils/db-helpers.ts:887 — The DocumentDB credentials and TLS/auth query string are now hardcoded in about eight places that must be kept in sync by hand → The same hyperdx:hyperdx@…?tls=true&tlsAllowInvalidCertificates=true&authMechanism=SCRAM-SHA-256 string is restated in db-helpers.ts, packages/api/scripts/seed-alerts.ts, .env.development, .env.e2e, .env.test, e2e-setup/action.yml and agent_docs/development.md. DOCDB_USER/DOCDB_PASSWORD are also repeated in three compose files. Changing the user, password or auth mechanism means editing all of them. Fix: export one URI builder (port and db name in, URI out) from a shared module such as packages/api/src/utils/ and use it in seed-alerts.ts. For the e2e helper, build the URI from the same constants, or document there that it intentionally duplicates .env.e2e.
  • 🔵 packages/app/tests/e2e/utils/db-helpers.ts:926 — The catch (e: any) in dropE2eDatabase breaks the repo's 'Avoid any' TypeScript rule → Catch as unknown and narrow it, e.g. const code = e instanceof MongoServerError ? e.code : undefined; with MongoServerError imported from mongodb. Then retry only when code is 1 or 112. This loop also duplicates the backoff logic of withRetry (packages/api/src/utils/retry.ts), which the app package can't import. Add a comment naming that twin so the two retry lists (codes 1 and 112) stay aligned.

Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 460 passed • 1 skipped • 1519s

Status Count
✅ Passed 460
❌ Failed 0
⚠️ Flaky 3
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

Moves development, integration tests, and E2E tests to a source-built DocumentDB image. Shipped deployment images remain unchanged.

  • Local development runs on a shared DocumentDB image.
  • Integration tests now start and wait for DocumentDB.
  • Full-stack E2E tests use DocumentDB through the Node driver.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Dev[Local development] --> Gateway[DocumentDB gateway]
  Int[Integration tests] --> Gateway
  E2E[E2E API and database helpers] --> Gateway
  Gateway --> PG[(Postgres with DocumentDB extensions)]
Loading

Reviews (4) · Last reviewed commit: "Merge branch 'main' into jordansimonovsk..." · Reviewed by Greptile

Comment thread docker/documentdb/entrypoint.sh Resolved
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. This is a dev/test/CI-only migration from MongoDB 5.0 to a source-built DocumentDB image; the API, shipped images, and the root user-facing docker-compose.yml are untouched (verified against the diff). The async-driver conversions are correctly awaited, the dropDatabase retry loops are bounded and net-improve reliability, and both prior review comments are addressed. The findings below are maintainability and hardening items only.

🟡 P2 — recommended

  • packages/app/tests/e2e/utils/db-helpers.ts:16 — the connection-string suffix ?tls=true&tlsAllowInvalidCertificates=true&authMechanism=SCRAM-SHA-256 plus the hyperdx:hyperdx credentials are copied verbatim into six files, so any future TLS or auth-mechanism change must be made in six scattered literals.
    • Fix: Hoist the query-suffix and credentials into a named constant in each of the two TypeScript producers (db-helpers.ts, packages/api/scripts/seed-alerts.ts) and leave a pointer comment in the .env.* files, which genuinely cannot share a fragment.
    • maintainability, security
🔵 P3 nitpicks (6)
  • docker/documentdb/entrypoint.sh:52 — the TERM/INT trap runs under set -e, so if kill "$gateway" returns non-zero (gateway already gone) the handler can abort before pg_ctl ... stop, skipping the clean Postgres shutdown.
    • Fix: Append || true to the kill, or add set +e at the top of the trap handler.
  • packages/app/tests/e2e/utils/db-helpers.ts:46 — catch (e: any) widens the binding from unknown and reads .code unguarded.
    • Fix: Use catch (e: unknown) and narrow before testing e.code against [1, 112].
  • packages/app/tests/e2e/utils/db-helpers.ts:30 — the transient drop-retry codes [1, 112] are repeated as bare magic numbers here and in packages/api/src/fixtures.ts, relying on an adjacent comment that can drift away.
    • Fix: Name them (e.g. DOCUMENTDB_TRANSIENT_DROP_CODES = [1, 112]) in each file so the meaning survives comment edits.
  • docker/documentdb/Dockerfile:44 — the gateway port 10260 is hard-coded in EXPOSE, the HEALTHCHECK, and all three compose files, but its authoritative source is the baked-in upstream SetupConfiguration.json.
    • Fix: Add a one-line comment at EXPOSE/HEALTHCHECK noting the port is dictated by SetupConfiguration.json so an upstream bump is traceable.
  • AGENTS.md:37 — the data-flow line still reads MongoDB (configuration/metadata) while the surrounding Development Setup prose was updated to DocumentDB, leaving a contradictory reference.
    • Fix: Update the data-flow line to reflect DocumentDB as the metadata store.
  • docker-compose.dev.yml:19 — the DocumentDB port is published on 0.0.0.0, making the dev database reachable from the developer's LAN with the known weak hyperdx:hyperdx credentials.
    • Fix: Bind the published port to loopback (e.g. 127.0.0.1:${HDX_DEV_MONGO_PORT}:10260); still a net improvement over the prior unauthenticated MongoDB.

Reviewers (6): correctness, testing, maintainability, security, kieran-typescript, previous-comments.

Testing gaps:

  • dropE2eDatabase / closeDB retry branching (retry on code 1/112, give up after 5 attempts) is new control flow with no direct test, and the DocumentDB-surfaces-[1,112]-on-.code contract it depends on is unasserted anywhere — if the gateway reports different codes, the retry silently stops helping.
  • clearDatabase() in global-setup-fullstack.ts swallows a failed drop and only warns (pre-existing behavior, not introduced here), so a persistent clear failure degrades to a stale-data run rather than a hard failure; the diff's retry reduces but does not remove this path.
  • The reliability and project-standards reviewers did not return before synthesis; the reliability dimension was covered via the correctness reviewer and direct analysis of the entrypoint, healthcheck, and CI --wait gating, which surfaced no additional blocking issues.

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

…s start errors

CI e2e setup failed on every shard: `buildx bake` on the e2e compose file
resolves its out-of-tree build context as a filesystem entitlement and
refuses to run. Build docker/documentdb directly with the same GHA cache.

A failed Postgres start now prints the tail of postgresql.log to the
container logs, so `docker compose logs db` shows the cause.
@changeset-bot

changeset-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a4a8b46

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

The integration job's `up --wait` failed before any test ran: the OTel
collector's healthcheck needs an OpAMP server the job doesn't run, so it
never reports healthy. Start every service as before, then wait on db.
);
}
return `mongodb://localhost:${port}/hyperdx`;
return `mongodb://hyperdx:hyperdx@localhost:${port}/hyperdx?tls=true&tlsAllowInvalidCertificates=true&authMechanism=SCRAM-SHA-256`;

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.

🔵 minor — DocumentDB credentials and TLS options are now hand-copied into six places

The hyperdx:hyperdx user and the tls=true&tlsAllowInvalidCertificates=true&authMechanism=SCRAM-SHA-256 options are hardcoded here, in .env.development, .env.test, .env.e2e, .github/actions/e2e-setup/action.yml and e2eMongoUri() in packages/app/tests/e2e/utils/db-helpers.ts. They must all match DOCDB_USER/DOCDB_PASSWORD in the three compose files, so changing the user or the TLS mode in compose leaves yarn seed:alerts and the e2e helpers failing to authenticate. Here, build the URI by substituting the slot port into process.env.MONGO_URI (already loaded from .env.development), or move the auth/TLS suffix into one exported constant.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Leaving this as is. The .env.* files cannot import a shared fragment and each environment uses its own port and database, so a single constant would only cover the two TypeScript copies. The values are fixed local-dev credentials that change together with the compose files.

services:
db:
image: mongo:5.0.32-focal
image: hyperdx/documentdb:local

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.

🔵 minor — The e2e README still documents MongoDB, its ports and its log commands after the e2e stack switched to DocumentDB

packages/app/tests/e2e/README.md (lines 17-37, 98-124, 397-465) still describes a MongoDB service on 29998/27017 and how to troubleshoot it. The PR updated AGENTS.md and agent_docs but not this file. Update it to describe DocumentDB on HDX_E2E_MONGO_PORT (container port 10260) and the authenticated TLS connection string, and remove the troubleshooting steps that rely on mongosh running inside the container.

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

catinspace-au added a commit to hyperi-io/dfe-hyperdx that referenced this pull request Oct 22, 2026
0006 records DocumentDB 1.0 replacing FerretDB, following ClickHouse/ClickStack#3375. 0001 keeps its text and gains a status line pointing at it, and the index marks it superseded.
Integration shards were rebuilding DocumentDB from source and timing out.
The bake shared one GHA cache scope between the collector and db images,
and a scope holds a single manifest, so each export overwrote the other.
db now uses the documentdb scope the e2e job already fills.
@jordan-simonovski
jordan-simonovski requested a review from a team as a code owner November 5, 2026 05:27

This branch was successfully deployed

2 active (outdated) deployments
Preview – hyperdx-oss — e5de3419 Deployed Oct 20, 2026 by vercel[bot]
Preview – hyperdx-storybook — e5de3419 Deployed Oct 20, 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-3 Standard — full human review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant