Skip to content

Commit 6b59d70

Browse files
committed
e2e wip
1 parent a154b3a commit 6b59d70

File tree

6 files changed

+375
-0
lines changed

6 files changed

+375
-0
lines changed

.evergreen/config.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,25 @@ tasks:
22752275
- func: bootstrap-mongo-orchestration
22762276
- func: run-deployed-aws-lambda-tests
22772277

2278+
- name: "test-search-index-deployed"
2279+
commands:
2280+
- command: ec2.assume_role
2281+
params:
2282+
role_arn: ${LAMBDA_AWS_ROLE_ARN}
2283+
duration_seconds: 3600
2284+
- command: shell.exec
2285+
params:
2286+
working_dir: src/go.mongodb.org/mongo-driver
2287+
shell: bash
2288+
add_expansions_to_env: true
2289+
env:
2290+
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/internal/test/searchindex
2291+
LAMBDA_STACK_NAME: dbx-go-searchindex
2292+
AWS_REGION: us-east-1
2293+
script: |
2294+
${PREPARE_SHELL}
2295+
./.evergreen/run-deployed-lambda-aws-tests.sh
2296+
22782297
axes:
22792298
- id: version
22802299
display_name: MongoDB Version
@@ -2599,6 +2618,39 @@ task_groups:
25992618
tasks:
26002619
- testazurekms-task
26012620

2621+
- name: test-search-index-task-group
2622+
setup_group:
2623+
- func: fetch-source
2624+
- func: prepare-resources
2625+
- command: subprocess.exec
2626+
params:
2627+
working_dir: src/go.mongodb.org/mongo-driver
2628+
binary: bash
2629+
add_expansions_to_env: true
2630+
env:
2631+
LAMBDA_STACK_NAME: dbx-go-searchindex
2632+
AWS_REGION: us-east-1
2633+
MONGODB_VERSION: 7.0
2634+
args:
2635+
- ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh
2636+
- command: expansions.update
2637+
params:
2638+
file: src/go.mongodb.org/mongo-driver/atlas-expansion.yml
2639+
teardown_group:
2640+
- command: subprocess.exec
2641+
params:
2642+
working_dir: src/go.mongodb.org/mongo-driver
2643+
binary: bash
2644+
add_expansions_to_env: true
2645+
env:
2646+
LAMBDA_STACK_NAME: dbx-go-searchindex
2647+
AWS_REGION: us-east-1
2648+
args:
2649+
- ${DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh
2650+
setup_group_can_fail_task: true
2651+
setup_group_timeout_secs: 1800
2652+
tasks:
2653+
- test-search-index-deployed
26022654

26032655
buildvariants:
26042656
- name: static-analysis
@@ -2749,6 +2801,12 @@ buildvariants:
27492801
tasks:
27502802
- test-aws-lambda
27512803

2804+
- matrix_name: "searchindex-test"
2805+
matrix_spec: { version: ["7.0"], os-faas-80: ["rhel80-large-go-1-20"] }
2806+
display_name: "Search Index ${version} ${os-faas-80}"
2807+
tasks:
2808+
- test-search-index-task-group
2809+
27522810
- name: testgcpkms-variant
27532811
display_name: "GCP KMS"
27542812
run_on:

internal/test/searchindex/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.PHONY: default
2+
default:
3+
sam build --debug
4+
# Cannot connect to a local mongo server on non x86_64 architectures.
5+
# These cases require either building a mongodb docker container or
6+
# using a serverless service such as Atlas.
7+
sam local invoke --parameter-overrides "MongoDbUri=${MONGODB_URI}"
8+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module go.mongodb.go/mongo-driver/internal/test/mongodb
2+
3+
go 1.20
4+
5+
replace go.mongodb.org/mongo-driver => ../../../../../
6+
7+
require (
8+
github.com/aws/aws-lambda-go v1.41.0
9+
// Note that the Go driver version is replaced with the local Go driver code
10+
// by the replace directive above.
11+
go.mongodb.org/mongo-driver v1.11.7
12+
)
13+
14+
require (
15+
github.com/golang/snappy v0.0.1 // indirect
16+
github.com/klauspost/compress v1.13.6 // indirect
17+
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
18+
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
19+
github.com/xdg-go/scram v1.1.2 // indirect
20+
github.com/xdg-go/stringprep v1.0.4 // indirect
21+
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
22+
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
23+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
24+
golang.org/x/text v0.7.0 // indirect
25+
)
26+
27+
replace gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.2.8
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l+3Y=
2+
github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
6+
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
7+
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
8+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
9+
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
10+
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
11+
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
12+
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
13+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14+
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
15+
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
16+
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
17+
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
18+
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
19+
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
20+
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
21+
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
22+
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
23+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
24+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
25+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
26+
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
27+
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
28+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
29+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
30+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
31+
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
32+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
33+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
34+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
35+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
36+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
37+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
38+
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
39+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
40+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
41+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
42+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
43+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
44+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
45+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
46+
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
47+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
48+
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
49+
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
50+
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
51+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
52+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
53+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
54+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
55+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
56+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
57+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Copyright (C) MongoDB, Inc. 2023-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
package main
8+
9+
import (
10+
"context"
11+
"fmt"
12+
"net/http"
13+
"os"
14+
"time"
15+
16+
"github.com/aws/aws-lambda-go/events"
17+
"github.com/aws/aws-lambda-go/lambda"
18+
"go.mongodb.org/mongo-driver/bson"
19+
"go.mongodb.org/mongo-driver/event"
20+
"go.mongodb.org/mongo-driver/mongo"
21+
"go.mongodb.org/mongo-driver/mongo/options"
22+
)
23+
24+
const timeout = 10 * time.Second
25+
26+
// eventListener supports command, heartbeat, and pool event handlers to record
27+
// event durations, as well as the number of heartbeats, commands, and open
28+
// conections.
29+
type eventListener struct {
30+
commandCount int
31+
commandDuration int64
32+
heartbeatCount int
33+
heartbeatDuration int64
34+
openConnections int
35+
}
36+
37+
// commandMonitor initializes an event.CommandMonitor that will count the number
38+
// of successful or failed command events and record a running duration of these
39+
// events.
40+
func (listener *eventListener) commandMonitor() *event.CommandMonitor {
41+
succeeded := func(_ context.Context, e *event.CommandSucceededEvent) {
42+
listener.commandCount++
43+
listener.commandDuration += e.DurationNanos
44+
}
45+
46+
failed := func(_ context.Context, e *event.CommandFailedEvent) {
47+
listener.commandCount++
48+
listener.commandDuration += e.DurationNanos
49+
}
50+
51+
return &event.CommandMonitor{
52+
Succeeded: succeeded,
53+
Failed: failed,
54+
}
55+
}
56+
57+
// severMonitor initializes an event.ServerMonitor that will count the number
58+
// of successful or failed heartbeat events and record a running duration of
59+
// these events.
60+
func (listener *eventListener) serverMonitor() *event.ServerMonitor {
61+
succeeded := func(e *event.ServerHeartbeatSucceededEvent) {
62+
listener.heartbeatCount++
63+
listener.heartbeatDuration += e.DurationNanos
64+
}
65+
66+
failed := func(e *event.ServerHeartbeatFailedEvent) {
67+
listener.heartbeatCount++
68+
listener.heartbeatDuration += e.DurationNanos
69+
}
70+
71+
return &event.ServerMonitor{
72+
ServerHeartbeatSucceeded: succeeded,
73+
ServerHeartbeatFailed: failed,
74+
}
75+
}
76+
77+
// poolMonitor initialize an event.PoolMonitor that will increment each time a
78+
// new conneciton is created and decrement each time a connection is closed.
79+
func (listener *eventListener) poolMonitor() *event.PoolMonitor {
80+
poolEvent := func(e *event.PoolEvent) {
81+
switch e.Type {
82+
case event.ConnectionCreated:
83+
listener.openConnections++
84+
case event.ConnectionClosed:
85+
listener.openConnections--
86+
}
87+
}
88+
89+
return &event.PoolMonitor{Event: poolEvent}
90+
}
91+
92+
// response is the data we return in the body of the API Gateway response.
93+
type response struct {
94+
AvgCommandDuration float64 `json:"averageCommandDuration"`
95+
AvgHeartbeatDuration float64 `json:"averageHeartbeatDuration"`
96+
OpenConnections int `json:"openConnections"`
97+
HeartbeatCount int `json:"heartbeatCount"`
98+
}
99+
100+
// gateway500 is a convenience function for constructing a gateway response with
101+
// a 500 status code, indicating an internal server error.
102+
func gateway500() events.APIGatewayProxyResponse {
103+
return events.APIGatewayProxyResponse{
104+
StatusCode: http.StatusInternalServerError,
105+
Body: http.StatusText(http.StatusInternalServerError),
106+
}
107+
108+
}
109+
110+
// handler is the AWS Lambda handler, executing at runtime.
111+
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
112+
ctx, cancel := context.WithTimeout(ctx, timeout)
113+
defer cancel()
114+
115+
listener := new(eventListener)
116+
117+
clientOptions := options.Client().ApplyURI(os.Getenv("MONGODB_URI")).
118+
SetMonitor(listener.commandMonitor()).
119+
SetServerMonitor(listener.serverMonitor()).
120+
SetPoolMonitor(listener.poolMonitor())
121+
122+
// Create a MongoClient that points to MONGODB_URI and listens to the
123+
// ComandMonitor, ServerMonitor, and PoolMonitor events.
124+
client, err := mongo.NewClient(clientOptions)
125+
if err != nil {
126+
return gateway500(), fmt.Errorf("failed to create client: %w", err)
127+
}
128+
129+
// Attempt to connect to the client with a timeout.
130+
if err = client.Connect(ctx); err != nil {
131+
return gateway500(), fmt.Errorf("failed to connect: %w", err)
132+
}
133+
134+
defer client.Disconnect(ctx)
135+
136+
collection := client.Database("test").Collection("coll0")
137+
138+
// Insert the document.
139+
view := collection.SearchIndexes()
140+
name := "test-search-index"
141+
index, err := view.CreateOne(ctx, mongo.SearchIndexModel{
142+
Definition: bson.D{{"mapping", bson.D{{"dynamic", true}}}},
143+
Name: &name,
144+
})
145+
if err != nil {
146+
return gateway500(), fmt.Errorf("failed to insert: %w", err)
147+
}
148+
149+
// Delete the document.
150+
cursor, err := view.List(ctx, &index, nil)
151+
if err != nil {
152+
return gateway500(), fmt.Errorf("failed to delete: %w", err)
153+
}
154+
155+
defer cursor.Close(ctx)
156+
157+
return events.APIGatewayProxyResponse{
158+
Body: cursor.Current.String(),
159+
StatusCode: http.StatusOK,
160+
}, nil
161+
}
162+
163+
func main() {
164+
ctx := context.Background()
165+
166+
lambda.StartWithOptions(handler, lambda.WithContext(ctx))
167+
}

0 commit comments

Comments
 (0)