feat: switch heartbeat repositories to use MongoDB directly#892
Conversation
Replace the hedging dual-write pattern with direct MongoDB usage for heartbeat monitors and heartbeats. When HEARTBEAT_DB_BACKEND is set to 'hedging', it now routes to MongoDB instead of the dual-write hedging repository. This is the first migration step before switching to MongoDB completely. - Remove hedging_heartbeat_monitor_repository.go - Remove hedging_heartbeat_repository.go - Remove HedgingFailureCounter from DI container - Route 'hedging' env value to MongoDB in both repository factories Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | -16 |
| Duplication | 0 |
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 SummaryThis PR completes the first step of migrating heartbeat repositories from a dual-write (hedging) pattern to MongoDB directly. It deletes the two hedging repository implementations, removes the
Confidence Score: 4/5The repository-routing change is safe to deploy with the existing HEARTBEAT_DB_BACKEND=hedging setup, but go.mod includes an unused direct dependency that should be cleaned up before merging. The container and repository deletions are straightforward and correct. The only unexpected change is github.com/schollz/progressbar/v3 being added as a direct (non-indirect) entry in go.mod with no corresponding import in any .go file — this dependency and its four transitive packages should not be in the module graph. api/go.mod and api/go.sum — the progressbar dependency and its transitive entries should be removed. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
ENV[HEARTBEAT_DB_BACKEND env var]
ENV -->|mongodb or hedging| MONGO[NewMongoHeartbeatRepository - MongoDB]
ENV -->|default| GORM[NewGormHeartbeatRepository - PostgreSQL via GORM]
subgraph Removed
HEDGE[HedgingHeartbeatRepository - dual-write GORM primary + MongoDB secondary]
end
style Removed fill:#fdd,stroke:#f66,stroke-dasharray:5
Reviews (1): Last reviewed commit: "feat: switch heartbeat repositories to u..." | Re-trigger Greptile |
| github.com/redis/go-redis/extra/redisotel/v9 v9.19.0 | ||
| github.com/redis/go-redis/v9 v9.19.0 | ||
| github.com/rs/zerolog v1.35.1 | ||
| github.com/schollz/progressbar/v3 v3.19.0 |
There was a problem hiding this comment.
Unrelated direct dependency added
github.com/schollz/progressbar/v3 is listed as a direct (non-// indirect) dependency in go.mod, but it is not imported anywhere in the Go source tree — not in container.go, cmd/migration/main.go, or any other .go file. This looks like an accidental inclusion that brings in three additional transitive packages (mitchellh/colorstring, rivo/uniseg, chengxilo/virtualterm, golang.org/x/term). Unused direct dependencies should be removed to keep the module graph clean.
Summary
Replace the hedging dual-write pattern with direct MongoDB usage for heartbeat monitors and heartbeats. When \HEARTBEAT_DB_BACKEND\ is set to \hedging, it now routes to MongoDB instead of the dual-write hedging repository.
This is the first migration step before switching to MongoDB completely.
Changes
Migration Plan