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: add custom cpu scaling to mesh #1212

Merged
merged 2 commits into from
Nov 16, 2023
Merged
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
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
Loading