Skip to content
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

GODRIVER-3434 Revert builder-lister pattern for client options #1899

Merged
merged 15 commits into from
Dec 5, 2024

Conversation

prestonvasquez
Copy link
Collaborator

GODRIVER-3434

Summary

Don't apply the builder-lister pattern for client options.

Background & Motivation

This update has been a source of frustration for users migrating to the v2 beta. While the lister-builder pattern is effective for operational options, client options are often defined as struct literals and used in test / general comparison within a users code. For example:

opts := options.Client().SetAppName("x")

// ...

if opts.AppName != nil && opts.AppName == "x" {
    // do something
}

While this isn't too difficult to manage in v2, it does require a code change. The primarily discussed alternative is to apply a Merge function to ClientOptionsBuilder. However, this would still require a code change and is kind of confusing for people who aren't familiar with the history of the problem in the Go Driver. This PR suggests deferring that question to v3, as client options are rather unique.

@prestonvasquez prestonvasquez marked this pull request as draft November 21, 2024 19:52
@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot added the priority-3-low Low Priority PR for Review label Nov 21, 2024
Copy link
Contributor

mongodb-drivers-pr-bot bot commented Nov 21, 2024

API Change Report

./v2/mongo

incompatible changes

##Connect: changed from func(..../v2/mongo/options.Lister[./v2/mongo/options.ClientOptions]) (Client, error) to func(..../v2/mongo/options.ClientOptions) (*Client, error)

./v2/mongo/options

incompatible changes

(*AutoEncryptionOptionsBuilder).List: removed
(*AutoEncryptionOptionsBuilder).SetKeyVaultClientOptions: changed from func(Lister[ClientOptions]) *AutoEncryptionOptionsBuilder to func(*ClientOptions) *AutoEncryptionOptions
(*ClientOptionsBuilder).List: removed
(*ClientOptionsBuilder).SetAutoEncryptionOptions: changed from func(Lister[AutoEncryptionOptions]) *ClientOptionsBuilder to func(*AutoEncryptionOptions) *ClientOptions
(*ClientOptionsBuilder).SetLoggerOptions: changed from func(Lister[LoggerOptions]) *ClientOptionsBuilder to func(*LoggerOptions) *ClientOptions
(*ClientOptionsBuilder).SetServerAPIOptions: changed from func(Lister[ServerAPIOptions]) *ClientOptionsBuilder to func(*ServerAPIOptions) *ClientOptions
(*LoggerOptionsBuilder).List: removed
(*ServerAPIOptionsBuilder).List: removed
AutoEncryptionOptions.KeyVaultClientOptions: changed from Lister[ClientOptions] to *ClientOptions
AutoEncryptionOptionsBuilder.Opts: removed
AutoEncryptionOptionsBuilder: removed
ClientOptions.AutoEncryptionOptions: changed from Lister[AutoEncryptionOptions] to *AutoEncryptionOptions
ClientOptions.LoggerOptions: changed from Lister[LoggerOptions] to *LoggerOptions
ClientOptions.ServerAPIOptions: changed from Lister[ServerAPIOptions] to *ServerAPIOptions
ClientOptionsBuilder.Opts: removed
ClientOptionsBuilder: removed
LoggerOptionsBuilder.Opts: removed
LoggerOptionsBuilder: removed
ServerAPIOptionsBuilder.Opts: removed
ServerAPIOptionsBuilder: removed

compatible changes

