diff --git a/packages/graphql-mesh-server/lib/fargate.ts b/packages/graphql-mesh-server/lib/fargate.ts index 0fef4854..e787db12 100644 --- a/packages/graphql-mesh-server/lib/fargate.ts +++ b/packages/graphql-mesh-server/lib/fargate.ts @@ -7,7 +7,6 @@ import * as ecr from "aws-cdk-lib/aws-ecr"; import * as ecsPatterns from "aws-cdk-lib/aws-ecs-patterns"; import * as iam from "aws-cdk-lib/aws-iam"; import * as ssm from "aws-cdk-lib/aws-ssm"; -import * as auto_scaling from "aws-cdk-lib/aws-autoscaling"; import { Port, SecurityGroup, IVpc, Vpc } from "aws-cdk-lib/aws-ec2"; import { RedisService } from "./redis-construct"; import { @@ -15,6 +14,7 @@ import { Scope, WebApplicationFirewall, } from "./web-application-firewall"; +import { ScalingInterval, AdjustmentType } from "aws-cdk-lib/aws-autoscaling"; export interface MeshServiceProps { /** @@ -56,6 +56,16 @@ export interface MeshServiceProps { * SSM values to pass through to the container as secrets */ secrets?: { [key: string]: ssm.IStringParameter | ssm.IStringListParameter }; + /** + * Pass custom cpu scaling steps + * Default value: + * [ + * { upper: 30, change: -1 }, + * { lower: 50, change: +1 }, + * { lower: 85, change: +3 }, + * ] + */ + cpuScalingSteps: ScalingInterval[]; } export class MeshService extends Construct { @@ -211,15 +221,17 @@ export class MeshService extends Construct { maxCapacity: props.maxCapacity || 5, }); + const cpuScalingSteps = props.cpuScalingSteps || [ + { upper: 30, change: -1 }, + { lower: 50, change: +1 }, + { lower: 85, change: +3 }, + ]; + const cpuUtilization = fargateService.service.metricCpuUtilization(); scaling.scaleOnMetric("auto-scale-cpu", { metric: cpuUtilization, - scalingSteps: [ - { upper: 30, change: -1 }, - { lower: 50, change: +1 }, - { lower: 85, change: +3 }, - ], - adjustmentType: auto_scaling.AdjustmentType.CHANGE_IN_CAPACITY, + scalingSteps: cpuScalingSteps, + adjustmentType: AdjustmentType.CHANGE_IN_CAPACITY, }); } } diff --git a/packages/graphql-mesh-server/lib/graphql-mesh-server.ts b/packages/graphql-mesh-server/lib/graphql-mesh-server.ts index 2d95a8ed..5e01f196 100644 --- a/packages/graphql-mesh-server/lib/graphql-mesh-server.ts +++ b/packages/graphql-mesh-server/lib/graphql-mesh-server.ts @@ -7,6 +7,7 @@ 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 { ScalingInterval } from "aws-cdk-lib/aws-autoscaling"; export type MeshHostingProps = { /** @@ -56,6 +57,16 @@ export type MeshHostingProps = { * SSM values to pass through to the container as secrets */ secrets?: { [key: string]: ssm.IStringParameter | ssm.IStringListParameter }; + /** + * Pass custom cpu scaling steps + * Default value: + * [ + * { upper: 30, change: -1 }, + * { lower: 50, change: +1 }, + * { lower: 85, change: +3 }, + * ] + */ + cpuScalingSteps: ScalingInterval[]; /** * ARN of the SNS Topic to send deployment notifications to */