Skip to content

feat(ecs-patterns) add idle timeout to alb fargate and ec2 services#21261

Merged
mergify[bot] merged 29 commits intoaws:mainfrom
michaeldrey:alb_idle_timeout
Jul 30, 2022
Merged

feat(ecs-patterns) add idle timeout to alb fargate and ec2 services#21261
mergify[bot] merged 29 commits intoaws:mainfrom
michaeldrey:alb_idle_timeout

Conversation

@michaeldrey
Copy link
Copy Markdown
Contributor

@michaeldrey michaeldrey commented Jul 21, 2022

This PR exposes the idleTime property for both EC2 and Fargate ALB services. Per the CFN specs, I have set the idleTimeout to default to 60 seconds, and it cannot exceed 4000 seconds.

If no value is provided we set the value to undefined. We do this because:

  1. The default value is set for the user via the CFN. The behavior for the property is to either add a value or leave it undefined and let CFN set the default. See here

  2. Setting a default causes snapshot tests to fail for dependent services as we're adding a new attribute to the cloudformation.

A README entry has been created for this property.

Relates to
#21221
#21266

closes #12913

All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Jul 21, 2022

@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 labels Jul 21, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team July 21, 2022 04:01
/**
* The load balancer idle timeout, in seconds
*
* @default 60
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We're not defaulting it to 60 seconds so I don't think this should say 60 here. I'd remove the @default altogether.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only issue with removing @default is that the linter and spec requires that optional properties must have @default documentation

error: [awslint:props-default-doc:@aws-cdk/aws-ecs-patterns.ApplicationLoadBalancedServiceBaseProps.idleTimeout] Optional property must have @default documentation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What are your thoughts on explaining the behavior if nothing is provided
@default - idle timeout is set to 60 seconds

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, forgot about that. Just put that it's undefined. I think it's fine to note that cloudformation will set it to 60 when undefined, but we're not setting anything on their behalf so let's make sure it doesn't look like the default is coming from our code.

}).toThrow();
});

test('errors when idleTimeout is over 4000 seconds', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add three more test cases here: one that uses a value below 1 and the timeout, one with a valid timeout, and one that doesn't add a timeout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Working through this, I am able to add the first two tests without issue, but for the third, it appears that idle_timeout.timeout_seconds does not show up as an attribute in the CFN output. Still trying to figure out the best way to test this given that the CFN spec says it's 60 (i've also checked loadbalancers i've created and in the console it says 60)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Take a look at the test below the one you've written. That's how we want to test it against the template instead of using .toBeTruthy(); We know that if it's not showing up in the template, we're not actually passing that value to CloudFormation so it will default back to 60 seconds.

It's fine for it to be undefined in the 4th case, that's what we're looking for. CloudFormation has their own internal logic that takes an undefined value and translates it to 60 seconds. From the integ test, you can see that the 120 seconds you set are showing up in the snapshots, so it looks like it is being added correctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

AH! Okay I was under the impression that if we didn't add idle_timeout it would still show up in the CFN.

I'll add the other test checking for idle_time to be undefined when it's not added in a little bit and get that pushed up for ya. Really appreciate you taking the time to run through this with me!


if (props.idleTimeout) {
if (props.idleTimeout > Duration.seconds(4000)) {
throw new Error( 'IdleTime cannot exceed 4000 seconds');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like the minimum is also 1 so we should check against that as well. We don't want to allow for a number below 1 either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah totally agree. Added that guardrail in

@TheRealAmazonKendra TheRealAmazonKendra changed the title feat(ecs-patterns) adds idle timeout to alb fargate and ec2 services feat(ecs-patterns) add idle timeout to alb fargate and ec2 services Jul 22, 2022
@mergify mergify bot dismissed TheRealAmazonKendra’s stale review July 22, 2022 06:08

Pull request has been modified.

"Value": "false"
},
{
"Key": "idle_timeout.timeout_seconds",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shows up here in this test.

"value": "false"
},
{
"key": "idle_timeout.timeout_seconds",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And here in this test

zoneName: 'example.com.',
}),
redirectHTTP: true,
idleTimeout: Duration.seconds(120),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Matches the 120 you added here.

}).toThrow();
});

test('errors when idleTimeout is over 4000 seconds', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Take a look at the test below the one you've written. That's how we want to test it against the template instead of using .toBeTruthy(); We know that if it's not showing up in the template, we're not actually passing that value to CloudFormation so it will default back to 60 seconds.

It's fine for it to be undefined in the 4th case, that's what we're looking for. CloudFormation has their own internal logic that takes an undefined value and translates it to 60 seconds. From the integ test, you can see that the 120 seconds you set are showing up in the snapshots, so it looks like it is being added correctly.

Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

This is VERY close to being ready to go. See my notes about the tests. I also pointed out where you are seeing the output you expect, so you can see where it shows up in the template. Please also take the feedback on this one and apply it to the other PR you have open and then that review will go super quick. We appreciate all your work on this!

…alanced-service-base.ts

Co-authored-by: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com>
@mergify mergify bot dismissed TheRealAmazonKendra’s stale review July 22, 2022 16:36

Pull request has been modified.

Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Putting this back in request changes for those test cases. I use that status to know when to come back and re-review.

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review July 27, 2022 21:20

Pull request has been modified.

Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

@michaeldrey Just a reminder to please add one more test case where we leave idleTimeout as undefined.

It also looks like you'll need to run the integ tests locally with yarn integ --update-on-failed integ.alb-fargate-service-https-idle-timeout.js. It's now failing due to us merging an unrelated change that added the Memory field in your template.

vpc: this.cluster.vpc,
loadBalancerName: props.loadBalancerName,
internetFacing,
idleTimeout: props.idleTimeout ?? undefined,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is redundant. You only need idleTimeout: props.idleTimeout; here.

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review July 29, 2022 18:58

Pull request has been modified.

@michaeldrey
Copy link
Copy Markdown
Contributor Author

Hmm i added the extra test and did a rebase on main and now there are extra files in this PR 🤦

@michaeldrey
Copy link
Copy Markdown
Contributor Author

I'll try to see if i can undo the rebase to clean up the pr

@TheRealAmazonKendra
Copy link
Copy Markdown
Contributor

@Mergifyio update

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 29, 2022

update

✅ Branch has been successfully updated

@TheRealAmazonKendra
Copy link
Copy Markdown
Contributor

I'll try to see if i can undo the rebase to clean up the pr

@michaeldrey looks like mergify has your back here.

Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Just one last thing.

…alanced-service-base.ts

Co-authored-by: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com>
@michaeldrey
Copy link
Copy Markdown
Contributor Author

Ah i missed that. Committed now. I'll begin to make the same updates to the multi ALB PR this weekend

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review July 29, 2022 23:43

Pull request has been modified.

Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Thank you for all your work on this!

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 30, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 6b163ec
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 00a3388 into aws:main Jul 30, 2022
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 30, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

mergify bot pushed a commit that referenced this pull request Aug 1, 2022
…ices (#21266)

This PR exposes the idleTime property for both EC2 and Fargate **multi** ALB services. [Per the CFN specs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-loadbalancer-loadbalancerattributes.html), I have set the idleTimeout to default to 60 seconds, and it cannot exceed 4000 seconds.

If no value is provided we set the value to undefined. We do this because:

1. The default value is set for the user via the CFN. The behavior for the property is to either add a value or leave it undefined and let CFN set the default.[ See here](https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts#L102)

2. Setting a default causes snapshot tests to fail for dependent services as we're adding a new attribute to the cloudformation.

A README entry has been created for this property.

Relates to
#21221
#21261

closes #12913
----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ApplicationLoadBalancedFargateService CDK construct: currently there is no way to specify idleTimeout for the load balancer

3 participants