-
Notifications
You must be signed in to change notification settings - Fork 4k
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(aws-codedeploy): add support for setting CloudWatch alarms on a server Deployment Group #926
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import autoscaling = require("@aws-cdk/aws-autoscaling"); | ||
import cloudwatch = require("@aws-cdk/aws-cloudwatch"); | ||
import codedeploylb = require("@aws-cdk/aws-codedeploy-api"); | ||
import ec2 = require("@aws-cdk/aws-ec2"); | ||
import iam = require('@aws-cdk/aws-iam'); | ||
|
@@ -167,6 +168,8 @@ export interface ServerDeploymentGroupProps { | |
/** | ||
* The auto-scaling groups belonging to this Deployment Group. | ||
* | ||
* Auto-scaling groups can also be added after the Deployment Group is created using the {@link #addAutoScalingGroup} method. | ||
* | ||
* @default [] | ||
*/ | ||
autoScalingGroups?: autoscaling.AutoScalingGroup[]; | ||
|
@@ -189,7 +192,7 @@ export interface ServerDeploymentGroupProps { | |
*/ | ||
loadBalancer?: codedeploylb.ILoadBalancer; | ||
|
||
/* | ||
/** | ||
* All EC2 instances matching the given set of tags when a deployment occurs will be added to this Deployment Group. | ||
* | ||
* @default no additional EC2 instances will be added to the Deployment Group | ||
|
@@ -202,6 +205,25 @@ export interface ServerDeploymentGroupProps { | |
* @default no additional on-premise instances will be added to the Deployment Group | ||
*/ | ||
onPremiseInstanceTags?: InstanceTagSet; | ||
|
||
/** | ||
* The CloudWatch alarms associated with this Deployment Group. | ||
* CodeDeploy will stop (and optionally roll back) | ||
* a deployment if during it any of the alarms trigger. | ||
* | ||
* Alarms can also be added after the Deployment Group is created using the {@link #addAlarm} method. | ||
* | ||
* @default [] | ||
* @see https://docs.aws.amazon.com/codedeploy/latest/userguide/monitoring-create-alarms.html | ||
*/ | ||
alarms?: cloudwatch.Alarm[]; | ||
|
||
/** | ||
* Whether to continue a deployment even if fetching the alarm status from CloudWatch failed. | ||
* | ||
* @default false | ||
*/ | ||
ignorePollAlarmsFailure?: boolean; | ||
} | ||
|
||
/** | ||
|
@@ -216,6 +238,7 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupRef { | |
private readonly _autoScalingGroups: autoscaling.AutoScalingGroup[]; | ||
private readonly installAgent: boolean; | ||
private readonly codeDeployBucket: s3.BucketRef; | ||
private readonly alarms: cloudwatch.Alarm[]; | ||
|
||
constructor(parent: cdk.Construct, id: string, props: ServerDeploymentGroupProps = {}) { | ||
super(parent, id, props.deploymentConfig); | ||
|
@@ -237,6 +260,8 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupRef { | |
this.addCodeDeployAgentInstallUserData(asg); | ||
} | ||
|
||
this.alarms = props.alarms || []; | ||
|
||
const resource = new cloudformation.DeploymentGroupResource(this, 'Resource', { | ||
applicationName: this.application.applicationName, | ||
deploymentGroupName: props.deploymentGroupName, | ||
|
@@ -255,18 +280,33 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupRef { | |
}, | ||
ec2TagSet: this.ec2TagSet(props.ec2InstanceTags), | ||
onPremisesTagSet: this.onPremiseTagSet(props.onPremiseInstanceTags), | ||
alarmConfiguration: new cdk.Token(() => this.renderAlarmConfiguration(props.ignorePollAlarmsFailure)), | ||
}); | ||
|
||
this.deploymentGroupName = resource.deploymentGroupName; | ||
this.deploymentGroupArn = deploymentGroupName2Arn(this.application.applicationName, | ||
this.deploymentGroupName); | ||
} | ||
|
||
/** | ||
* Adds an additional auto-scaling group to this Deployment Group. | ||
* | ||
* @param asg the auto-scaling group to add to this Deployment Group | ||
*/ | ||
public addAutoScalingGroup(asg: autoscaling.AutoScalingGroup): void { | ||
this._autoScalingGroups.push(asg); | ||
this.addCodeDeployAgentInstallUserData(asg); | ||
} | ||
|
||
/** | ||
* Associates an additional alarm with this Deployment Group. | ||
* | ||
* @param alarm the alarm to associate with this Deployment Group | ||
*/ | ||
public addAlarm(alarm: cloudwatch.Alarm): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
this.alarms.push(alarm); | ||
} | ||
|
||
public get autoScalingGroups(): autoscaling.AutoScalingGroup[] | undefined { | ||
return this._autoScalingGroups.slice(); | ||
} | ||
|
@@ -404,6 +444,17 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupRef { | |
} | ||
return tagsInGroup; | ||
} | ||
|
||
private renderAlarmConfiguration(ignorePollAlarmFailure?: boolean): | ||
cloudformation.DeploymentGroupResource.AlarmConfigurationProperty | undefined { | ||
return this.alarms.length === 0 | ||
? undefined | ||
: { | ||
alarms: this.alarms.map(a => ({ name: a.alarmName })), | ||
enabled: true, | ||
ignorePollAlarmFailure, | ||
}; | ||
} | ||
} | ||
|
||
function deploymentGroupName2Arn(applicationName: string, deploymentGroupName: string): string { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add details (maybe copy & paste from the official docs) why someone would want to associate alarms with a deployment group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.