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(codedeploy): ignoreAlarmConfiguration parameter to Deployment Groups #26957

Merged
merged 15 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions packages/aws-cdk-lib/aws-codedeploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const deploymentGroup = new codedeploy.ServerDeploymentGroup(this, 'CodeDeployDe
// whether to ignore failure to fetch the status of alarms from CloudWatch
// default: false
ignorePollAlarmsFailure: false,
// whether to skip the step of checking CloudWatch alarms during the deployment process
// default: false
ignoreAlarmConfiguration: false,
// auto-rollback configuration
autoRollback: {
failedDeployment: true, // default: true
Expand Down
14 changes: 13 additions & 1 deletion packages/aws-cdk-lib/aws-codedeploy/lib/ecs/deployment-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ export interface EcsDeploymentGroupProps {
* @default - default AutoRollbackConfig.
*/
readonly autoRollback?: AutoRollbackConfig;

/**
* Whether to skip the step of checking CloudWatch alarms during the deployment process
*
* @default false
nrgeil marked this conversation as resolved.
Show resolved Hide resolved
*/
readonly ignoreAlarmConfiguration?: boolean;
}

/**
Expand Down Expand Up @@ -261,7 +268,12 @@ export class EcsDeploymentGroup extends DeploymentGroupBase implements IEcsDeplo
}),
loadBalancerInfo: cdk.Lazy.any({ produce: () => this.renderLoadBalancerInfo(props.blueGreenDeploymentConfig) }),
alarmConfiguration: cdk.Lazy.any({
produce: () => renderAlarmConfiguration(this.alarms, props.ignorePollAlarmsFailure, removeAlarmsFromDeploymentGroup),
produce: () => renderAlarmConfiguration(
this.alarms,
props.ignorePollAlarmsFailure,
removeAlarmsFromDeploymentGroup,
props.ignoreAlarmConfiguration,
),
}),
autoRollbackConfiguration: cdk.Lazy.any({ produce: () => renderAutoRollbackConfiguration(this.alarms, props.autoRollback) }),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ export interface LambdaDeploymentGroupProps {
* @default - default AutoRollbackConfig.
*/
readonly autoRollback?: AutoRollbackConfig;

/**
* Whether to skip the step of checking CloudWatch alarms during the deployment process
*
* @default false
nrgeil marked this conversation as resolved.
Show resolved Hide resolved
*/
readonly ignoreAlarmConfiguration?: boolean;
}

/**
Expand Down Expand Up @@ -177,7 +184,11 @@ export class LambdaDeploymentGroup extends DeploymentGroupBase implements ILambd
deploymentOption: 'WITH_TRAFFIC_CONTROL',
},
alarmConfiguration: cdk.Lazy.any({
produce: () => renderAlarmConfiguration(this.alarms, props.ignorePollAlarmsFailure, removeAlarmsFromDeploymentGroup),
produce: () => renderAlarmConfiguration(
this.alarms, props.ignorePollAlarmsFailure,
nrgeil marked this conversation as resolved.
Show resolved Hide resolved
removeAlarmsFromDeploymentGroup,
props.ignoreAlarmConfiguration,
),
}),
autoRollbackConfiguration: cdk.Lazy.any({ produce: () => renderAutoRollbackConfiguration(this.alarms, props.autoRollback) }),
});
Expand Down
12 changes: 8 additions & 4 deletions packages/aws-cdk-lib/aws-codedeploy/lib/private/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ export function arnForDeploymentConfig(name: string, resource?: IResource): stri
});
}

export function renderAlarmConfiguration(alarms: cloudwatch.IAlarm[], ignorePollAlarmFailure: boolean | undefined, removeAlarms = true):
CfnDeploymentGroup.AlarmConfigurationProperty | undefined {
export function renderAlarmConfiguration(
alarms: cloudwatch.IAlarm[],
ignorePollAlarmFailure: boolean | undefined,
removeAlarms = true,
ignoreAlarmConfiguration: boolean = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
removeAlarms = true,
ignoreAlarmConfiguration: boolean = false,
ignoreAlarmConfiguration = false,
removeAlarms = true,

I think it's better/clearer to keep the feature flag parameter last.

): CfnDeploymentGroup.AlarmConfigurationProperty | undefined {
if (removeAlarms) {
return {
alarms: alarms.length > 0 ? alarms.map(a => ({ name: a.alarmName })) : undefined,
enabled: alarms.length > 0,
enabled: !ignoreAlarmConfiguration && alarms.length > 0,
ignorePollAlarmFailure,
};
}
Expand All @@ -45,7 +49,7 @@ CfnDeploymentGroup.AlarmConfigurationProperty | undefined {
? undefined
: {
alarms: alarms.map(a => ({ name: a.alarmName })),
enabled: true,
enabled: !ignoreAlarmConfiguration,
ignorePollAlarmFailure,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ export interface ServerDeploymentGroupProps {
* @default - default AutoRollbackConfig.
*/
readonly autoRollback?: AutoRollbackConfig;

/**
* Whether to skip the step of checking CloudWatch alarms during the deployment process
*
* @default false
nrgeil marked this conversation as resolved.
Show resolved Hide resolved
*/
readonly ignoreAlarmConfiguration?: boolean;
}

