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
MongoDB 4 driver instrumentation #2043
Conversation
private static final BsonValue HIDDEN_CHAR = new BsonString("?"); | ||
|
||
private static BsonDocument scrub(final BsonDocument origin) { | ||
final BsonDocument scrub = new BsonDocument(); |
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.
I know we do this elsewhere, but I know from experience with this driver thatBsonDocument
(having maintained a private fork) is quite heavy - every value is wrapped in a BsonValue
. What we could be doing here is piping the document into a BsonWriter
which writes the scrubbed value into a StringBuilder
:
ScrubbingBsonWriter scrubber = new ScrubbingBsonWriter(new StringBuilder()); // implements org.bson.BsonWriter
scrubber.pipe(new BsonDocumentReader(statement));
CharSequence scrubbed = scrubber.getOutput()
I have an example of how to do this sort of thing (which just prints out the attributed weight of a BSON document) here. This will be quite handy for getting the overhead of this instrumentation down.
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.
cool - yes, this approach comes from the old MongoDB 3 instrumentation - thanks for the link
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.
Looks reasonable, perhaps we could revisit the performance of the scrubbing for all instrumentation versions in another PR.
One small request - could you fixup the commit which changes the Java version for the tests so we don't have a commit for which tests couldn't pass? |
Covers both sync and reactivestreams clients
1f53b31
to
0f4f768
Compare
pass { | ||
group = "org.mongodb" | ||
module = "mongodb-driver-core" | ||
versions = "[3.7,)" |
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.
This version number ideally should align with the project name. Any reason for the mismatch?
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.
Comes down to how MongoDB evolved MongoClientOptions
into MongoClientSettings
- the v3 instrumentation works with early v3 drivers and the latest legacy drivers (both v3 and v4) that use MongoClientOptions
. Whereas the v4 instrumentation works with the newer sync and reactivestreams drivers that use MongoClientSettings
- but is also compatible with early releases of those drivers back to 3.7.
Since v3 based applications tend to use the legacy driver, and v4 based applications typically use the sync or reactivestreams drivers I decided it was simpler to mark the new instrumentation as v4, but declare in the muzzle spec that this will also work with earlier releases (when using the newer client API that uses MongoClientSettings
).
Also because no Mongo client uses both MongoClientOptions
and MongoClientSettings
there's no risk of double instrumentation.
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.
@mcculls would you mind adding a comment in the gradle file describing your reasoning here?
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.
Covers both
mongodb-driver-sync
andmongodb-driver-reactivestreams
clients