Skip to content

Commit

Permalink
feat(ecs): add support for enabling container insights (#5601)
Browse files Browse the repository at this point in the history
* feat(ecs): Add boolean for container insights

* Adding some tests for containerInsights

Co-authored-by: Yenlin Chen <[email protected]>
Co-authored-by: Piradeep Kandasamy <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Feb 5, 2020
1 parent 6456a7c commit 6236634
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-ecs/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export interface ClusterProps {
* @default - no EC2 capacity will be added, you can use `addCapacity` to add capacity later.
*/
readonly capacity?: AddCapacityOptions;

/**
* If true CloudWatch Container Insights will be enabled for the cluster
*
* @default - Container Insights will be disabled for this cluser.
*/
readonly containerInsights?: boolean;
}

/**
Expand Down Expand Up @@ -96,8 +103,12 @@ export class Cluster extends Resource implements ICluster {
physicalName: props.clusterName,
});

const containerInsights = props.containerInsights !== undefined ? props.containerInsights : false;
const clusterSettings = containerInsights ? [{name: "containerInsights", value: "enabled"}] : undefined;

const cluster = new CfnCluster(this, 'Resource', {
clusterName: this.physicalName,
clusterSettings,
});

this.clusterArn = this.getResourceArnAttribute(cluster.attrArn, {
Expand Down
44 changes: 43 additions & 1 deletion packages/@aws-cdk/aws-ecs/test/test.ecs-cluster.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { countResources, expect, haveResource } from '@aws-cdk/assert';
import { countResources, expect, haveResource, ResourcePart } from '@aws-cdk/assert';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cloudmap from '@aws-cdk/aws-servicediscovery';
import * as cdk from '@aws-cdk/core';
Expand Down Expand Up @@ -1313,4 +1313,46 @@ export = {
// THEN
test.done();
},

"enable container insights"(test: Test) {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'test');

new ecs.Cluster(stack, 'EcsCluster', { containerInsights: true });

// THEN
expect(stack).to(haveResource("AWS::ECS::Cluster", {
ClusterSettings: [
{
Name: "containerInsights",
Value: "enabled"
}
]
}, ResourcePart.Properties));

test.done();
},

"default container insights undefined"(test: Test) {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'test');

new ecs.Cluster(stack, 'EcsCluster');

// THEN
const assembly = app.synth();
const stackAssembly = assembly.getStackByName(stack.stackName);
const template = stackAssembly.template;

test.equal(
template.Resources.EcsCluster97242B84.Properties === undefined ||
template.Resources.EcsCluster97242B84.Properties.ClusterSettings === undefined,
true,
"ClusterSettings should not be defined"
);

test.done();
},
};

0 comments on commit 6236634

Please sign in to comment.