From 07ed5fcd157f6f6cec837c674b105dd0378ad572 Mon Sep 17 00:00:00 2001 From: Haakon Ranum Date: Thu, 8 Feb 2024 11:18:09 +0100 Subject: [PATCH 1/2] feat: circuit breaker configuration --- .prettierignore | 1 + API.md | 28 ++++++++++++++++++++++ src/extensions/extension-interfaces.ts | 7 ++++++ src/service.ts | 8 +++++++ test/service.test.ts | 33 ++++++++++++++++++++++++++ 5 files changed, 77 insertions(+) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..6461deec --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +*.ts diff --git a/API.md b/API.md index 5be1b2ae..b60c25f5 100644 --- a/API.md +++ b/API.md @@ -1669,6 +1669,7 @@ const serviceBuild: ServiceBuild = { ... } | cluster | aws-cdk-lib.aws_ecs.ICluster | The cluster in which to launch the service. | | taskDefinition | aws-cdk-lib.aws_ecs.TaskDefinition | The task definition registered to this service. | | assignPublicIp | boolean | Specifies whether the task's elastic network interface receives a public IP address. | +| circuitBreaker | aws-cdk-lib.aws_ecs.DeploymentCircuitBreaker | Circuit breaker configuration for the service. | | cloudMapOptions | aws-cdk-lib.aws_ecs.CloudMapOptions | Configuration for how to register the service in service discovery. | | desiredCount | number | How many tasks to run. | | healthCheckGracePeriod | aws-cdk-lib.Duration | How long the healthcheck can fail during initial task startup before the task is considered unhealthy. | @@ -1717,6 +1718,19 @@ If true, each task will receive a public IP address. --- +##### `circuitBreaker`Optional + +```typescript +public readonly circuitBreaker: DeploymentCircuitBreaker; +``` + +- *Type:* aws-cdk-lib.aws_ecs.DeploymentCircuitBreaker +- *Default:* No circuit breaker configured + +Circuit breaker configuration for the service. + +--- + ##### `cloudMapOptions`Optional ```typescript @@ -1817,6 +1831,7 @@ const serviceProps: ServiceProps = { ... } | environment | IEnvironment | The environment to launch the service in. | | serviceDescription | ServiceDescription | The ServiceDescription used to build the service. | | autoScaleTaskCount | AutoScalingOptions | The options for configuring the auto scaling target. | +| circuitBreaker | aws-cdk-lib.aws_ecs.DeploymentCircuitBreaker | Circuit breaker configuration for the service. | | desiredCount | number | The desired number of instantiations of the task definition to keep running on the service. | | taskRole | aws-cdk-lib.aws_iam.IRole | The name of the IAM role that grants containers in the task permission to call AWS APIs on your behalf. | @@ -1859,6 +1874,19 @@ The options for configuring the auto scaling target. --- +##### `circuitBreaker`Optional + +```typescript +public readonly circuitBreaker: DeploymentCircuitBreaker; +``` + +- *Type:* aws-cdk-lib.aws_ecs.DeploymentCircuitBreaker +- *Default:* No circuit breaker configured + +Circuit breaker configuration for the service. + +--- + ##### `desiredCount`Optional ```typescript diff --git a/src/extensions/extension-interfaces.ts b/src/extensions/extension-interfaces.ts index 5cfcc901..fea5cb5c 100644 --- a/src/extensions/extension-interfaces.ts +++ b/src/extensions/extension-interfaces.ts @@ -91,6 +91,13 @@ export interface ServiceBuild { * @default - 200 */ readonly maxHealthyPercent?: number; + + /** + * Circuit breaker configuration for the service. + * + * @default - No circuit breaker configured + */ + readonly circuitBreaker?: ecs.DeploymentCircuitBreaker; } /** diff --git a/src/service.ts b/src/service.ts index 37a9f96a..f0dea1a6 100644 --- a/src/service.ts +++ b/src/service.ts @@ -55,6 +55,13 @@ export interface ServiceProps { * @default none */ readonly autoScaleTaskCount?: AutoScalingOptions; + + /** + * Circuit breaker configuration for the service. + * + * @default - No circuit breaker configured + */ + readonly circuitBreaker?: ecs.DeploymentCircuitBreaker; } export interface AutoScalingOptions { @@ -231,6 +238,7 @@ export class Service extends Construct { taskDefinition: this.taskDefinition, minHealthyPercent: 100, maxHealthyPercent: 200, + circuitBreaker: props.circuitBreaker, desiredCount: props.desiredCount ?? 1, } as ServiceBuild; diff --git a/test/service.test.ts b/test/service.test.ts index c5a4bc38..27935d19 100644 --- a/test/service.test.ts +++ b/test/service.test.ts @@ -21,6 +21,39 @@ describe('service', () => { }).toThrow(/Service 'my-service' must have a Container extension/); }); + test('allows circuit breaker configuration', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const environment = new Environment(stack, 'production'); + const serviceDescription = new ServiceDescription(); + serviceDescription.add(new Container({ + cpu: 256, + memoryMiB: 512, + trafficPort: 80, + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + })); + + new Service(stack, 'my-service', { + environment, + serviceDescription, + circuitBreaker: { + rollback: true, + }, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { + DeploymentConfiguration: { + DeploymentCircuitBreaker: { + Enable: true, + Rollback: true, + }, + }, + }); + }); + test('allows scaling on a target CPU utilization', () => { // GIVEN const stack = new Stack(); From d22c9c2f86110f9f2890551e2a2af4ea9f04c932 Mon Sep 17 00:00:00 2001 From: Haakon Ranum Date: Thu, 8 Feb 2024 11:27:22 +0100 Subject: [PATCH 2/2] clean up --- .prettierignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index 6461deec..00000000 --- a/.prettierignore +++ /dev/null @@ -1 +0,0 @@ -*.ts