/**
Expand Down Expand Up @@ -286,7 +293,11 @@ export class ServerDeploymentGroup extends DeploymentGroupBase implements IServe
ec2TagSet: this.ec2TagSet(props.ec2InstanceTags),
onPremisesTagSet: this.onPremiseTagSet(props.onPremiseInstanceTags),
alarmConfiguration: cdk.Lazy.any({
produce: () => renderAlarmConfiguration(this.alarms, props.ignorePollAlarmsFailure, removeAlarmsFromDeploymentGroup),
produce: () => renderAlarmConfiguration(
this.alarms, props.ignorePollAlarmsFailure,
nrgeil marked this conversation as resolved.
Show resolved Hide resolved
removeAlarmsFromDeploymentGroup,
props.ignoreAlarmConfiguration,
),
}),
autoRollbackConfiguration: cdk.Lazy.any({ produce: () => renderAutoRollbackConfiguration(this.alarms, props.autoRollback) }),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,4 +884,33 @@ describe('CodeDeploy ECS DeploymentGroup', () => {
));
});
});

test('can ignore alarm status when alarms are present', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Test cases should be added for each deployment group to verify that the configuration is disabled when ignoreAlarmConfiguration: true, alarms is not empty, and the @aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup feature flag is enabled (this condition).

const stack = new cdk.Stack();
new codedeploy.EcsDeploymentGroup(stack, 'MyDG', {
ignoreAlarmConfiguration: true,
alarms: [
new cloudwatch.Alarm(stack, 'BlueTGUnHealthyHosts', {
metric: new cloudwatch.Metric({
namespace: 'AWS/ApplicationELB',
metricName: 'UnHealthyHostCount',
}),
threshold: 1,
evaluationPeriods: 1,
}),
],
service: mockEcsService(stack),
blueGreenDeploymentConfig: {
blueTargetGroup: mockTargetGroup(stack, 'blue'),
greenTargetGroup: mockTargetGroup(stack, 'green'),
listener: mockListener(stack, 'prod'),
},
});

Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
AlarmConfiguration: {
Enabled: false,
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,31 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
));
});
});

test('can ignore alarm status when alarms are present', () => {
const stack = new cdk.Stack();
const application = new codedeploy.LambdaApplication(stack, 'MyApp');
const alias = mockAlias(stack);
new codedeploy.LambdaDeploymentGroup(stack, 'MyDG', {
application,
alias,
postHook: mockFunction(stack, 'PostHook'),
deploymentConfig: codedeploy.LambdaDeploymentConfig.ALL_AT_ONCE,
ignoreAlarmConfiguration: true,
alarms: [new cloudwatch.Alarm(stack, 'Failures', {
metric: alias.metricErrors(),
comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
threshold: 1,
evaluationPeriods: 1,
})],
});

Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
AlarmConfiguration: {
Enabled: false,
},
});
});
});

describe('imported with fromLambdaDeploymentGroupAttributes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,4 +540,28 @@ describe('CodeDeploy Server Deployment Group', () => {
));
});
});

test('can ignore alarm status when alarms are present', () => {
const stack = new cdk.Stack();

new codedeploy.ServerDeploymentGroup(stack, 'DeploymentGroup', {
alarms: [
new cloudwatch.Alarm(stack, 'Alarm1', {
metric: new cloudwatch.Metric({
metricName: 'Errors',
namespace: 'my.namespace',
}),
threshold: 1,
evaluationPeriods: 1,
}),
],
ignoreAlarmConfiguration: true,
});

Template.fromStack(stack).hasResourceProperties('AWS::CodeDeploy::DeploymentGroup', {
AlarmConfiguration: {
Enabled: false,
},
});
});
});
Loading