Skip to content
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

feat(ecs): set default HealthCheckGracePeriodSeconds #2942

Merged
merged 6 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@
}
}
],
"HealthCheckGracePeriodSeconds": 60,
"NetworkConfiguration": {
"AwsvpcConfiguration": {
"AssignPublicIp": "DISABLED",
Expand Down Expand Up @@ -1038,4 +1039,4 @@
"Description": "Artifact hash for asset \"aws-ecs-integ/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\""
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
},
"DesiredCount": 1,
"LaunchType": "FARGATE",
"HealthCheckGracePeriodSeconds": 60,
"LoadBalancers": [
{
"ContainerName": "web",
Expand Down Expand Up @@ -701,4 +702,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@
},
"DesiredCount": 1,
"LaunchType": "FARGATE",
"HealthCheckGracePeriodSeconds": 60,
"LoadBalancers": [
{
"ContainerName": "web",
Expand Down
18 changes: 15 additions & 3 deletions packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ec2 = require('@aws-cdk/aws-ec2');
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
import iam = require('@aws-cdk/aws-iam');
import cloudmap = require('@aws-cdk/aws-servicediscovery');
import { Construct, Duration, Fn, IResource, Lazy, PhysicalName, Resource, Stack } from '@aws-cdk/cdk';
import { Construct, Duration, Fn, IResolvable, IResource, Lazy, PhysicalName, Resource, Stack } from '@aws-cdk/cdk';
import { NetworkMode, TaskDefinition } from '../base/task-definition';
import { ICluster } from '../cluster';
import { CfnService } from '../ecs.generated';
Expand Down Expand Up @@ -63,7 +63,7 @@ export interface BaseServiceProps {
/**
* Time after startup to ignore unhealthy load balancer checks.
*
* @default ??? FIXME
* @default - defaults to 60 seconds if at least one load balancer is in-use and it is not already set
*/
readonly healthCheckGracePeriod?: Duration;

Expand Down Expand Up @@ -152,7 +152,7 @@ export abstract class BaseService extends Resource
maximumPercent: props.maximumPercent || 200,
minimumHealthyPercent: props.minimumHealthyPercent === undefined ? 50 : props.minimumHealthyPercent
},
healthCheckGracePeriodSeconds: props.healthCheckGracePeriod && props.healthCheckGracePeriod.toSeconds(),
healthCheckGracePeriodSeconds: this.evaluateHealthGracePeriod(props.healthCheckGracePeriod),
/* role: never specified, supplanted by Service Linked Role */
networkConfiguration: Lazy.anyValue({ produce: () => this.networkConfiguration }),
serviceRegistries: Lazy.anyValue({ produce: () => this.serviceRegistries }),
Expand Down Expand Up @@ -392,6 +392,18 @@ export abstract class BaseService extends Resource

return cloudmapService;
}

/**
* Return the default grace period when load balancers are configured and
* healthCheckGracePeriod is not already set
*/
private evaluateHealthGracePeriod(providedHealthCheckGracePeriod?: Duration): IResolvable {
return Lazy.anyValue({
produce: () => providedHealthCheckGracePeriod !== undefined ? providedHealthCheckGracePeriod.toSeconds() :
this.loadBalancers.length > 0 ? 60 :
undefined
});
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"HealthCheckGracePeriodSeconds": 60,
"LaunchType": "EC2",
"LoadBalancers": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"HealthCheckGracePeriodSeconds": 60,
"LaunchType": "EC2",
"LoadBalancers": [
{
Expand Down
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,17 @@ export = {
ContainerPort: 808,
LoadBalancerName: { Ref: "LB8A12904C" }
}
],
]
}));

expect(stack).to(haveResource('AWS::ECS::Service', {
// if any load balancer is configured and healthCheckGracePeriodSeconds is not
// set, then it should default to 60 seconds.
HealthCheckGracePeriodSeconds: 60
}));

test.done();
},
}
},

'When enabling service discovery': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"HealthCheckGracePeriodSeconds": 60,
"LaunchType": "FARGATE",
"LoadBalancers": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ export = {
}
}));

expect(stack).to(haveResource('AWS::ECS::Service', {
// if any load balancer is configured and healthCheckGracePeriodSeconds is not
hencrice marked this conversation as resolved.
Show resolved Hide resolved
// set, then it should default to 60 seconds.
HealthCheckGracePeriodSeconds: 60
}));

test.done();
},

Expand Down