Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it work
Browse files Browse the repository at this point in the history
comandeo-mongo committed Oct 19, 2023
1 parent 1d979ff commit 2c8833c
Showing 10 changed files with 310 additions and 73 deletions.
1 change: 1 addition & 0 deletions .evergreen/atlas
81 changes: 72 additions & 9 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
@@ -482,6 +482,8 @@ task_groups:
script: |
${PREPARE_SHELL}
echo "Setting up Atlas cluster"
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
@@ -492,6 +494,8 @@ task_groups:
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
echo "MONGODB_URI=${MONGODB_URI}"
- command: expansions.update
params:
file: src/atlas-expansion.yml
@@ -512,6 +516,51 @@ task_groups:
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
tasks:
- test-full-atlas-task

- name: test_aws_lambda_task_group
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800 # 30 minutes
setup_group:
- func: fetch source
- func: create expansions
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}
echo "Setting up Atlas cluster"
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
MONGODB_VERSION="7.0" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
- command: expansions.update
params:
file: src/atlas-expansion.yml
teardown_group:
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
tasks:
- test-aws-lambda-deployed

- name: testgcpkms_task_group
@@ -706,21 +755,35 @@ tasks:
- name: "test-aws-lambda-deployed"
commands:
- func: "install dependencies"
- command: ec2.assume_role
params:
role_arn: ${LAMBDA_AWS_ROLE_ARN}
duration_seconds: 3600
- command: subprocess.exec
- command: shell.exec
type: test
params:
working_dir: src
binary: bash
add_expansions_to_env: true
args:
- ${DRIVERS_TOOLS}/.evergreen/aws_lambda/run-deployed-lambda-aws-tests.sh
working_dir: "src"
shell: "bash"
script: |
${PREPARE_SHELL}
export MONGODB_URI=${MONGODB_URI}
.evergreen/run-tests-deployed-lambda.sh
env:
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/spec/faas/ruby-sam-app
AWS_REGION: us-east-1
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
DRIVERS_TOOLS: ${DRIVERS_TOOLS}
DRIVERS_ATLAS_PUBLIC_API_KEY: ${DRIVERS_ATLAS_PUBLIC_API_KEY}
DRIVERS_ATLAS_PRIVATE_API_KEY: ${DRIVERS_ATLAS_PRIVATE_API_KEY}
DRIVERS_ATLAS_LAMBDA_USER: ${DRIVERS_ATLAS_LAMBDA_USER}
DRIVERS_ATLAS_LAMBDA_PASSWORD: ${DRIVERS_ATLAS_LAMBDA_PASSWORD}
DRIVERS_ATLAS_GROUP_ID: ${DRIVERS_ATLAS_GROUP_ID}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN}
LAMBDA_STACK_NAME: "dbx-ruby-lambda"
RVM_RUBY: ruby-3.2
MONGODB_URI: ${MONGODB_URI}
axes:

- id: preload
@@ -1712,7 +1775,7 @@ buildvariants:
- matrix_name: "aws-lambda"
matrix_spec:
ruby: "ruby-3.2"
os: rhel8
os: ubuntu2204
display_name: "AWS Lambda"
tasks:
- name: test-aws-lambda-deployed
- name: test_aws_lambda_task_group
77 changes: 70 additions & 7 deletions .evergreen/config/common.yml.erb
Original file line number Diff line number Diff line change
@@ -479,6 +479,8 @@ task_groups:
script: |
${PREPARE_SHELL}

echo "Setting up Atlas cluster"

DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
@@ -489,6 +491,8 @@ task_groups:
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh

echo "MONGODB_URI=${MONGODB_URI}"
- command: expansions.update
params:
file: src/atlas-expansion.yml
@@ -509,6 +513,51 @@ task_groups:
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
tasks:
- test-full-atlas-task

- name: test_aws_lambda_task_group
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800 # 30 minutes
setup_group:
- func: fetch source
- func: create expansions
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}

echo "Setting up Atlas cluster"

DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
MONGODB_VERSION="7.0" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
- command: expansions.update
params:
file: src/atlas-expansion.yml
teardown_group:
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}

DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
tasks:
- test-aws-lambda-deployed

- name: testgcpkms_task_group
@@ -703,18 +752,32 @@ tasks:

- name: "test-aws-lambda-deployed"
commands:
- func: "install dependencies"
- command: ec2.assume_role
params:
role_arn: ${LAMBDA_AWS_ROLE_ARN}
duration_seconds: 3600
- command: subprocess.exec
- command: shell.exec
type: test
params:
working_dir: src
binary: bash
add_expansions_to_env: true
args:
- ${DRIVERS_TOOLS}/.evergreen/aws_lambda/run-deployed-lambda-aws-tests.sh
working_dir: "src"
shell: "bash"
script: |
${PREPARE_SHELL}
export MONGODB_URI=${MONGODB_URI}
.evergreen/run-tests-deployed-lambda.sh
env:
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/spec/faas/ruby-sam-app
AWS_REGION: us-east-1
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
DRIVERS_TOOLS: ${DRIVERS_TOOLS}
DRIVERS_ATLAS_PUBLIC_API_KEY: ${DRIVERS_ATLAS_PUBLIC_API_KEY}
DRIVERS_ATLAS_PRIVATE_API_KEY: ${DRIVERS_ATLAS_PRIVATE_API_KEY}
DRIVERS_ATLAS_LAMBDA_USER: ${DRIVERS_ATLAS_LAMBDA_USER}
DRIVERS_ATLAS_LAMBDA_PASSWORD: ${DRIVERS_ATLAS_LAMBDA_PASSWORD}
DRIVERS_ATLAS_GROUP_ID: ${DRIVERS_ATLAS_GROUP_ID}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN}
LAMBDA_STACK_NAME: "dbx-ruby-lambda"
RVM_RUBY: ruby-3.2
MONGODB_URI: ${MONGODB_URI}
4 changes: 2 additions & 2 deletions .evergreen/config/standard.yml.erb
Original file line number Diff line number Diff line change
@@ -524,7 +524,7 @@ buildvariants:
- matrix_name: "aws-lambda"
matrix_spec:
ruby: <%= latest_ruby %>
os: rhel8
os: ubuntu2204
display_name: "AWS Lambda"
tasks:
- name: test-aws-lambda-deployed
- name: test_aws_lambda_task_group
117 changes: 117 additions & 0 deletions .evergreen/run-deployed-lambda-aws-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash
set -o errexit # Exit the script with error if any of the commands fail

# Explanation of required environment variables:
#
# TEST_LAMBDA_DIRECTORY: The root of the project's Lambda sam project.
# DRIVERS_ATLAS_PUBLIC_API_KEY: The public Atlas key for the drivers org.
# DRIVERS_ATLAS_PRIVATE_API_KEY: The private Atlas key for the drivers org.
# DRIVERS_ATLAS_LAMBDA_USER: The user for the lambda cluster.
# DRIVERS_ATLAS_LAMBDA_PASSWORD: The password for the user.
# DRIVERS_ATLAS_GROUP_ID: The id of the individual projects under the drivers org, per language.
# LAMBDA_STACK_NAME: The name of the stack on lambda "dbx-<language>-lambda"
# AWS_REGION: The region for the function - generally us-east-1

VARLIST=(
TEST_LAMBDA_DIRECTORY
DRIVERS_ATLAS_PUBLIC_API_KEY
DRIVERS_ATLAS_PRIVATE_API_KEY
DRIVERS_ATLAS_LAMBDA_USER
DRIVERS_ATLAS_LAMBDA_PASSWORD
DRIVERS_ATLAS_GROUP_ID
LAMBDA_STACK_NAME
AWS_REGION
)

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in ${VARLIST[*]}; do
[[ -z "${!VARNAME}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

# Set up the common variables
. `dirname "$0"`/atlas/setup-variables.sh

# Restarts the cluster's primary node.
restart_cluster_primary ()
{
echo "Testing Atlas primary restart..."
curl \
--digest -u ${DRIVERS_ATLAS_PUBLIC_API_KEY}:${DRIVERS_ATLAS_PRIVATE_API_KEY} \
-X POST \
"${ATLAS_BASE_URL}/groups/${DRIVERS_ATLAS_GROUP_ID}/clusters/${FUNCTION_NAME}/restartPrimaries"
}

# Deploys a lambda function to the set stack name.
deploy_lambda_function ()
{
echo "Deploying Lambda function..."
sam deploy \
--stack-name "${FUNCTION_NAME}" \
--capabilities CAPABILITY_IAM \
--resolve-s3 \
--parameter-overrides "MongoDbUri=${MONGODB_URI}" \
--region ${AWS_REGION}
}

# Get the ARN for the Lambda function we created and export it.
get_lambda_function_arn ()
{
echo "Getting Lambda function ARN..."
LAMBDA_FUNCTION_ARN=$(sam list stack-outputs \
--stack-name ${FUNCTION_NAME} \
--region ${AWS_REGION} \
--output json | jq '.[] | select(.OutputKey == "MongoDBFunction") | .OutputValue' | tr -d '"'
)
echo "Lambda function ARN: $LAMBDA_FUNCTION_ARN"
export LAMBDA_FUNCTION_ARN=$LAMBDA_FUNCTION_ARN
}

delete_lambda_function ()
{
echo "Deleting Lambda Function..."
sam delete --stack-name ${FUNCTION_NAME} --no-prompts --region us-east-1
}

cleanup ()
{
delete_lambda_function
}

trap cleanup EXIT SIGHUP

cd "${TEST_LAMBDA_DIRECTORY}"

sam build --use-container

deploy_lambda_function

get_lambda_function_arn


check_lambda_output () {
if grep -q FunctionError output.json
then
echo "Exiting due to FunctionError!"
exit 1
fi
cat output.json | jq -r '.LogResult' | base64 --decode
}

aws lambda invoke --function-name ${LAMBDA_FUNCTION_ARN} --log-type Tail lambda-invoke-standard.json > output.json
cat lambda-invoke-standard.json
check_lambda_output

echo "Sleeping 1 minute to build up some streaming protocol heartbeats..."
sleep 60
aws lambda invoke --function-name ${LAMBDA_FUNCTION_ARN} --log-type Tail lambda-invoke-frozen.json > output.json
cat lambda-invoke-frozen.json
check_lambda_output

restart_cluster_primary

echo "Sleeping 1 minute to build up some streaming protocol heartbeats..."
sleep 60
aws lambda invoke --function-name ${LAMBDA_FUNCTION_ARN} --log-type Tail lambda-invoke-outage.json > output.json
cat lambda-invoke-outage.json
check_lambda_output
17 changes: 17 additions & 0 deletions .evergreen/run-tests-deployed-lambda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -ex

. `dirname "$0"`/../spec/shared/shlib/distro.sh
. `dirname "$0"`/../spec/shared/shlib/set_env.sh
. `dirname "$0"`/functions.sh

set_env_vars
set_env_python
set_env_ruby

echo MONGODB_URI: ${MONGODB_URI}

export MONGODB_URI=${MONGODB_URI}

. `dirname "$0"`/run-deployed-lambda-aws-tests.sh
2 changes: 0 additions & 2 deletions spec/faas/ruby-sam-app/mongodb/Gemfile
Original file line number Diff line number Diff line change
@@ -2,5 +2,3 @@ source "https://rubygems.org"

gem "httparty"
gem "mongo"

ruby '~> 3.2.0'
Loading

0 comments on commit 2c8833c

Please sign in to comment.