Skip to content

Commit

Permalink
DRIVERS-2723: ensure atlas cluster names are unique (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson authored Sep 15, 2023
1 parent 6f42c3b commit 1f018c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions .evergreen/atlas/setup-atlas-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ DRIVERS_ATLAS_LAMBDA_USER
DRIVERS_ATLAS_LAMBDA_PASSWORD
LAMBDA_STACK_NAME
task_id
execution
)

# Ensure that all variables required to run the test are set, otherwise throw
Expand Down
12 changes: 10 additions & 2 deletions .evergreen/atlas/setup-variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ ATLAS_API_VERSION="v1.0"
ATLAS_BASE_URL="https://cloud.mongodb.com/api/atlas/$ATLAS_API_VERSION"

# create a unique per CI task tag for the function.
TASK_NAME=$(echo $task_id | base64 | head -c 8)
# task_id has the structure $projectID_$variantName_$taskName_$commitHash_$createTime, which is unique per task per ci run per project.
# task_id is NOT unique across restarts of the same task though, so we include execution to ensure that it is unique for every restart too.
#
# the generated string is then transformed to satisfy Atlas cluster naming requirements
# - the string cannot be > 64 characters long, so we hash the name to shorten it and maintain its uniqueness (hashes do have collisions but infrequently
# enough that hashing suffices here)
# - we convert it to hex encoding because cluster names must be alphanumeric (hyphens are allowed)
transform="process.stdout.write(require('crypto').createHash('md5').update(process.argv[1]).digest().toString('hex'))"
TASK_ID=$(node -e $transform "${task_id}-${execution}")

# Add git commit to name of function and cluster.
FUNCTION_NAME="${LAMBDA_STACK_NAME}-${TASK_NAME}-$(git rev-parse --short HEAD)"
FUNCTION_NAME="${LAMBDA_STACK_NAME}-${TASK_ID}"
1 change: 1 addition & 0 deletions .evergreen/atlas/teardown-atlas-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ DRIVERS_ATLAS_PRIVATE_API_KEY
DRIVERS_ATLAS_GROUP_ID
LAMBDA_STACK_NAME
task_id
execution
)

# Ensure that all variables required to run the test are set, otherwise throw
Expand Down

0 comments on commit 1f018c7

Please sign in to comment.