Convert MongoDB from standalone to replica set#4184
Conversation
Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 Walkthrough🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
deploy/helm/thecombine/charts/database/templates/database.yaml (1)
49-54: Consider parameterizing replica-set values in chart config.
rs0anddatabase:27017are hardcoded here. Moving them to Helm values reduces drift risk across deployment, scripts, and connection strings.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@deploy/helm/thecombine/charts/database/templates/database.yaml` around lines 49 - 54, The template hardcodes the replica set name and host/port; change database/templates/database.yaml to use Helm values instead of "rs0" and "database:27017" by replacing the args entry ("--replSet", "rs0") and the env var MONGO_INITDB_REPLICA_HOST value with templated values (e.g., .Values.database.replicaSetName and .Values.database.hostPort or similar), and add corresponding defaults in values.yaml (e.g., database.replicaSetName: "rs0", database.hostPort: "database:27017"); ensure the template uses proper Helm quoting/template syntax so the rendered args and env.value are valid.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.vscode/tasks.json:
- Around line 30-38: The "run-mongo" VSCode task currently invokes "mongod"
directly with args ("--dbpath", "${workspaceFolder}/mongo_database",
"--replSet", "rs0") which enables replica-set mode but does not run
rs.initiate(), causing first-run connection failures; update the "run-mongo"
task to run the existing initialization script instead (invoke "npm run
database" or the equivalent npm script used to start and initialize the DB) so
the startup sequence performs replica set initialization automatically; keep the
task label "run-mongo" and replace the "command":"mongod" invocation with a
command that runs the npm script (ensuring the task type and args are adjusted
to execute the npm script).
In `@scripts/startDatabase.js`:
- Around line 51-66: The startup currently logs readiness/init failures and
drops mongod exit codes, allowing the process to succeed incorrectly; update the
logic around waitForMongo() and initReplicaSet() (functions referenced) to treat
failures as fatal (throw or return falsy should cause process.exit with a
non-zero code), ensure initReplicaSet() errors are awaited and checked (or
caught and cause process.exit(1)), and replace the final Promise that resolves
the mongod "close" event with logic that reads the child process exit code and
calls process.exit(code || 1) so any non-zero or unexpected termination results
in a non-zero exit; also ensure the SIGINT/SIGTERM handlers forward termination
(stop/kill mongod) but do not swallow failure—propagate error/exit accordingly.
---
Nitpick comments:
In `@deploy/helm/thecombine/charts/database/templates/database.yaml`:
- Around line 49-54: The template hardcodes the replica set name and host/port;
change database/templates/database.yaml to use Helm values instead of "rs0" and
"database:27017" by replacing the args entry ("--replSet", "rs0") and the env
var MONGO_INITDB_REPLICA_HOST value with templated values (e.g.,
.Values.database.replicaSetName and .Values.database.hostPort or similar), and
add corresponding defaults in values.yaml (e.g., database.replicaSetName: "rs0",
database.hostPort: "database:27017"); ensure the template uses proper Helm
quoting/template syntax so the rendered args and env.value are valid.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
.gitignore.vscode/tasks.jsonBackend/appsettings.jsonREADME.mddatabase/init/00-replica-set.jsdeploy/helm/thecombine/charts/database/templates/database.yamlpackage.jsonscripts/setupMongo.jsscripts/startDatabase.js
💤 Files with no reviewable changes (1)
- scripts/setupMongo.js
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
Fixed in d0942b0. The |
|
@copilot In |
Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
Fixed in 2c9afee. Changes to
|
Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4184 +/- ##
=======================================
Coverage 74.95% 74.95%
=======================================
Files 302 302
Lines 11090 11090
Branches 1394 1394
=======================================
Hits 8312 8312
Misses 2378 2378
Partials 400 400
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
scripts/startDatabase.jsto startmongodwith--replSet rs0and initialize replica set.gitignoreto includestartDatabase.jsexception; removesetupMongo.jsexceptionscripts/setupMongo.js(functionality absorbed intostartDatabase.js)package.jsonto use new database start script (removepredatabase, updatedatabase)database/init/00-replica-set.jsfor first-time Docker replica set initializationdatabase.yamlto add--replSet rs0argument andMONGO_INITDB_REPLICA_HOSTenv var.vscode/tasks.jsonrun-mongotask to invokenpm run database(includes replica set init)appsettings.jsonto reference replica set (?replicaSet=rs0)README.mdMongoDB Compass connection stringscripts/startDatabase.jsand.vscode/tasks.jsonstartDatabase.jsfailures fatal: register SIGINT/SIGTERM before waiting, exit(1) if mongo doesn't start or replicaset init fails, propagate mongod exit code viaprocess.exit(exitCode ?? 1)Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.
This change is
Summary by CodeRabbit
New Features
Documentation
Chores