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(ecs): integrate AWS Cloud Map (service discovery) #2065

Merged
merged 21 commits into from
Apr 3, 2019
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
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-ecs/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ export class Cluster extends cdk.Construct implements ICluster {
}

/**
* Add an AWS Cloud Map Private DNS namespace for this cluster.
* Add an AWS Cloud Map DNS namespace for this cluster.
* NOTE: HttpNamespaces are not supported, as ECS always requires a DNSConfig when registering an instance to a Cloud
* Map service.
*/
public setDefaultCloudMapNamespace(options: NamespaceOptions): cloudmap.INamespace {
public addDefaultCloudMapNamespace(options: NamespaceOptions): cloudmap.INamespace {
SoManyHs marked this conversation as resolved.
Show resolved Hide resolved

const namespaceType = options.type !== undefined
? options.type
Expand Down
81 changes: 41 additions & 40 deletions packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,47 @@ export class Ec2Service extends BaseService implements elb.ILoadBalancerTarget {
});
}

/**
* Return the given named metric for this Service
*/
public metric(metricName: string, props?: cloudwatch.MetricCustomization): cloudwatch.Metric {
return new cloudwatch.Metric({
namespace: 'AWS/ECS',
metricName,
dimensions: { ClusterName: this.clusterName, ServiceName: this.serviceName },
...props
});
}

/**
* Metric for cluster Memory utilization
*
* @default average over 5 minutes
*/
public metricMemoryUtilization(props?: cloudwatch.MetricCustomization): cloudwatch.Metric {
return this.metric('MemoryUtilization', props );
}

/**
* Metric for cluster CPU utilization
*
* @default average over 5 minutes
*/
public metricCpuUtilization(props?: cloudwatch.MetricCustomization): cloudwatch.Metric {
return this.metric('CPUUtilization', props);
}

/**
* Validate this Ec2Service
*/
protected validate(): string[] {
const ret = super.validate();
if (!this.cluster.hasEc2Capacity) {
ret.push('Cluster for this service needs Ec2 capacity. Call addXxxCapacity() on the cluster.');
}
return ret;
}

/**
* Enable CloudMap service discovery for the service
*/
Expand Down Expand Up @@ -255,46 +296,6 @@ export class Ec2Service extends BaseService implements elb.ILoadBalancerTarget {
return cloudmapService;
}

/**
* Return the given named metric for this Service
*/
public metric(metricName: string, props?: cloudwatch.MetricCustomization): cloudwatch.Metric {
return new cloudwatch.Metric({
namespace: 'AWS/ECS',
metricName,
dimensions: { ClusterName: this.clusterName, ServiceName: this.serviceName },
...props
});
}

/**
* Metric for cluster Memory utilization
*
* @default average over 5 minutes
*/
public metricMemoryUtilization(props?: cloudwatch.MetricCustomization): cloudwatch.Metric {
return this.metric('MemoryUtilization', props );
}

/**
* Metric for cluster CPU utilization
*
* @default average over 5 minutes
*/
public metricCpuUtilization(props?: cloudwatch.MetricCustomization): cloudwatch.Metric {
return this.metric('CPUUtilization', props);
}

/**
* Validate this Ec2Service
*/
protected validate(): string[] {
const ret = super.validate();
if (!this.cluster.hasEc2Capacity) {
ret.push('Cluster for this service needs Ec2 capacity. Call addXxxCapacity() on the cluster.');
}
return ret;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-awsvpc-nw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cluster.addCapacity('DefaultAutoScalingGroup', {

// Add Private DNS Namespace
const domainName = "scorekeep.com";
cluster.setDefaultCloudMapNamespace({
cluster.addDefaultCloudMapNamespace({
name: domainName,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-bridge-nw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cluster.addCapacity('DefaultAutoScalingGroup', {

// Add Private DNS Namespace
const domainName = "scorekeep.com";
cluster.setDefaultCloudMapNamespace({
cluster.addDefaultCloudMapNamespace({
name: domainName,
});

Expand Down
12 changes: 6 additions & 6 deletions packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ export = {
});
container.addPortMappings({ containerPort: 8000 });

cluster.setDefaultCloudMapNamespace({ name: 'foo.com' });
cluster.addDefaultCloudMapNamespace({ name: 'foo.com' });

// THEN
test.throws(() => {
Expand Down Expand Up @@ -604,7 +604,7 @@ export = {
container.addPortMappings({ containerPort: 8000 });

// WHEN
cluster.setDefaultCloudMapNamespace({
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
});
Expand Down Expand Up @@ -681,7 +681,7 @@ export = {
container.addPortMappings({ containerPort: 8000 });

// WHEN
cluster.setDefaultCloudMapNamespace({
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
});
Expand Down Expand Up @@ -756,7 +756,7 @@ export = {
});
container.addPortMappings({ containerPort: 8000 });

cluster.setDefaultCloudMapNamespace({
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
});

Expand Down Expand Up @@ -792,7 +792,7 @@ export = {
container.addPortMappings({ containerPort: 8000 });

// WHEN
cluster.setDefaultCloudMapNamespace({
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
});
Expand Down Expand Up @@ -867,7 +867,7 @@ export = {
container.addPortMappings({ containerPort: 8000 });

// WHEN
cluster.setDefaultCloudMapNamespace({
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export = {
container.addPortMappings({ containerPort: 8000 });

// WHEN
cluster.setDefaultCloudMapNamespace({
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
});
Expand Down Expand Up @@ -339,7 +339,7 @@ export = {
container.addPortMappings({ containerPort: 8000 });

// WHEN
cluster.setDefaultCloudMapNamespace({
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
});
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/test/test.ecs-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export = {
});

// WHEN
cluster.setDefaultCloudMapNamespace({
cluster.addDefaultCloudMapNamespace({
name: "foo.com"
});

Expand Down