Skip to content

Conversation

prestonvasquez
Copy link
Member

GODRIVER-3544, GODRIVER-3653

Summary

Extend the mongo.Client stable API to allow appending handshake client metadata on demand.

Background & Motivation

NA

@prestonvasquez prestonvasquez requested a review from a team as a code owner September 12, 2025 05:04
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends the mongo.Client API to support appending client metadata on-demand for handshake requests. The implementation allows drivers to dynamically update metadata information (name, version, platform) that is sent to servers during connection establishment.

  • Replaces static driver info configuration with atomic pointer-based dynamic metadata management
  • Adds AppendDriverInfo method to Client for runtime metadata updates
  • Refactors topology configuration to use functional options pattern with atomic driver info handling

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
mongo/client.go Adds AppendDriverInfo method and atomic driver info management to Client
x/mongo/driver/topology/topology_options.go Refactors config creation with functional options and atomic driver info
x/mongo/driver/topology/server_options.go Replaces individual driver info fields with atomic pointer
x/mongo/driver/topology/server.go Updates connection creation to use atomic driver info
internal/integration/handshake_test.go Comprehensive test coverage for dynamic metadata appending
internal/integration/unified/operation.go Adds appendMetadata operation support
internal/integration/unified/client_operation_execution.go Implements unified test operation execution
internal/test/client_metadata.go Test utility for encoding client metadata
internal/integration/mtest/proxy_*.go Enhanced proxy message capture for testing
internal/handshake/handshake.go Utility for parsing client metadata from wire messages
internal/assert/assertbsoncore/assertions_bsoncore.go Assertion helpers for comparing client metadata

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +813 to +819
if s.cfg.driverInfo != nil {
driverInfo := s.cfg.driverInfo.Load()
if driverInfo != nil {
handshaker = handshaker.OuterLibraryName(driverInfo.Name).OuterLibraryVersion(driverInfo.Version).
OuterLibraryPlatform(driverInfo.Platform)
}
}
Copy link

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

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

[nitpick] The nested nil checks for s.cfg.driverInfo and driverInfo.Load() could be simplified using a helper function or by consolidating the logic, improving code readability.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

mongodb-drivers-pr-bot bot commented Sep 12, 2025

🧪 Performance Results

Commit SHA: 11797dc

The following benchmark tests for version 68f1ad4b2b4b620007210534 had statistically significant changes (i.e., |z-score| > 1.96):

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkBSONFullDocumentDecoding ops_per_second_min -20.1461 1709.1446 Avg: 2140.3402
Med: 2136.4062
Stdev: 23.9214
0.9743 -18.0256
BenchmarkMultiInsertSmallDocument total_mem_allocs 15.5366 2619568.0000 Avg: 2267306.4954
Med: 2237567.0000
Stdev: 118540.4234
0.8327 2.9717
BenchmarkSingleFindOneByID ns_per_op 13.0492 275931.0000 Avg: 244080.3636
Med: 242896.0000
Stdev: 6493.7038
0.8947 4.9048
BenchmarkMultiInsertSmallDocument total_bytes_allocated 11.2526 496632688.0000 Avg: 446401016.4651
Med: 445093368.0000
Stdev: 14612366.5998
0.8471 3.4376
BenchmarkSingleRunCommand ops_per_second_max -10.9222 7944.4524 Avg: 8918.5561
Med: 8902.2255
Stdev: 61.4542
0.9710 -15.8509
BenchmarkMultiInsertSmallDocument total_time_seconds 10.7537 1.1755 Avg: 1.0614
Med: 1.0474
Stdev: 0.0462
0.8051 2.4711
BenchmarkSingleFindOneByID ops_per_second_med -10.2860 3737.7728 Avg: 4166.3226
Med: 4188.7448
Stdev: 126.0224
0.8483 -3.4006
BenchmarkSmallDocInsertOne ops_per_second_max -10.0982 5641.1124 Avg: 6274.7515
Med: 6255.1605
Stdev: 137.0257
0.8869 -4.6242
BenchmarkBSONDeepDocumentEncoding total_mem_allocs 9.9822 244728.0000 Avg: 222515.9237
Med: 222826.5000
Stdev: 7422.7298
0.8354 2.9924
BenchmarkBSONDeepDocumentDecoding ops_per_second_max 2.9719 17805.3167 Avg: 17291.4307
Med: 17213.7779
Stdev: 220.1727
0.8141 2.3340
BenchmarkSmallDocInsertOne allocated_bytes_per_op 0.6042 5693.0000 Avg: 5658.8108
Med: 5660.0000
Stdev: 8.0237
0.8757 4.2610
BenchmarkLargeDocInsertOne allocated_bytes_per_op 0.5711 5692.0000 Avg: 5659.6757
Med: 5660.0000
Stdev: 7.6160
0.8825 4.2443
BenchmarkBSONFullDocumentEncoding allocated_bytes_per_op 0.0632 5200.0000 Avg: 5196.7143
Med: 5196.0000
Stdev: 1.3801
0.7888 2.3807

For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch.

Copy link
Contributor

API Change Report

./v2/mongo

compatible changes

(*Client).AppendDriverInfo: added

./v2/x/mongo/driver/topology

incompatible changes

NewConfigFromOptionsWithAuthenticator: removed
WithOuterLibraryName: removed
WithOuterLibraryPlatform: removed
WithOuterLibraryVersion: removed

compatible changes

AuthConfigOption: added
NewAuthenticatorConfig: added
WithAuthConfigClientOptions: added
WithAuthConfigClock: added
WithAuthConfigDriverInfo: added
WithDriverInfo: added

@alcaeus alcaeus requested review from matthewdale and removed request for qingyang-hu September 15, 2025 17:54
@matthewdale matthewdale added review-priority-normal Medium Priority PR for Review: within 1 business day feature labels Oct 14, 2025
matthewdale
matthewdale previously approved these changes Oct 14, 2025
Copy link
Collaborator

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

assert.True(mt, initialClientMetadata.IsHandshake(), "expected first message to be a handshake")

// Wait 5ms for the connection to become idle.
time.Sleep(20 * time.Millisecond)
Copy link
Collaborator

@qingyang-hu qingyang-hu Oct 15, 2025

Choose a reason for hiding this comment

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

Suggested change
time.Sleep(20 * time.Millisecond)
time.Sleep(5 * time.Millisecond)

Is 5ms enough here? Otherwise, we'd better to match the comment to the code. The following cases also have the mismatches.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll check if the tests are reliable with 5ms sleeps. If they are, I'll set them all to 5ms.

One of the tests had a 20ms sleep set, and I wanted to make them consistent so I set them all to 20ms. However, I don't think the sleep duration was the main source of test failures.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Updated all to 5ms and the tests seem to pass consistently.

qingyang-hu
qingyang-hu previously approved these changes Oct 15, 2025
Copy link
Collaborator

@qingyang-hu qingyang-hu left a comment

Choose a reason for hiding this comment

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

LGTM, just with some nitpicky comments.

@matthewdale matthewdale dismissed stale reviews from qingyang-hu and themself via 8b483fd October 16, 2025 05:08
@matthewdale matthewdale merged commit 4bc4835 into mongodb:master Oct 17, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature review-priority-normal Medium Priority PR for Review: within 1 business day

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants