feat(ecs-patterns) add idle timeout to alb fargate and ec2 services#21261
feat(ecs-patterns) add idle timeout to alb fargate and ec2 services#21261mergify[bot] merged 29 commits intoaws:mainfrom
Conversation
| /** | ||
| * The load balancer idle timeout, in seconds | ||
| * | ||
| * @default 60 |
There was a problem hiding this comment.
We're not defaulting it to 60 seconds so I don't think this should say 60 here. I'd remove the @default altogether.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
What are your thoughts on explaining the behavior if nothing is provided
@default - idle timeout is set to 60 seconds
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ah yeah totally agree. Added that guardrail in
Pull request has been modified.
| "Value": "false" | ||
| }, | ||
| { | ||
| "Key": "idle_timeout.timeout_seconds", |
There was a problem hiding this comment.
Shows up here in this test.
| "value": "false" | ||
| }, | ||
| { | ||
| "key": "idle_timeout.timeout_seconds", |
There was a problem hiding this comment.
And here in this test
| zoneName: 'example.com.', | ||
| }), | ||
| redirectHTTP: true, | ||
| idleTimeout: Duration.seconds(120), |
There was a problem hiding this comment.
Matches the 120 you added here.
| }).toThrow(); | ||
| }); | ||
|
|
||
| test('errors when idleTimeout is over 4000 seconds', () => { |
There was a problem hiding this comment.
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.
TheRealAmazonKendra
left a comment
There was a problem hiding this comment.
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!
packages/@aws-cdk/aws-ecs-patterns/lib/base/application-load-balanced-service-base.ts
Outdated
Show resolved
Hide resolved
…alanced-service-base.ts Co-authored-by: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com>
Pull request has been modified.
TheRealAmazonKendra
left a comment
There was a problem hiding this comment.
Putting this back in request changes for those test cases. I use that status to know when to come back and re-review.
Pull request has been modified.
TheRealAmazonKendra
left a comment
There was a problem hiding this comment.
@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, |
There was a problem hiding this comment.
This is redundant. You only need idleTimeout: props.idleTimeout; here.
Pull request has been modified.
|
Hmm i added the extra test and did a rebase on main and now there are extra files in this PR 🤦 |
|
I'll try to see if i can undo the rebase to clean up the pr |
|
@Mergifyio update |
✅ Branch has been successfully updated |
@michaeldrey looks like mergify has your back here. |
TheRealAmazonKendra
left a comment
There was a problem hiding this comment.
Just one last thing.
packages/@aws-cdk/aws-ecs-patterns/lib/base/application-load-balanced-service-base.ts
Outdated
Show resolved
Hide resolved
…alanced-service-base.ts Co-authored-by: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com>
|
Ah i missed that. Committed now. I'll begin to make the same updates to the multi ALB PR this weekend |
Pull request has been modified.
TheRealAmazonKendra
left a comment
There was a problem hiding this comment.
Thank you for all your work on this!
|
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
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). |
…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*
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:
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
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:
New Features
yarn integto deploy the infrastructure and generate the snapshot (i.e.yarn integwithout--dry-run)?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license