Skip to content

Conversation

@RafaelCenzano
Copy link
Contributor

GODRIVER-3502

Summary

Use the struct literal instead of builder pattern functions for a driver internal only API. Cuts down code on something that is not necessary

Background & Motivation

#1922 (comment)

@RafaelCenzano RafaelCenzano added enhancement review-priority-normal Medium Priority PR for Review: within 1 business day go Pull requests that update Go code labels Jan 2, 2026
@mongodb-drivers-pr-bot
Copy link
Contributor

mongodb-drivers-pr-bot bot commented Jan 2, 2026

🧪 Performance Results

Commit SHA: 6645c1a

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

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkLargeDocInsertOne ops_per_second_min -40.7501 895.4844 Avg: 1511.3678
Med: 1562.5195
Stdev: 278.2152
0.7626 -2.2137
BenchmarkLargeDocInsertOne total_time_seconds 5.0477 1.2418 Avg: 1.1822
Med: 1.1821
Stdev: 0.0231
0.7853 2.5791
BenchmarkLargeDocInsertOne allocated_bytes_per_op -0.3056 5670.0000 Avg: 5687.3824
Med: 5688.0000
Stdev: 5.0213
0.8679 -3.4618

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

@mongodb-drivers-pr-bot
Copy link
Contributor

mongodb-drivers-pr-bot bot commented Jan 2, 2026

API Change Report

./v2/x/mongo/driver/mongocrypt/options

incompatible changes

(*DataKeyOptions).SetKeyAltNames: removed
(*DataKeyOptions).SetKeyMaterial: removed
(*DataKeyOptions).SetMasterKey: removed
(*ExplicitEncryptionOptions).SetAlgorithm: removed
(*ExplicitEncryptionOptions).SetContentionFactor: removed
(*ExplicitEncryptionOptions).SetKeyAltName: removed
(*ExplicitEncryptionOptions).SetKeyID: removed
(*ExplicitEncryptionOptions).SetQueryType: removed
(*ExplicitEncryptionOptions).SetRangeOptions: removed
(*MongoCryptOptions).SetBypassQueryAnalysis: removed
(*MongoCryptOptions).SetCryptSharedLibDisabled: removed
(*MongoCryptOptions).SetCryptSharedLibOverridePath: removed
(*MongoCryptOptions).SetEncryptedFieldsMap: removed
(*MongoCryptOptions).SetHTTPClient: removed
(*MongoCryptOptions).SetKeyExpiration: removed
(*MongoCryptOptions).SetKmsProviders: removed
(*MongoCryptOptions).SetLocalSchemaMap: removed
(*RewrapManyDataKeyOptions).SetMasterKey: removed
(*RewrapManyDataKeyOptions).SetProvider: removed
DataKey: removed
ExplicitEncryption: removed
MongoCrypt: removed
RewrapManyDataKey: removed

@RafaelCenzano RafaelCenzano marked this pull request as ready for review January 2, 2026 22:28
Copilot AI review requested due to automatic review settings January 2, 2026 22:28
@RafaelCenzano RafaelCenzano requested a review from a team as a code owner January 2, 2026 22:28
Copy link
Contributor

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 refactors the MongoCryptOptions API from a builder pattern to using struct literals directly. This simplification removes unnecessary builder methods for an internal-only API.

Key Changes:

  • Removed all builder pattern methods (MongoCrypt(), SetKmsProviders, SetLocalSchemaMap, etc.) from MongoCryptOptions
  • Updated NewMongoCrypt calls in client_encryption.go and client.go to use struct literal initialization

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
x/mongo/driver/mongocrypt/options/mongocrypt_options.go Removed builder pattern methods, keeping only the struct definition
mongo/client_encryption.go Replaced builder pattern with struct literal for ClientEncryption MongoCrypt initialization
mongo/client.go Replaced builder pattern with struct literal for auto-encryption MongoCrypt initialization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Can we also remove the setters in "x/mongo/driver/mongocrypt/options/mongocrpyt_context_options.go"?

matthewdale
matthewdale previously approved these changes Jan 7, 2026
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 with one suggestion 👍

Comment on lines 214 to 226
transformed := &mcopts.ExplicitEncryptionOptions{}
if args.KeyID != nil {
transformed.SetKeyID(*args.KeyID)
transformed.KeyID = args.KeyID
}
if args.KeyAltName != nil {
transformed.SetKeyAltName(*args.KeyAltName)
transformed.KeyAltName = args.KeyAltName
}
transformed.SetAlgorithm(args.Algorithm)
transformed.SetQueryType(args.QueryType)
transformed.Algorithm = args.Algorithm
transformed.QueryType = args.QueryType

if args.ContentionFactor != nil {
transformed.SetContentionFactor(*args.ContentionFactor)
transformed.ContentionFactor = args.ContentionFactor
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: Because we're now assigning these directly without dereferencing and using setters, we can use struct literal syntax for these fields.

E.g.

transformed := &mcopts.ExplicitEncryptionOptions{
	KeyID: args.KeyID,
	KeyAltName: args.KeyAltName,
	Algorithm: args.Algorithm,
	QueryType: args.QueryType,
	ContentionFactor: args.ContentionFactor,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea I updated the code to use this. Simplifies the code and cuts down on the number of lines, I always feel like that is the best outcome when possible.

Comment on lines 190 to 192
if args.KeyMaterial != nil {
co.SetKeyMaterial(args.KeyMaterial)
co.KeyMaterial = args.KeyMaterial
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Nitpicking] This block can be merged into L177-L179, the initialization of co.

Comment on lines 479 to 481
if args.Provider != nil {
co.SetProvider(*args.Provider)
co.Provider = args.Provider
}
Copy link
Collaborator

@qingyang-hu qingyang-hu Jan 7, 2026

Choose a reason for hiding this comment

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

[Nitpicking] This block can be merged into L468.

qingyang-hu
qingyang-hu previously approved these changes Jan 7, 2026
@RafaelCenzano RafaelCenzano merged commit 21a6b9b into mongodb:master Jan 9, 2026
34 checks passed
@RafaelCenzano RafaelCenzano deleted the refactor/remove-uneeded-setters-godriver-3502 branch January 14, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement go Pull requests that update Go code 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