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): Added support for fargate service #944

Open
wants to merge 3 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
150 changes: 150 additions & 0 deletions API.md

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

10 changes: 10 additions & 0 deletions src/aspect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { IAspect } from 'aws-cdk-lib';
import * as apigw from 'aws-cdk-lib/aws-apigateway';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as ecs_patterns from 'aws-cdk-lib/aws-ecs-patterns';
import * as elasticLoadBalancing from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as rds from 'aws-cdk-lib/aws-rds';
import * as stepfunctions from 'aws-cdk-lib/aws-stepfunctions';
Expand Down Expand Up @@ -99,9 +101,17 @@ export class WatchfulAspect implements IAspect {
this.watchful.watchFargateEcs(node.node.path, node.service, node.targetGroup);
}

if (watchFargateEcs && node instanceof ecs.FargateService) {
this.watchful.watchFargateService(node.node.path, node);
}

if (watchEc2Ecs && node instanceof ecs_patterns.ApplicationLoadBalancedEc2Service) {
this.watchful.watchEc2Ecs(node.node.path, node.service, node.targetGroup);
}

if (watchEc2Ecs && node instanceof elasticLoadBalancing.ApplicationTargetGroup) {
this.watchful.watchApplicationTargetGroup(node.node.path, node);
}
}
}

Expand Down
92 changes: 92 additions & 0 deletions src/ecs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Names } from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { ApplicationTargetGroup } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import { Construct } from 'constructs';
import { IWatchful } from '../api';
import { linkForEcsService, WatchService } from './service';
import { WatchTargetGroup } from './target-group';

export * from './target-group';
export * from './service';


export interface WatchEcsServiceOptions {
/**
* Threshold for the Cpu Maximum utilization
*
* @default 80
*/
readonly cpuMaximumThresholdPercent?: number;

/**
* Threshold for the Memory Maximum utilization.
*
* @default - 0.
*/
readonly memoryMaximumThresholdPercent?: number;

/**
* Threshold for the Target Response Time.
*
* @default - 0.
*/
readonly targetResponseTimeThreshold?: number;

/**
* Threshold for the Number of Requests.
*
* @default - 0.
*/
readonly requestsThreshold?: number;

/**
* Threshold for the Number of Request Errors.
*
* @default - 0.
*/
readonly requestsErrorRateThreshold?: number;
}

export interface WatchEcsServiceProps extends WatchEcsServiceOptions {
readonly title: string;
readonly watchful: IWatchful;
readonly fargateService?: ecs.FargateService;
readonly ec2Service?: ecs.Ec2Service;
readonly targetGroup: ApplicationTargetGroup;
}

export class WatchEcsService extends Construct {

private readonly watchful: IWatchful;
private readonly ecsService: ecs.BaseService;

constructor(scope: Construct, id: string, props: WatchEcsServiceProps) {
super(scope, id);

this.watchful = props.watchful;

if (!props.ec2Service || !props.fargateService) {
throw new Error('No service provided to monitor.');
};

this.ecsService = props.ec2Service ?? props.fargateService;

this.watchful.addSection(props.title, {
links: [
{ title: 'ECS Service', url: linkForEcsService(this.ecsService) },
],
});

new WatchService(this, Names.uniqueId(this.ecsService), {
...props,
service: this.ecsService,
skipLinkSection: true,
});

new WatchTargetGroup(this, Names.uniqueId(props.targetGroup), {
...props,
skipLinkSection: true,
});
}

}
Loading