Skip to content

Add Client Metadata Update Support. #1708

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

Merged
merged 48 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9753f28
Add Client Metadata update support.
vbabanin May 6, 2025
889d5c8
Add prose tests.
vbabanin May 8, 2025
4b3065c
Add prose tests.
vbabanin May 8, 2025
2a684bf
Add ClientMetadata entity.
vbabanin May 8, 2025
28c1844
Update tests.
vbabanin May 8, 2025
371ce0b
Merge branch 'main' into JAVA-5854
vbabanin May 8, 2025
972fe9d
Fix tests.
vbabanin May 8, 2025
bcf9cc8
Fix tests.
vbabanin May 8, 2025
179b262
Spotless fix.
vbabanin May 8, 2025
bc43ba0
Skip tests when auth is enabled.
vbabanin May 9, 2025
3f5fc91
Apply Scala spotless.
vbabanin May 9, 2025
61192d8
Update tests.
vbabanin May 10, 2025
e9f8dd6
Fix tests.
vbabanin May 10, 2025
95c1bb1
Add parametrized tests.
vbabanin May 19, 2025
dd63a49
Apply Kotlin spotless.
vbabanin May 19, 2025
89d67bb
Move update to separate variables.
vbabanin May 19, 2025
8a18d39
Merge branch 'main' into JAVA-5854
vbabanin May 20, 2025
f296d0c
Merge branch 'main' into JAVA-5854
vbabanin May 20, 2025
a8dc4fb
Add lock for updates.
vbabanin May 21, 2025
8ade58b
Clone document before passing it as an argument.
vbabanin May 21, 2025
71350fa
Rename to "appendMetadata".
vbabanin May 21, 2025
9890aa1
Add ReadWriteLock and rename method.
vbabanin May 27, 2025
28f7d88
Add parametrized tests.
vbabanin Jun 4, 2025
246a040
Add readLock.
vbabanin Jun 4, 2025
8a58294
Fix readLock issue.
vbabanin Jun 4, 2025
15ecef8
Merge branch 'main' into JAVA-5854
vbabanin Jun 4, 2025
5c7a6e3
Add Kotlin and Scala API.
vbabanin Jun 6, 2025
f466d08
Add unified tests.
vbabanin Jun 10, 2025
3132541
Merge branch 'main' into JAVA-5854
vbabanin Jun 10, 2025
d961447
Fix static checks.
vbabanin Jun 10, 2025
74d8558
Change specification submodule commit.
vbabanin Jun 10, 2025
31ef18e
Revert specifications submodule URL to upstream repository.
vbabanin Jun 17, 2025
38ba5e6
Update specifications submodule commit hash.
vbabanin Jun 17, 2025
edafc54
Merge branch 'main' into JAVA-5854
vbabanin Jun 17, 2025
6aa0a1e
Merge branch 'main' into JAVA-5854
vbabanin Jun 17, 2025
dab5451
Remove duplicate import of CLIENT_METADATA in MultiServerClusterSpeci…
vbabanin Jun 17, 2025
1550122
Merge branch 'main' into JAVA-5854
vbabanin Jun 19, 2025
b5c4c20
Remove ClientMetadataHelper.
vbabanin Jun 20, 2025
b6b4d67
Update native-image.properties.
vbabanin Jun 20, 2025
d43972d
Refactor tests to use JUnit assertions and remove unused dependencies.
vbabanin Jun 24, 2025
73bdbd8
Fix test.
vbabanin Jun 24, 2025
66a5913
Add internal driver information.
vbabanin Jun 25, 2025
26246f0
Fix tests.
vbabanin Jun 25, 2025
843d890
Merge branch 'main' into JAVA-5854
vbabanin Jun 25, 2025
850ebe7
Add metadata logging.
vbabanin Jun 26, 2025
d0cabe4
Merge branch 'main' into JAVA-5854
vbabanin Jun 30, 2025
cb40b6a
Add test assertion.
vbabanin Jun 30, 2025
c44200f
Fix GSSAPI test.
vbabanin Jun 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ClientMetadata entity.
  • Loading branch information
