Skip to content

refactor: remove hedging tag, use mongodb directly for heartbeats#893

Merged
AchoArnold merged 1 commit into
mainfrom
remove-hedging-use-mongodb-directly
May 17, 2026
Merged

refactor: remove hedging tag, use mongodb directly for heartbeats#893
AchoArnold merged 1 commit into
mainfrom
remove-hedging-use-mongodb-directly

Conversation

@AchoArnold
Copy link
Copy Markdown
Member

Summary

Now that the migration is deployed and stable, remove the hedging case from the HEARTBEAT_DB_BACKEND switch. Only mongodb is recognized going forward.

Changes

  • api/pkg/di/container.go - Remove hedging from both HeartbeatMonitorRepository() and HeartbeatRepository() switch cases
  • tests/.env.test - Update HEARTBEAT_DB_BACKEND=hedging to HEARTBEAT_DB_BACKEND=mongodb

Deployment

Update the production environment variable from HEARTBEAT_DB_BACKEND=hedging to HEARTBEAT_DB_BACKEND=mongodb after merging.

Now that the migration is complete, remove the 'hedging' case from the
HEARTBEAT_DB_BACKEND switch. Only 'mongodb' is supported going forward.

- Update DI container to only recognize 'mongodb' case
- Update integration test .env.test to use HEARTBEAT_DB_BACKEND=mongodb

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 17, 2026

Greptile Summary

This PR completes the MongoDB migration for heartbeat data by removing the "hedging" dual-write case from the HEARTBEAT_DB_BACKEND switch in both HeartbeatMonitorRepository and HeartbeatRepository, and updates the test env file to match.

  • api/pkg/di/container.go — Both repository factory methods now only recognise \"mongodb\"; any other value (including the old \"hedging\" value still present in production) silently falls to the GORM/PostgreSQL default branch. Deploying this code while the production env var is still \"hedging\" will cause a silent backend downgrade with no error surfaced.
  • tests/.env.testHEARTBEAT_DB_BACKEND updated from hedging to mongodb, keeping the test environment consistent with the new logic.

Confidence Score: 3/5

Safe to merge only if the production env var is updated atomically with the deploy; deploying ahead of the env var change will silently route heartbeat traffic to the old GORM backend.

Both repository factory methods now fall through to the GORM backend for any value that isn't exactly "mongodb", including the "hedging" string that production currently holds. There is no log warning, panic, or error when an unrecognised value hits the default branch, so a deployment-before-env-var-update scenario fails invisibly.

api/pkg/di/container.go — the default branches in both heartbeat repository constructors need a guard for unrecognised configuration values.

Important Files Changed

Filename Overview
api/pkg/di/container.go Removes "hedging" from both heartbeat repository switch cases; the remaining default branch silently falls back to GORM if the env var isn't updated to "mongodb" before deployment.
tests/.env.test Updates HEARTBEAT_DB_BACKEND from "hedging" to "mongodb" in the test environment, correctly aligning tests with the new switch behaviour.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Container.HeartbeatRepository / HeartbeatMonitorRepository] --> B{HEARTBEAT_DB_BACKEND env var}
    B -- "mongodb" --> C[NewMongoHeartbeatRepository\nNewMongoHeartbeatMonitorRepository]
    B -- "hedging" (old value)\nor anything else --> D[default: NewGormHeartbeatRepository\nNewGormHeartbeatMonitorRepository]
    D --> E[⚠️ Silent fallback to GORM\nif env var not updated before deploy]
    C --> F[✅ MongoDB backend]
Loading

Comments Outside Diff (1)

  1. api/pkg/di/container.go, line 907-922 (link)

    P1 Silent GORM fallback if env var isn't updated before deploy

    After this change, any value other than "mongodb" — including the old "hedging" value that production currently has — will silently fall through to the default case and instantiate the GORM/PostgreSQL-backed repository. If the production HEARTBEAT_DB_BACKEND env var is still set to "hedging" at the moment this code is deployed, both HeartbeatMonitorRepository and HeartbeatRepository will silently switch from MongoDB to GORM with no error or log warning, risking data inconsistency between the two backends. The same applies in HeartbeatRepository at line ~1736. Consider adding a panic or container.logger.Fatal in the default branch for unrecognised values so a misconfiguration surfaces loudly rather than silently downgrading the backend.

Reviews (1): Last reviewed commit: "refactor: remove hedging tag, use mongod..." | Re-trigger Greptile

@AchoArnold AchoArnold merged commit d0482a4 into main May 17, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant