Skip to content

Commit

Permalink
GODRIVER-3046 [master] Fix FaaS Test Configuration (mongodb#1559)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Feb 15, 2024
1 parent 85ff8d2 commit 7fd4e30
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ tasks:
shell: bash
add_expansions_to_env: true
env:
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/internal/test/faas/awslambda
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/internal/cmd/faas/awslambda
LAMBDA_STACK_NAME: dbx-go-lambda
AWS_REGION: us-east-1
script: |
Expand Down
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ venv
test.suite

# AWS SAM-generated files
internal/test/faas/awslambda/.aws-sam
internal/test/faas/awslambda/events/event.json
internal/cmd/faas/awslambda/.aws-sam
internal/cmd/faas/awslambda/events/event.json

# Ignore compiled binaries from the compilecheck
internal/test/compilecheck/compilecheck
internal/test/compilecheck/compilecheck.so
internal/cmd/compilecheck/compilecheck
internal/cmd/compilecheck/compilecheck.so

# Ignore api report files
api-report.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"go.mongodb.org/mongo-driver/event"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/event"
"go.mongodb.org/mongo-driver/mongo/options"
)

Expand All @@ -41,12 +41,12 @@ type eventListener struct {
func (listener *eventListener) commandMonitor() *event.CommandMonitor {
succeeded := func(_ context.Context, e *event.CommandSucceededEvent) {
listener.commandCount++
listener.commandDuration += e.DurationNanos
listener.commandDuration += e.Duration.Nanoseconds()
}

failed := func(_ context.Context, e *event.CommandFailedEvent) {
listener.commandCount++
listener.commandDuration += e.DurationNanos
listener.commandDuration += e.Duration.Nanoseconds()
}

return &event.CommandMonitor{
Expand All @@ -61,7 +61,7 @@ func (listener *eventListener) commandMonitor() *event.CommandMonitor {
func (listener *eventListener) serverMonitor() *event.ServerMonitor {
succeeded := func(e *event.ServerHeartbeatSucceededEvent) {
listener.heartbeatCount++
listener.heartbeatDuration += e.DurationNanos
listener.heartbeatDuration += e.Duration.Nanoseconds()

if e.Awaited {
listener.heartbeatAwaitedCount++
Expand All @@ -70,7 +70,7 @@ func (listener *eventListener) serverMonitor() *event.ServerMonitor {

failed := func(e *event.ServerHeartbeatFailedEvent) {
listener.heartbeatCount++
listener.heartbeatDuration += e.DurationNanos
listener.heartbeatDuration += e.Duration.Nanoseconds()

if e.Awaited {
listener.heartbeatAwaitedCount++
Expand Down Expand Up @@ -130,16 +130,11 @@ func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events

// Create a MongoClient that points to MONGODB_URI and listens to the
// ComandMonitor, ServerMonitor, and PoolMonitor events.
client, err := mongo.NewClient(clientOptions)
client, err := mongo.Connect(clientOptions)
if err != nil {
return gateway500(), fmt.Errorf("failed to create client: %w", err)
}

// Attempt to connect to the client with a timeout.
if err = client.Connect(ctx); err != nil {
return gateway500(), fmt.Errorf("failed to connect: %w", err)
}

defer client.Disconnect(ctx)

collection := client.Database("faas").Collection("lambda")
Expand Down
1 change: 0 additions & 1 deletion internal/cmd/faas/awslambda/mongodb/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
require (
github.com/golang/snappy v0.0.1 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
Expand Down
2 changes: 0 additions & 2 deletions internal/cmd/faas/awslambda/mongodb/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/faas/awslambda/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ Globals:
Resources:
MongoDBFunction:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: go1.x
Properties:
CodeUri: mongodb/
Handler: main
Runtime: go1.x
Architectures:
- x86_64
Handler: bootstrap
Runtime: provided.al2
Architectures: [arm64]
Events:
MongoDB:
Type: Api
Expand Down Expand Up @@ -54,5 +55,4 @@ Outputs:
Value: !GetAtt MongoDBFunction.Arn
MongoDBFunctionIamRole:
Description: "Implicit IAM Role created for MongoDB function"
Value: !GetAtt MongoDBFunctionRole.Arn

Value: !GetAtt MongoDBFunctionRole.Arn

0 comments on commit 7fd4e30

Please sign in to comment.