-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add metadata to mongodb client #9997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: alpha
Are you sure you want to change the base?
feat: Add metadata to mongodb client #9997
Conversation
|
🚀 Thanks for opening this pull request! |
📝 WalkthroughWalkthroughAdds driver metadata (name: "Parse Server", version from package.json) to MongoDB client connections in two storage adapters and adds tests verifying the metadata is propagated to the MongoDB driver. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Adapter as Parse Adapter
participant MongoClient as mongodb.MongoClient
participant MongoDB as MongoDB Server
Note over Adapter,MongoClient: Adapter builds connection options\nincluding driverInfo {name, version}
Adapter->>MongoClient: connect(uri, {...options, driverInfo})
MongoClient->>MongoDB: handshake with driverInfo metadata
MongoDB-->>MongoClient: handshake response
MongoClient-->>Adapter: connected client instance
Note right of Adapter: Tests inspect client.s.options.driverInfo\n(or internal fields) to verify metadata
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
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 |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
I will reformat the title to use the proper commit message syntax. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/Adapters/Storage/Mongo/MongoStorageAdapter.js (1)
187-187: Add missing semicolon for consistency.The closing brace on line 187 is missing a semicolon, which is inconsistent with the rest of the codebase style.
🔎 Suggested fix
const driverInfo = { name: 'Parse Server', version: pkg.version, - } + };src/Adapters/Files/GridFSBucketAdapter.js (1)
49-56: Add missing semicolon for consistency.The implementation correctly mirrors the MongoStorageAdapter pattern. However, the closing brace on line 53 is missing a semicolon.
🔎 Suggested fix
const driverInfo = { name: 'Parse Server', version: pkg.version, - }; + }; const mongoclient = new MongoClient(this._databaseURI, this._mongoOptions);
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
spec/GridFSBucketStorageAdapter.spec.jsspec/MongoStorageAdapter.spec.jssrc/Adapters/Files/GridFSBucketAdapter.jssrc/Adapters/Storage/Mongo/MongoStorageAdapter.js
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-12-02T08:00:20.138Z
Learning: For Parse Server 9 release (PR #9938 and related), the parse/push-adapter dependency must be upgraded to version >= 8.0.0, not 7.0.0. Version 8.x drops support for Node 18.
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.940Z
Learning: When reviewing Parse Server PRs that add new features, always check whether the feature is documented in the README.md file, though for new Parse Server options this is optional rather than required.
📚 Learning: 2025-12-02T08:00:20.138Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-12-02T08:00:20.138Z
Learning: For Parse Server 9 release (PR #9938 and related), the parse/push-adapter dependency must be upgraded to version >= 8.0.0, not 7.0.0. Version 8.x drops support for Node 18.
Applied to files:
src/Adapters/Files/GridFSBucketAdapter.jssrc/Adapters/Storage/Mongo/MongoStorageAdapter.js
📚 Learning: 2025-05-09T09:59:06.289Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: Tests in the parse-server repository should use promise-based approaches rather than callback patterns with `done()`. Use a pattern where a Promise is created that resolves when the event occurs, then await that promise.
Applied to files:
spec/MongoStorageAdapter.spec.jsspec/GridFSBucketStorageAdapter.spec.js
📚 Learning: 2025-11-08T13:46:04.940Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.940Z
Learning: For new Parse Server options, verify that the option is documented in src/Options/index.js and that npm run definitions has been executed to reflect changes in src/Options/docs.js and src/Options/Definitions.js. README.md documentation is a bonus but not required for new options.
Applied to files:
src/Adapters/Storage/Mongo/MongoStorageAdapter.js
📚 Learning: 2025-05-04T20:41:05.147Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 9445
File: spec/ParseLiveQuery.spec.js:1312-1338
Timestamp: 2025-05-04T20:41:05.147Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`.
Applied to files:
spec/GridFSBucketStorageAdapter.spec.js
📚 Learning: 2025-05-09T09:59:06.289Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`. The preferred pattern is to create a Promise that resolves when an expected event occurs, then await that Promise.
Applied to files:
spec/GridFSBucketStorageAdapter.spec.js
🧬 Code graph analysis (2)
src/Adapters/Files/GridFSBucketAdapter.js (1)
src/Adapters/Storage/Mongo/MongoStorageAdapter.js (3)
driverInfo(184-187)mongoclient(188-188)MongoClient(26-26)
spec/GridFSBucketStorageAdapter.spec.js (1)
src/Adapters/Files/GridFSBucketAdapter.js (1)
GridFSBucketAdapter(16-261)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Node 20
- GitHub Check: MongoDB 8, ReplicaSet
- GitHub Check: Redis Cache
- GitHub Check: Node 22
- GitHub Check: MongoDB 7, ReplicaSet
- GitHub Check: PostgreSQL 17, PostGIS 3.5
- GitHub Check: PostgreSQL 16, PostGIS 3.5
- GitHub Check: Benchmarks
- GitHub Check: PostgreSQL 18, PostGIS 3.6
- GitHub Check: Docker Build
🔇 Additional comments (3)
spec/GridFSBucketStorageAdapter.spec.js (1)
479-487: LGTM! Test correctly verifies metadata propagation.The test properly uses async/await and validates that the MongoDB driver receives the correct driverInfo. While accessing
_client.s.optionsrelies on MongoDB driver internals, this is currently the most practical way to verify the metadata was applied.spec/MongoStorageAdapter.spec.js (1)
452-460: LGTM! Metadata validation test is correct.The test follows async/await best practices and properly verifies the driverInfo metadata. Consistent with the GridFSBucketAdapter test implementation.
src/Adapters/Storage/Mongo/MongoStorageAdapter.js (1)
183-190: appendMetadata API is confirmed available in MongoDB driver 6.20.0.The
appendMetadata()method is supported in mongodb v6.20.0 (introduced in v6.18.0) and the implementation correctly passes the driverInfo object with name and version fields. No changes needed.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #9997 +/- ##
=======================================
Coverage 92.53% 92.53%
=======================================
Files 190 190
Lines 15470 15474 +4
Branches 176 176
=======================================
+ Hits 14315 14319 +4
Misses 1143 1143
Partials 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
08d9a9e to
f4a93ae
Compare
|
See #9996 (comment) |
|
@coderabbitai see the discussion in #9930 and suggest the required changes in this PR to make this an opt-in feature. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 22790 @mtrezza Based on the discussion in PR #9930, here are the required changes to make this an opt-in feature: Implementation Changes Required1. Add a new Parse Server optionAdd a new option in /**
* Custom metadata to append to MongoDB client connections for identifying Parse Server instances in MongoDB logs.
* If set, this metadata will be visible in mongos/mongod logs during connection handshakes.
* This can help with debugging and monitoring in deployments with multiple database clients.
* Set to a string value like a deployment identifier, server version, or commit hash.
* Leave undefined (default) to disable this feature and avoid the additional data transfer overhead.
* @type {string}
* @default undefined
*/
mongoDBClientMetadata: undefined,2. Update MongoStorageAdapterModify async connect() {
if (this.connectionPromise) {
return this.connectionPromise;
}
// Remove the pkg import from top of file
// Only use driverInfo if mongoDBClientMetadata option is set
const options = { ...this._mongoOptions };
if (this.mongoOptions.mongoDBClientMetadata) {
options.driverInfo = {
name: this.mongoOptions.mongoDBClientMetadata,
version: pkg.version
};
}
this.connectionPromise = MongoClient.connect(encodedUri, options)
.then(client => {
// ... rest of the connection logic
});
return this.connectionPromise;
}3. Update GridFSBucketAdapterSimilarly modify async _connect() {
if (!this._connectionPromise) {
const options = { ...this._mongoOptions };
if (this._mongoOptions.mongoDBClientMetadata) {
options.driverInfo = {
name: this._mongoOptions.mongoDBClientMetadata,
version: pkg.version
};
}
this._connectionPromise = MongoClient.connect(this._uri, options).then(client => {
this._client = client;
return client.db(this._databaseName);
});
}
return this._connectionPromise;
}4. Update testsModify the tests to verify opt-in behavior: In it('should not pass metadata to MongoClient by default', async () => {
const adapter = new MongoStorageAdapter({ uri: databaseURI });
await adapter.connect();
expect(adapter.client.s.options.driverInfo).toBeUndefined();
});
it('should pass custom metadata to MongoClient when configured', async () => {
const customMetadata = 'MyParseServer-v1.0.0';
const adapter = new MongoStorageAdapter({
uri: databaseURI,
mongoDBClientMetadata: customMetadata
});
await adapter.connect();
expect(adapter.client.s.options.driverInfo.name).toBe(customMetadata);
expect(adapter.client.s.options.driverInfo.version).toBe(require('../package.json').version);
});Similar changes in 5. Run npm definitionsAfter updating npm run definitionsThis will automatically update RationaleThis opt-in approach addresses the concerns from PR #9930:
Would you like me to generate a complete code example for any of these changes? 🧠 Learnings used |
Pull Request
Issue
Closes: #9996
Approach
Added a call to
MongoClient.appendMetadata()before callingMongoClient.connect()insideMongoStorageAdapterandGridFSBucketAdapterclasses so that medatata is appended from the moment a connection is opened to MongoDB.Tasks
Add changes to documentation (guides, repository pages, code comments)Add security checkAdd new Parse Error codes to Parse JS SDKSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.