Skip to content

feat: switch heartbeat repositories to use MongoDB directly#892

Merged
AchoArnold merged 1 commit into
mainfrom
migrate-heartbeat-monitors-to-mongodb
May 17, 2026
Merged

feat: switch heartbeat repositories to use MongoDB directly#892
AchoArnold merged 1 commit into
mainfrom
migrate-heartbeat-monitors-to-mongodb

Conversation

@AchoArnold
Copy link
Copy Markdown
Member

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

  • 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

Migration Plan

  1. This PR — deploy with \HEARTBEAT_DB_BACKEND=hedging\ which now uses MongoDB directly
  2. After verifying production stability, switch env to \mongodb\ and remove the GORM fallback

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>
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics -16 complexity · 0 duplication

Metric Results
Complexity -16
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 first step of migrating heartbeat repositories from a dual-write (hedging) pattern to MongoDB directly. It deletes the two hedging repository implementations, removes the HedgingFailureCounter OTel metric from the DI container, and updates the factory functions so that HEARTBEAT_DB_BACKEND=hedging now routes to the MongoDB backend instead of the old dual-write shim.

  • container.go: Both HeartbeatMonitorRepository() and HeartbeatRepository() now treat \"mongodb\" and \"hedging\" identically, each constructing a MongoHeartbeat*Repository directly.
  • hedging_heartbeat_monitor_repository.go / hedging_heartbeat_repository.go: Both deleted — all dual-write logic is gone.
  • go.mod / go.sum: github.com/schollz/progressbar/v3 is added as a direct dependency but is not imported anywhere in the source tree, making it appear to be an accidental inclusion.

Confidence Score: 4/5

The 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

Filename Overview
api/go.mod Adds schollz/progressbar/v3 as a direct dependency, but it is not imported anywhere in the codebase — appears to be an accidental inclusion.
api/go.sum Adds checksums for progressbar and its transitive deps; these are unneeded and should be removed alongside go.mod changes.
api/pkg/di/container.go Removes HedgingFailureCounter and collapses "hedging" into the "mongodb" case for both HeartbeatMonitorRepository and HeartbeatRepository factories — clean, minimal change.
api/pkg/repositories/hedging_heartbeat_monitor_repository.go Deleted — dual-write hedging repository removed as part of migration to MongoDB-only.
api/pkg/repositories/hedging_heartbeat_repository.go Deleted — dual-write hedging repository removed as part of migration to MongoDB-only.

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
Loading

Reviews (1): Last reviewed commit: "feat: switch heartbeat repositories to u..." | Re-trigger Greptile

Comment thread api/go.mod
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
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 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.

@AchoArnold AchoArnold merged commit 49901d0 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