Skip to content

Commit

Permalink
Merge pull request #1212 from aligent/feature/custom-cpu-scaling
Browse files Browse the repository at this point in the history
feat: add custom cpu scaling to mesh
  • Loading branch information
TheOrangePuff authored Nov 16, 2023
2 parents 7cd67b3 + 7810dd6 commit 8ef5d55
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
26 changes: 19 additions & 7 deletions packages/graphql-mesh-server/lib/fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ 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 {
ManagedRule,
Scope,
WebApplicationFirewall,
} from "./web-application-firewall";
import { ScalingInterval, AdjustmentType } from "aws-cdk-lib/aws-autoscaling";

export interface MeshServiceProps {
/**
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
});
}
}
11 changes: 11 additions & 0 deletions packages/graphql-mesh-server/lib/graphql-mesh-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
/**
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 8ef5d55

Please sign in to comment.