(*AutoEncryptionOptions).SetBypassAutoEncryption: added
(*AutoEncryptionOptions).SetBypassQueryAnalysis: added
(*AutoEncryptionOptions).SetEncryptedFieldsMap: added
(*AutoEncryptionOptions).SetExtraOptions: added
(*AutoEncryptionOptions).SetKeyVaultClientOptions: added
(*AutoEncryptionOptions).SetKeyVaultNamespace: added
(*AutoEncryptionOptions).SetKmsProviders: added
(*AutoEncryptionOptions).SetSchemaMap: added
(*AutoEncryptionOptions).SetTLSConfig: added
(*ClientOptions).ApplyURI: added
(*ClientOptions).SetAppName: added
(*ClientOptions).SetAuth: added
(*ClientOptions).SetAutoEncryptionOptions: added
(*ClientOptions).SetBSONOptions: added
(*ClientOptions).SetCompressors: added
(*ClientOptions).SetConnectTimeout: added
(*ClientOptions).SetDialer: added
(*ClientOptions).SetDirect: added
(*ClientOptions).SetDisableOCSPEndpointCheck: added
(*ClientOptions).SetDriverInfo: added
(*ClientOptions).SetHTTPClient: added
(*ClientOptions).SetHeartbeatInterval: added
(*ClientOptions).SetHosts: added
(*ClientOptions).SetLoadBalanced: added
(*ClientOptions).SetLocalThreshold: added
(*ClientOptions).SetLoggerOptions: added
(*ClientOptions).SetMaxConnIdleTime: added
(*ClientOptions).SetMaxConnecting: added
(*ClientOptions).SetMaxPoolSize: added
(*ClientOptions).SetMinPoolSize: added
(*ClientOptions).SetMonitor: added
(*ClientOptions).SetPoolMonitor: added
(*ClientOptions).SetReadConcern: added
(*ClientOptions).SetReadPreference: added
(*ClientOptions).SetRegistry: added
(*ClientOptions).SetReplicaSet: added
(*ClientOptions).SetRetryReads: added
(*ClientOptions).SetRetryWrites: added
(*ClientOptions).SetSRVMaxHosts: added
(*ClientOptions).SetSRVServiceName: added
(*ClientOptions).SetServerAPIOptions: added
(*ClientOptions).SetServerMonitor: added
(*ClientOptions).SetServerMonitoringMode: added
(*ClientOptions).SetServerSelectionTimeout: added
(*ClientOptions).SetTLSConfig: added
(*ClientOptions).SetTimeout: added
(*ClientOptions).SetWriteConcern: added
(*ClientOptions).SetZlibLevel: added
(*ClientOptions).SetZstdLevel: added
(*ClientOptions).Validate: added
(*LoggerOptions).SetComponentLevel: added
(*LoggerOptions).SetMaxDocumentLength: added
(*LoggerOptions).SetSink: added
(*ServerAPIOptions).SetDeprecationErrors: added
(*ServerAPIOptions).SetStrict: added
AutoEncryptionOptionsBuilder.BypassAutoEncryption: added
AutoEncryptionOptionsBuilder.BypassQueryAnalysis: added
AutoEncryptionOptionsBuilder.EncryptedFieldsMap: added
AutoEncryptionOptionsBuilder.ExtraOptions: added
AutoEncryptionOptionsBuilder.HTTPClient: added
AutoEncryptionOptionsBuilder.KeyVaultClientOptions: added
AutoEncryptionOptionsBuilder.KeyVaultNamespace: added
AutoEncryptionOptionsBuilder.KmsProviders: added
AutoEncryptionOptionsBuilder.SchemaMap: added
AutoEncryptionOptionsBuilder.TLSConfig: added
ClientOptionsBuilder.AppName: added
ClientOptionsBuilder.Auth: added
ClientOptionsBuilder.AutoEncryptionOptions: added
ClientOptionsBuilder.BSONOptions: added
ClientOptionsBuilder.Compressors: added
ClientOptionsBuilder.ConnectTimeout: added
ClientOptionsBuilder.Crypt: added
ClientOptionsBuilder.Deployment: added
ClientOptionsBuilder.Dialer: added
ClientOptionsBuilder.Direct: added
ClientOptionsBuilder.DisableOCSPEndpointCheck: added
ClientOptionsBuilder.DriverInfo: added
ClientOptionsBuilder.HTTPClient: added
ClientOptionsBuilder.HeartbeatInterval: added
ClientOptionsBuilder.Hosts: added
ClientOptionsBuilder.LoadBalanced: added
ClientOptionsBuilder.LocalThreshold: added
ClientOptionsBuilder.LoggerOptions: added
ClientOptionsBuilder.MaxConnIdleTime: added
ClientOptionsBuilder.MaxConnecting: added
ClientOptionsBuilder.MaxPoolSize: added
ClientOptionsBuilder.MinPoolSize: added
ClientOptionsBuilder.Monitor: added
ClientOptionsBuilder.PoolMonitor: added
ClientOptionsBuilder.ReadConcern: added
ClientOptionsBuilder.ReadPreference: added
ClientOptionsBuilder.Registry: added
ClientOptionsBuilder.ReplicaSet: added
ClientOptionsBuilder.RetryReads: added
ClientOptionsBuilder.RetryWrites: added
ClientOptionsBuilder.SRVMaxHosts: added
ClientOptionsBuilder.SRVServiceName: added
ClientOptionsBuilder.ServerAPIOptions: added
ClientOptionsBuilder.ServerMonitor: added
ClientOptionsBuilder.ServerMonitoringMode: added
ClientOptionsBuilder.ServerSelectionTimeout: added
ClientOptionsBuilder.TLSConfig: added
ClientOptionsBuilder.Timeout: added
ClientOptionsBuilder.WriteConcern: added
ClientOptionsBuilder.ZlibLevel: added
ClientOptionsBuilder.ZstdLevel: added
LoggerOptionsBuilder.ComponentLevels: added
LoggerOptionsBuilder.MaxDocumentLength: added
LoggerOptionsBuilder.Sink: added
MergeClientOptions: added
ServerAPIOptionsBuilder.DeprecationErrors: added
ServerAPIOptionsBuilder.ServerAPIVersion: added
ServerAPIOptionsBuilder.Strict: added

./v2/x/mongo/driver/topology

incompatible changes

##ConvertToDriverAPIOptions: changed from func(./v2/mongo/options.Lister[./v2/mongo/options.ServerAPIOptions]) ./v2/x/mongo/driver.ServerAPIOptions to func(./v2/mongo/options.ServerAPIOptions) ./v2/x/mongo/driver.ServerAPIOptions
##NewConfig: changed from func(
./v2/mongo/options.ClientOptionsBuilder, *./v2/x/mongo/driver/session.ClusterClock) (Config, error) to func(./v2/mongo/options.ClientOptions, *./v2/x/mongo/driver/session.ClusterClock) (*Config, error)
NewConfigFromOptions: removed

@prestonvasquez prestonvasquez added priority-1-high High Priority PR for Review and removed priority-3-low Low Priority PR for Review labels Nov 21, 2024
@prestonvasquez prestonvasquez marked this pull request as ready for review November 21, 2024 22:11
@alcaeus alcaeus requested a review from qingyang-hu November 25, 2024 15:42
qingyang-hu
qingyang-hu previously approved these changes Dec 3, 2024
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


return nil
})
func (c *ClientOptions) SetAutoEncryptionOptions(aeopts Lister[AutoEncryptionOptions]) *ClientOptions {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For AutoEncryptionOptions, LoggerOptions, and ServerAPIOptions, should we also revert to the previous pattern (i.e. not use of Lister type)?

matthewdale
matthewdale previously approved these changes Dec 4, 2024
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! 👍

mongo/client.go Outdated Show resolved Hide resolved
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.

It looks good other than some typos.

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.

👍

@prestonvasquez prestonvasquez merged commit 17a547f into mongodb:master Dec 5, 2024
28 of 35 checks passed
@prestonvasquez prestonvasquez deleted the GODRIVER-3434 branch December 5, 2024 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-1-high High Priority PR for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants