Skip to content

Stop making a new S3 bucket for every integration tests run #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2021

Conversation

nhinsch
Copy link
Contributor

@nhinsch nhinsch commented Apr 1, 2021

What does this PR do?

Updates the integration tests to use a single shared S3 bucket for deployment rather than creating a new one every time.

Motivation

Sometimes, the CloudFormation stack created by integration tests might not be deleted at the end of the test run (e.g. if the tests are cancelled). When this happens, we cannot easily remove the CloudFormation stack after the test run, because the stack contains an S3 bucket that contains an Object. We have to empty the S3 bucket before we can manually delete the stack.

By having one shared bucket for all integration test runs, we no longer have to worry about this issue when removing the stack. This bucket also has a lifecycle policy set that will remove objects after one day, so they will never accumulate if they are left behind.

Testing Guidelines

I ran the integration tests.

Additional Notes

It is still possible that we might end up with extraneous CloudFormation stacks, but they will be easier to remove and we can deal with that issue later if it becomes a problem.

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

@nhinsch nhinsch requested a review from a team as a code owner April 1, 2021 20:39
@@ -12,6 +12,8 @@ provider:
DD_API_KEY: ${env:DD_API_KEY}
lambdaHashingVersion: 20201221
timeout: 15
deploymentBucket:
name: integration-tests-deployment-bucket
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link to docs for deploymentBucket? I don't see where it sets up the 1 day lifecycle policy by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lifecycle policy is a setting in AWS. I hardcoded this bucket name in the test, and then configured the bucket in AWS to delete all objects older than one day.

Does that answer your question or do you still want to see docs for something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, we're good. I misunderstood you, I thought deploymentBucket was setting the lifecycle policy automatically. It looks like it automatically prunes artifacts once it has more than 5 artifacts, which is pretty good in and of itself. https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/

Copy link
Contributor

@agocs agocs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick question about the deploymentBucket. It looks like a good change regardless. Doing something like this in your run_integration_tests.sh will help tear down tests if they're cancelled midway through as well.

 63 # trap remove_stack EXIT should go immediately after we create the stack
 64 remove_stack() {
 65     if [ "$KEEP_STACK" = true ]; then
 66         return
 67     fi
 68     echo "About to remove!"
 69     echo serverless remove -- java-layer-version "$tracing_layer_version"
 70     serverless remove --java-layer-version "$tracing_layer_version"
 71 }
 72
 73 trap remove_stack EXIT

@nhinsch
Copy link
Contributor Author

nhinsch commented Apr 1, 2021

Thanks @agocs, trap looks like a great addition. I'm not going to include it in this PR for simplicity but I will follow up later in another PR.

@nhinsch nhinsch merged commit bf466a4 into main Apr 1, 2021
@nhinsch nhinsch deleted the ngh/bucket branch April 1, 2021 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants