Skip to content

Commit

Permalink
Merge pull request #1238 from aligent/feature/graphql-server-monitori…
Browse files Browse the repository at this point in the history
…ng-enhancements

Graphql server monitoring enhancements
  • Loading branch information
TheOrangePuff authored Nov 27, 2023
2 parents 014fa69 + 970eac7 commit 3e3a1cc
Show file tree
Hide file tree
Showing 3 changed files with 371 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/graphql-mesh-server/lib/fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
} from "./web-application-firewall";
import { CfnIPSet, CfnWebACL } from "aws-cdk-lib/aws-wafv2";
import { ScalingInterval, AdjustmentType } from "aws-cdk-lib/aws-autoscaling";
import { ApplicationLoadBalancer } from "aws-cdk-lib/aws-elasticloadbalancingv2";
import { LogGroup } from "aws-cdk-lib/aws-logs";

export interface MeshServiceProps {
/**
Expand Down Expand Up @@ -109,12 +111,19 @@ export interface MeshServiceProps {
* Defaults to true
*/
containerInsights?: boolean;
/**
* Log stream prefix
* Defaults to 'graphql-server'
*/
logStreamPrefix?: string;
}

export class MeshService extends Construct {
public readonly vpc: IVpc;
public readonly repository: ecr.Repository;
public readonly service: ecs.FargateService;
public readonly loadBalancer: ApplicationLoadBalancer;
public readonly logGroup: LogGroup;
public readonly firewall: WebApplicationFirewall;

constructor(scope: Construct, id: string, props: MeshServiceProps) {
Expand Down Expand Up @@ -205,6 +214,13 @@ export class MeshService extends Construct {
for (const [key, ssm] of Object.entries(props.secrets)) {
secrets[key] = ecs.Secret.fromSsmParameter(ssm);
}

// Configure a custom log driver and group
this.logGroup = new LogGroup(this, "graphql-server-log", {});
const logDriver = ecs.LogDrivers.awsLogs({
streamPrefix: props.logStreamPrefix || "graphql-server",
logGroup: this.logGroup,
});
// Create a load-balanced Fargate service and make it public
const fargateService =
new ecsPatterns.ApplicationLoadBalancedFargateService(this, `fargate`, {
Expand All @@ -219,6 +235,7 @@ export class MeshService extends Construct {
containerPort: 4000, // graphql mesh gateway port
secrets: secrets,
environment: environment,
logDriver: logDriver,
},
publicLoadBalancer: true, // default,
taskSubnets: {
Expand All @@ -228,6 +245,7 @@ export class MeshService extends Construct {
});

this.service = fargateService.service;
this.loadBalancer = fargateService.loadBalancer;

const blockedIpList = new CfnIPSet(this, "BlockedIpList", {
addresses: props.blockedIps || [],
Expand Down
37 changes: 36 additions & 1 deletion packages/graphql-mesh-server/lib/graphql-mesh-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ import { Repository } from "aws-cdk-lib/aws-ecr";
import { FargateService } from "aws-cdk-lib/aws-ecs";
import { CfnCacheCluster } from "aws-cdk-lib/aws-elasticache";
import * as ssm from "aws-cdk-lib/aws-ssm";
import { AWSManagedRule } from "./web-application-firewall";
import {
AWSManagedRule,
WebApplicationFirewall,
} from "./web-application-firewall";
import { CfnWebACL } from "aws-cdk-lib/aws-wafv2";
import { ScalingInterval } from "aws-cdk-lib/aws-autoscaling";
import { PerformanceMetrics } from "./metrics";
import { ApplicationLoadBalancer } from "aws-cdk-lib/aws-elasticloadbalancingv2";
import { LogGroup } from "aws-cdk-lib/aws-logs";
import { Topic } from "aws-cdk-lib/aws-sns";
import { Alarm } from "aws-cdk-lib/aws-cloudwatch";

export type MeshHostingProps = {
/**
Expand Down Expand Up @@ -114,14 +122,30 @@ export type MeshHostingProps = {
* Defaults to true
*/
containerInsights?: boolean;
/**
* Log stream prefix
* Defaults to 'graphql-server'
*/
logStreamPrefix?: string;
/**
* Optional sns topic to subscribe all alarms to
*/
snsTopic?: Topic;
/**
* Any additional custom alarms
*/
additionalAlarms?: Alarm[];
};

export class MeshHosting extends Construct {
public readonly vpc: IVpc;
public readonly repository: Repository;
public readonly service: FargateService;
public readonly loadBalancer: ApplicationLoadBalancer;
public readonly logGroup: LogGroup;
public readonly cacheCluster: CfnCacheCluster;
public readonly securityGroup: SecurityGroup;
public readonly firewall: WebApplicationFirewall;

constructor(scope: Construct, id: string, props: MeshHostingProps) {
super(scope, id);
Expand Down Expand Up @@ -153,12 +177,23 @@ export class MeshHosting extends Construct {
});

this.service = mesh.service;
this.firewall = mesh.firewall;
this.loadBalancer = mesh.loadBalancer;
this.logGroup = mesh.logGroup;
this.repository = mesh.repository;

new CodePipelineService(this, "pipeline", {
repository: this.repository,
service: this.service,
notificationArn: props.notificationArn,
});

new PerformanceMetrics(this, "cloudwatch", {
...props,
service: this.service,
loadBalancer: this.loadBalancer,
logGroup: this.logGroup,
firewall: this.firewall,
});
}
}
Loading

0 comments on commit 3e3a1cc

Please sign in to comment.