vbabanin committed May 8, 2025
commit 2a684bf3cb0ffac04774afb5467a4d39e0ca5ff8
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2008-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.mongodb.internal.connection;

import com.mongodb.MongoDriverInformation;
import com.mongodb.lang.Nullable;
import org.bson.BsonDocument;

import static com.mongodb.internal.connection.ClientMetadataHelper.createClientMetadataDocument;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have a proper ClientMetadata class that is meant to be instantiated, it seems like we no longer need a separate ClientMetadataHelper class, instead moving the methods of that class into this one.

import static com.mongodb.internal.connection.ClientMetadataHelper.updateClientMedataDocument;

/**
* Represents metadata of the current MongoClient.
*
* <p>This class is not part of the public API and may be removed or changed at any time</p>
*/
public class ClientMetadata {
private volatile BsonDocument clientMetadataBsonDocument;

public ClientMetadata(@Nullable final String applicationName, final MongoDriverInformation mongoDriverInformation) {
this.clientMetadataBsonDocument = createClientMetadataDocument(applicationName, mongoDriverInformation);
}

/**
* Returns mutable BsonDocument that represents the client metadata.
*/
public BsonDocument getBsonDocument() {
return clientMetadataBsonDocument;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return a defensive copy (instead of a reference to this mutable instance?)

Suggested change
return clientMetadataBsonDocument;
return clientMetadataBsonDocument.clone();

Copy link
Member Author

@vbabanin vbabanin May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We mostly pass mutable BsonDocuments through layers (except at the public API). To keep consistency in the codebase, I think it’s fine not to clone here. I’m open to defensive copy as well. Let me know what you think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine without defensive copy if it's consistent throughout the codebase.

}

public void append(final MongoDriverInformation mongoDriverInformation) {
this.clientMetadataBsonDocument = updateClientMedataDocument(clientMetadataBsonDocument, mongoDriverInformation);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class InternalStreamConnectionFactory implements InternalConnectionFactory {
private final MongoCredentialWithCache credential;

InternalStreamConnectionFactory(final ClusterConnectionMode clusterConnectionMode,
final StreamFactory streamFactory,
@Nullable final MongoCredentialWithCache credential,
final StreamFactory streamFactory,
@Nullable final MongoCredentialWithCache credential,
final ClientMetadata clientMetadata,
final List<MongoCompressor> compressorList,
final LoggerSettings loggerSettings, @Nullable final CommandListener commandListener, @Nullable final ServerApi serverApi) {
Expand All @@ -52,8 +52,8 @@ class InternalStreamConnectionFactory implements InternalConnectionFactory {
}

InternalStreamConnectionFactory(final ClusterConnectionMode clusterConnectionMode, final boolean isMonitoringConnection,
final StreamFactory streamFactory,
@Nullable final MongoCredentialWithCache credential,
final StreamFactory streamFactory,
@Nullable final MongoCredentialWithCache credential,
final ClientMetadata clientMetadata,
final List<MongoCompressor> compressorList,
final LoggerSettings loggerSettings, @Nullable final CommandListener commandListener, @Nullable final ServerApi serverApi) {
Expand All @@ -72,7 +72,7 @@ class InternalStreamConnectionFactory implements InternalConnectionFactory {
public InternalConnection create(final ServerId serverId, final ConnectionGenerationSupplier connectionGenerationSupplier) {
Authenticator authenticator = credential == null ? null : createAuthenticator(credential);
InternalStreamConnectionInitializer connectionInitializer = new InternalStreamConnectionInitializer(
clusterConnectionMode, authenticator, clientMetadata.getClientMetadataBsonDocument(), compressorList, serverApi);
clusterConnectionMode, authenticator, clientMetadata.getBsonDocument(), compressorList, serverApi);
return new InternalStreamConnection(
clusterConnectionMode, authenticator,
isMonitoringConnection, serverId, connectionGenerationSupplier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ void testUpdateClientMetadataDocument() {
.driverPlatform("JDK 99")
.build();

//We pass metadataToAppend to a builder and prepend with initial driver information.
MongoDriverInformation expectedUpdatedMetadata = MongoDriverInformation.builder(metadataToAppend)
.driverName("mongo-spark")
.driverVersion("2.0.0")
Expand Down