Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Oct 2, 2023
2 parents 23df976 + cd3c699 commit 26f0a2f
Show file tree
Hide file tree
Showing 281 changed files with 2,721 additions and 80,388 deletions.
81 changes: 69 additions & 12 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ functions:
echo "crypt_shared library will be loaded from path: $CRYPT_SHARED_LIB_PATH"
fi
export GOFLAGS=-mod=vendor
AUTH="${AUTH}" \
SSL="${SSL}" \
MONGODB_URI="${MONGODB_URI}" \
Expand Down Expand Up @@ -571,7 +570,6 @@ functions:
# Per the LB testing spec, the URI of an LB fronting a single mongos should be used to configure internal
# testing Client instances, so we set MONGODB_URI to SINGLE_MONGOS_LB_URI.
export GOFLAGS=-mod=vendor
AUTH="${AUTH}" \
SSL="${SSL}" \
MONGODB_URI="${SINGLE_MONGOS_LB_URI}" \
Expand Down Expand Up @@ -688,6 +686,17 @@ functions:
params:
file: lb-expansion.yml

run-search-index-tests:
- command: shell.exec
type: test
params:
shell: "bash"
working_dir: src/go.mongodb.org/mongo-driver
script: |
${PREPARE_SHELL}
TEST_INDEX_URI="${TEST_INDEX_URI}" \
make evg-test-search-index
stop-load-balancer:
- command: shell.exec
params:
Expand Down Expand Up @@ -1108,7 +1117,6 @@ functions:
${PREPARE_SHELL}
export KMS_TLS_TESTCASE="${KMS_TLS_TESTCASE}"
export GOFLAGS=-mod=vendor
AUTH="${AUTH}" \
SSL="${SSL}" \
MONGODB_URI="${MONGODB_URI}" \
Expand Down Expand Up @@ -1136,7 +1144,6 @@ functions:
${PREPARE_SHELL}
export KMS_MOCK_SERVERS_RUNNING="true"
export GOFLAGS=-mod=vendor
AUTH="${AUTH}" \
SSL="${SSL}" \
MONGODB_URI="${MONGODB_URI}" \
Expand Down Expand Up @@ -1923,15 +1930,13 @@ tasks:
MONGO_GO_DRIVER_COMPRESSOR: "snappy"

# Build with the oldest supported version of Go.
- name: go1.13-build
- name: go1.18-build
tags: ["compile-check"]
commands:
- func: run-make
vars:
# We only test building the compilecheck submodule with Go 1.13 because the root module's
# go.mod file contains retract directives, which are not supported until Go 1.16.
targets: "build-compile-check"
BUILD_ENV: "PATH=/opt/golang/go1.13/bin:$PATH GOROOT=/opt/golang/go1.13"
BUILD_ENV: "PATH=/opt/golang/go1.18/bin:$PATH GOROOT=/opt/golang/go1.18"

# Build with the same Go version that we're using for tests.
- name: build
Expand Down Expand Up @@ -2259,6 +2264,14 @@ tasks:
${PREPARE_SHELL}
./.evergreen/run-deployed-lambda-aws-tests.sh
- name: "test-search-index"
commands:
- func: "bootstrap-mongo-orchestration"
vars:
VERSION: "latest"
TOPOLOGY: "replica_set"
- func: "run-search-index-tests"

axes:
- id: version
display_name: MongoDB Version
Expand Down Expand Up @@ -2314,7 +2327,7 @@ axes:
VENV_BIN_DIR: "Scripts"
- id: "rhel87-64-go-1-20"
display_name: "RHEL 8.7"
run_on: rhel8.7-large
run_on: rhel8.7-large
variables:
GO_DIST: "/opt/golang/go1.20"
- id: "macos11-go-1-20"
Expand Down Expand Up @@ -2618,6 +2631,44 @@ task_groups:
tasks:
- test-aws-lambda-deployed

- name: test-search-index-task-group
setup_group:
- func: fetch-source
- func: prepare-resources
- command: subprocess.exec
params:
working_dir: src/go.mongodb.org/mongo-driver
binary: bash
add_expansions_to_env: true
env:
MONGODB_VERSION: "7.0"
args:
- ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh
- command: expansions.update
params:
file: src/go.mongodb.org/mongo-driver/atlas-expansion.yml
- command: shell.exec
params:
working_dir: src/go.mongodb.org/mongo-driver
shell: bash
script: |-
echo "TEST_INDEX_URI: ${MONGODB_URI}" > atlas-expansion.yml
- command: expansions.update
params:
file: src/go.mongodb.org/mongo-driver/atlas-expansion.yml
teardown_group:
- command: subprocess.exec
params:
working_dir: src/go.mongodb.org/mongo-driver
binary: bash
add_expansions_to_env: true
args:
- ${DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800
tasks:
- test-search-index

buildvariants:
- name: static-analysis
tags: ["pullrequest"]
Expand Down Expand Up @@ -2647,12 +2698,12 @@ buildvariants:
GO_DIST: "/opt/golang/go1.20"
tasks:
- name: ".compile-check"

- name: atlas-test
tags: ["pullrequest"]
display_name: "Atlas test"
run_on:
- rhel8.7-large
- rhel8.7-large
expansions:
GO_DIST: "/opt/golang/go1.20"
tasks:
Expand All @@ -2662,7 +2713,7 @@ buildvariants:
tags: ["pullrequest"]
display_name: "Atlas Data Lake Test"
run_on:
- rhel8.7-large
- rhel8.7-large
expansions:
GO_DIST: "/opt/golang/go1.20"
tasks:
Expand Down Expand Up @@ -2777,6 +2828,12 @@ buildvariants:
tasks:
- test-aws-lambda-task-group

- matrix_name: "searchindex-test"
matrix_spec: { version: ["7.0"], os-faas-80: ["rhel87-large-go-1-20"] }
display_name: "Search Index ${version} ${os-faas-80}"
tasks:
- test-search-index-task-group

- name: testgcpkms-variant
display_name: "GCP KMS"
run_on:
Expand Down
1 change: 0 additions & 1 deletion .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export PATH="${GOROOT}/bin:${GCC_PATH}:$GOPATH/bin:$PATH"
export PROJECT="${project}"
export PKG_CONFIG_PATH=$(pwd)/install/libmongocrypt/lib64/pkgconfig:$(pwd)/install/mongo-c-driver/lib/pkgconfig
export LD_LIBRARY_PATH=$(pwd)/install/libmongocrypt/lib64
export GOFLAGS=-mod=vendor

SSL=${SSL:-nossl}
if [ "$SSL" != "nossl" -a -z "${SERVERLESS+x}" ]; then
Expand Down
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,14 @@ install-lll:
check-fmt: install-lll
etc/check_fmt.sh

# check-modules runs "go mod tidy" then "go mod vendor" and exits with a non-zero exit code if there
# are any module or vendored modules changes. The intent is to confirm two properties:
#
# 1. Exactly the required modules are declared as dependencies. We should always be able to run
# "go mod tidy" and expect that no unrelated changes are made to the "go.mod" file.
#
# 2. All required modules are copied into the vendor/ directory and are an exact copy of the
# original module source code (i.e. the vendored modules are not modified from their original code).
# check-modules runs "go mod tidy" and exits with a non-zero exit code if there
# are any module changes. The intent is to confirm that exactly the required
# modules are declared as dependencies. We should always be able to run "go mod
# tidy" and expect that no unrelated changes are made to the "go.mod" file.
.PHONY: check-modules
check-modules:
go mod tidy -v
go mod vendor
git diff --exit-code go.mod go.sum ./vendor
git diff --exit-code go.mod go.sum

.PHONY: doc
doc:
Expand Down Expand Up @@ -159,6 +154,10 @@ evg-test-load-balancers:
go test $(BUILD_TAGS) ./mongo/integration -run TestLoadBalancerSupport -v -timeout $(TEST_TIMEOUT)s >> test.suite
go test $(BUILD_TAGS) ./mongo/integration/unified -run TestUnifiedSpec -v -timeout $(TEST_TIMEOUT)s >> test.suite

.PHONY: evg-test-search-index
evg-test-search-index:
go test ./mongo/integration -run TestSearchIndexProse -v -timeout $(TEST_TIMEOUT)s >> test.suite

.PHONY: evg-test-ocsp
evg-test-ocsp:
go test -v ./mongo -run TestOCSP $(OCSP_TLS_SHOULD_SUCCEED) >> test.suite
Expand Down
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ The MongoDB supported driver for Go.
-------------------------
## Requirements

- Go 1.13 or higher. We aim to support the latest versions of Go.
- `go mod tidy` will error when importing the Go Driver using Go versions older than 1.15 due to dependencies that import [io/fs](https://pkg.go.dev/io/fs). See golang/go issue [#44557](https://github.com/golang/go/issues/44557) for more information.
- Go 1.20 or higher is required to run the driver test suite.
- Go 1.18 or higher. We aim to support the latest versions of Go.
- Go 1.20 or higher is required to run the driver test suite.
- MongoDB 3.6 and higher.

-------------------------
Expand Down Expand Up @@ -148,6 +147,34 @@ if err == mongo.ErrNoDocuments {

Additional examples and documentation can be found under the examples directory and [on the MongoDB Documentation website](https://www.mongodb.com/docs/drivers/go/current/).

### Network Compression

Network compression will reduce bandwidth requirements between MongoDB and the application.

The Go Driver supports the following compression algorithms:

1. [Snappy](https://google.github.io/snappy/) (`snappy`): available in MongoDB 3.4 and later.
2. [Zlib](https://zlib.net/) (`zlib`): available in MongoDB 3.6 and later.
3. [Zstandard](https://github.com/facebook/zstd/) (`zstd`): available in MongoDB 4.2 and later.

#### Specify Compression Algorithms

Compression can be enabled using the `compressors` parameter on the connection string or by using [`ClientOptions.SetCompressors`](https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo/options#ClientOptions.SetCompressors):

```
opts := options.Client().ApplyURI("mongodb://localhost:27017/?compressors=snappy,zlib,zstd")
client, _ := mongo.Connect(context.TODO(), opts)
```

```
opts := options.Client().SetCompressors([]string{"snappy", "zlib", "zstd"})
client, _ := mongo.Connect(context.TODO(), opts)
```

If compressors are set, the Go Driver negotiates with the server to select the first common compressor. For server configuration and defaults, refer to [`networkMessageCompressors`](https://www.mongodb.com/docs/manual/reference/program/mongod/#std-option-mongod.--networkMessageCompressors).

Messages compress when both parties enable network compression; otherwise, messages remain uncompressed

-------------------------
## Feedback

Expand Down
4 changes: 2 additions & 2 deletions benchmark/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func MultiFindMany(ctx context.Context, tm TimerManager, iters int) error {
if err != nil {
return err
}
defer db.Client().Disconnect(ctx)
defer func() { _ = db.Client().Disconnect(ctx) }()

db = db.Client().Database("perftest")
if err = db.Drop(ctx); err != nil {
Expand Down Expand Up @@ -87,7 +87,7 @@ func multiInsertCase(ctx context.Context, tm TimerManager, iters int, data strin
if err != nil {
return err
}
defer db.Client().Disconnect(ctx)
defer func() { _ = db.Client().Disconnect(ctx) }()

db = db.Client().Database("perftest")
if err = db.Drop(ctx); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions benchmark/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func BenchmarkClientWrite(b *testing.B) {
if err != nil {
b.Fatalf("error creating client: %v", err)
}
defer client.Disconnect(context.Background())
defer func() { _ = client.Disconnect(context.Background()) }()
coll := client.Database("test").Collection("test")
_, err = coll.DeleteMany(context.Background(), bson.D{})
if err != nil {
Expand Down Expand Up @@ -75,7 +75,7 @@ func BenchmarkClientBulkWrite(b *testing.B) {
if err != nil {
b.Fatalf("error creating client: %v", err)
}
defer client.Disconnect(context.Background())
defer func() { _ = client.Disconnect(context.Background()) }()
coll := client.Database("test").Collection("test")
_, err = coll.DeleteMany(context.Background(), bson.D{})
if err != nil {
Expand Down Expand Up @@ -119,7 +119,7 @@ func BenchmarkClientRead(b *testing.B) {
if err != nil {
b.Fatalf("error creating client: %v", err)
}
defer client.Disconnect(context.Background())
defer func() { _ = client.Disconnect(context.Background()) }()
coll := client.Database("test").Collection("test")
_, err = coll.DeleteMany(context.Background(), bson.D{})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions benchmark/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func SingleRunCommand(ctx context.Context, tm TimerManager, iters int) error {
if err != nil {
return err
}
defer db.Client().Disconnect(ctx)
defer func() { _ = db.Client().Disconnect(ctx) }()

cmd := bson.D{{handshake.LegacyHelloLowercase, true}}

Expand Down Expand Up @@ -127,7 +127,7 @@ func singleInsertCase(ctx context.Context, tm TimerManager, iters int, data stri
if err != nil {
return err
}
defer db.Client().Disconnect(ctx)
defer func() { _ = db.Client().Disconnect(ctx) }()

db = db.Client().Database("perftest")
if err = db.Drop(ctx); err != nil {
Expand Down
11 changes: 9 additions & 2 deletions bson/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,19 @@ func (r Raw) LookupErr(key ...string) (RawValue, error) {
// elements. If the document is not valid, the elements up to the invalid point will be returned
// along with an error.
func (r Raw) Elements() ([]RawElement, error) {
elems, err := bsoncore.Document(r).Elements()
doc := bsoncore.Document(r)
if len(doc) == 0 {
return nil, nil
}
elems, err := doc.Elements()
if err != nil {
return nil, err
}
relems := make([]RawElement, 0, len(elems))
for _, elem := range elems {
relems = append(relems, RawElement(elem))
}
return relems, err
return relems, nil
}

// Values returns this document as a slice of values. The returned slice will contain valid values.
Expand Down
2 changes: 1 addition & 1 deletion cmd/testkms/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func main() {
if err != nil {
panic(fmt.Sprintf("Connect error: %v", err))
}
defer keyVaultClient.Disconnect(context.Background())
defer func() { _ = keyVaultClient.Disconnect(context.Background()) }()

kmsProvidersMap := map[string]map[string]interface{}{
provider: {},
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Before starting to write code, look for existing [tickets](https://jira.mongodb.
The Go Driver team uses GitHub to manage and review all code changes. Patches should generally be made against the master (default) branch and include relevant tests, if
applicable.

Code should compile and tests should pass under all Go versions which the driver currently supports. Currently the Go Driver supports a minimum version of Go 1.13 and requires Go 1.20 for development. Please run the following Make targets to validate your changes:
Code should compile and tests should pass under all Go versions which the driver currently supports. Currently the Go Driver supports a minimum version of Go 1.18 and requires Go 1.20 for development. Please run the following Make targets to validate your changes:
- `make fmt`
- `make lint` (requires [golangci-lint](https://github.com/golangci/golangci-lint) and [lll](https://github.com/walle/lll) to be installed and available in the `PATH`)
- `make test`
Expand Down
4 changes: 2 additions & 2 deletions etc/check_license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ do
esac
done

# Find all .go files not in the vendor directory and try to write a license notice.
GO_FILES=$(find . -path ./vendor -prune -o -type f -name "*.go" -print)
# Find all .go files and try to write a license notice.
GO_FILES=$(find . -type f -name "*.go" -print)

for file in $GO_FILES
do
Expand Down
Loading

0 comments on commit 26f0a2f

Please sign in to comment.