WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@qingyang-hu
Copy link
Collaborator

@qingyang-hu qingyang-hu commented Nov 12, 2025

GODRIVER-3486
GODRIVER-3402

Summary

Support auto encryption in unified tests.

Background & Motivation

@mongodb-drivers-pr-bot
Copy link
Contributor

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

🧪 Performance Results

Commit SHA: 7c5d45b

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

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkMultiInsertLargeDocument allocated_bytes_per_op -5.0588 26513049.0000 Avg: 27925749.9594
Med: 27920409.0000
Stdev: 663917.7120
0.7436 -2.1278
BenchmarkBSONFlatDocumentEncoding ops_per_second_max -4.4843 82399.4726 Avg: 86268.0249
Med: 86325.9984
Stdev: 1837.1814
0.7539 -2.1057
BenchmarkMultiFindMany ops_per_second_max -3.7500 4065040.6504 Avg: 4223417.5755
Med: 4237288.1356
Stdev: 54030.4214
0.8210 -2.9313
BenchmarkMultiFindMany ops_per_second_med -3.2065 3610108.3032 Avg: 3729701.6649
Med: 3731343.2836
Stdev: 45311.6931
0.7918 -2.6393

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 Nov 12, 2025

API Change Report

No changes found!

This comment was marked as outdated.

@qingyang-hu qingyang-hu marked this pull request as draft November 13, 2025 14:37
@qingyang-hu qingyang-hu force-pushed the godriver3486 branch 4 times, most recently from b1f3ca6 to 6bf8480 Compare November 15, 2025 02:55
@qingyang-hu qingyang-hu removed the request for review from matthewdale December 4, 2025 19:49
@qingyang-hu qingyang-hu force-pushed the godriver3486 branch 13 times, most recently from 666c2d5 to b000132 Compare December 6, 2025 04:44
@qingyang-hu qingyang-hu force-pushed the godriver3486 branch 6 times, most recently from e036710 to a871c58 Compare December 6, 2025 20:11
@mongodb mongodb deleted a comment from Copilot AI Dec 6, 2025
@mongodb mongodb deleted a comment from Copilot AI Dec 6, 2025
@mongodb mongodb deleted a comment from Copilot AI Dec 6, 2025
@mongodb mongodb deleted a comment from Copilot AI Dec 6, 2025
@mongodb mongodb deleted a comment from Copilot AI Dec 6, 2025
@qingyang-hu qingyang-hu requested a review from Copilot December 6, 2025 23:53
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

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


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

}

// getKmsCredential processes a value of an input KMS provider credential.
// An empty document returns from the environment.
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

The comment "An empty document returns from the environment" is unclear and grammatically incorrect. It should be clarified to something like "A placeholder document ($$placeholder) causes the value to be retrieved from the environment variable or default value."

Suggested change
// An empty document returns from the environment.
// If a placeholder document ($$placeholder) is provided, the value is retrieved from the environment variable or default value.

Copilot uses AI. Check for mistakes.
// If neither documents nor options are provided, still create the collection with write concern "majority".
if len(c.Documents) == 0 && c.Options == nil {
} else {
// If options are provided, still create the collection with write concern "majority".
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

The comment states "If options are provided" but this is in the else block where c.Options is nil. The comment should say "If no options are provided" to accurately describe this code path.

Suggested change
// If options are provided, still create the collection with write concern "majority".
// If no options are provided, still create the collection with write concern "majority".

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

This seems relevant.

return nil, err
}
if v == "$$placeholder" {
provider["sessionToken"] = os.Getenv("CSFLE_AWS_TEMP_SESSION_TOKEN")
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

When the sessionToken placeholder is detected, the code directly assigns os.Getenv("CSFLE_AWS_TEMP_SESSION_TOKEN") without checking if the environment variable exists or is empty. If the environment variable is not set, this will assign an empty string to the provider's sessionToken. Consider using getKmsCredential or adding a check to ensure the environment variable is set before assigning it.

Suggested change
provider["sessionToken"] = os.Getenv("CSFLE_AWS_TEMP_SESSION_TOKEN")
sessionToken, err := getKmsCredential(opt, "sessionToken", "CSFLE_AWS_TEMP_SESSION_TOKEN", "")
if err != nil {
return nil, err
}
if sessionToken != nil {
provider["sessionToken"] = sessionToken
}

Copilot uses AI. Check for mistakes.
@qingyang-hu qingyang-hu marked this pull request as ready for review December 8, 2025 14:18
@mongodb mongodb deleted a comment from evergreen-ci-prod bot Dec 8, 2025
}
for _, coll := range colls {
if re.MatchString(coll) {
_, err = db.Collection(coll).DeleteMany(ctx, bson.D{})
Copy link
Member

Choose a reason for hiding this comment

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

[question] Why don't we just drop these collections?

}
}

func createAutoEncryptionOptions(opts bson.Raw) (*options.AutoEncryptionOptions, error) {
Copy link
Member

Choose a reason for hiding this comment

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

[nit] Could we add a TODO(GODRIVER-3726) here to investigate moving this logic to an Unmarshal method?

// If neither documents nor options are provided, still create the collection with write concern "majority".
if len(c.Documents) == 0 && c.Options == nil {
} else {
// If options are provided, still create the collection with write concern "majority".
Copy link
Member

Choose a reason for hiding this comment

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

This seems relevant.

Comment on lines 648 to 649
{"accessKeyId", accessKeyID},
{"secretAccessKey", secretAccessKey},
Copy link
Member

Choose a reason for hiding this comment

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

[nit] Suggest keying the field values for readability and breaking parameterization.

Comment on lines 664 to 666
{"tenantId", "FLE_AZURE_TENANTID"},
{"clientId", "FLE_AZURE_CLIENTID"},
{"clientSecret", "FLE_AZURE_CLIENTSECRET"},
Copy link
Member

Choose a reason for hiding this comment

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

[nit] Suggest keying the field values for readability and breaking parameterization.

Comment on lines 681 to 682
{"email", "FLE_GCP_EMAIL"},
{"privateKey", "FLE_GCP_PRIVATEKEY"},
Copy link
Member

Choose a reason for hiding this comment

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

[nit] Suggest keying the field values for readability and breaking parameterization.


azureClientSecret, err := getKmsCredential(azure, "clientSecret", "FLE_AZURE_CLIENTSECRET", "")
case "local", "local:name2":
defaultLocalKeyBase64 := "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk"
Copy link
Member

Choose a reason for hiding this comment

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

[nit] Consider constantizing.

kmipEndpoint, err := getKmsCredential(kmip, "endpoint", "", "localhost:5698")
func (em *EntityMap) addClientEncryptionEntity(entityOptions *entityOptions) error {
// Construct KMS providers.
kmsProviders := make(map[string]map[string]any)
Copy link
Member

Choose a reason for hiding this comment

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

[blocking] Can we merge the KMS logic here with createAutoEncryptionOptions? Same with the key vault namespace? From the specs:

kmsProviders: The same as in clientEncryption.
keyVaultNamespace: The same as in clientEncryption.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will be easier to merge the logic in GODRIVER-3726 in my idea

}
}

func createAutoEncryptionOptions(opts bson.Raw) (*options.AutoEncryptionOptions, error) {
Copy link
Member

Choose a reason for hiding this comment

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

[question] Can the analogue in integration/json_helpers_test.go be removed? Can we remove all support for auto encryption in the legacy runner?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can keep it until the legacy tests are completely eliminated to avoid handling logic fractions.

@github-actions github-actions bot added the review-priority-normal Medium Priority PR for Review: within 1 business day label Dec 11, 2025
}

// Clear automatically created collections used for queryable encryption
re := regexp.MustCompile("^enxcol_.*.e(sc|coc)$")
Copy link
Collaborator

Choose a reason for hiding this comment

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

(Optional) regexp.MustCompile panics if the regex can't be compiled. Consider moving this to a package-level initialization so any issue can be discovered at package initialization, not when the test is run.

E.g.

// qeCollectionPattern matches collections automatically created for
// queryable encryption.
var qeCollectionPattern = regexp.MustCompile("^enxcol_.*.e(sc|coc)$")

// An empty document returns from the environment.
// A string is returned as-is.
func getKmsCredential(kmsDocument bson.Raw, credentialName string, envVar string, defaultValue string) (string, error) {
func getKmsCredential(kmsDocument bson.Raw, credentialName string, envVar string, defaultValue string) (any, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why change the return type from string to any? All of the returned values seem to still be string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The main motivation of the change is to distinguish nonexistent value from empty. It is primarily used in line #647, where we set "sessionToken" only when it exists.

}

if tlsClientCertificateKeyFile != "" && tlsCAFile != "" {
if provider == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

(Optional) For maps, it's conventional to check for len(provider) == 0 because a nil and empty map both report length 0. Consider updating the check here to if len(provider) == 0 and removing the redundant if len(provider) == 0 from getKmsProvider.

embRawValue := bson.RawValue{Type: bson.TypeEmbeddedDocument, Value: data}
if err := embRawValue.Unmarshal(&csfle.Options); err == nil {
csfle.Boolean = false
csfle.Boolean = true
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The csfle logically is enabled when it contains a document of properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement 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