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: circuit breaker configuration #673

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/extensions/extension-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down
33 changes: 33 additions & 0 deletions test/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading