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 AM-1945: modify mesh scaling rules #1400

Merged
merged 1 commit into from
Oct 1, 2024
Merged
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
48 changes: 44 additions & 4 deletions packages/graphql-mesh-server/lib/fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ import {
WebApplicationFirewall,
} from "./web-application-firewall";
import { CfnIPSet, CfnWebACL } from "aws-cdk-lib/aws-wafv2";
import { ScalingInterval, AdjustmentType } from "aws-cdk-lib/aws-autoscaling";
import {
ScalingInterval,
AdjustmentType,
BasicStepScalingPolicyProps,
} from "aws-cdk-lib/aws-autoscaling";
import { ApplicationLoadBalancer } from "aws-cdk-lib/aws-elasticloadbalancingv2";
import { LogGroup } from "aws-cdk-lib/aws-logs";
import path = require("path");
import { MetricOptions } from "aws-cdk-lib/aws-cloudwatch";

export interface MeshServiceProps {
/**
* VPC to attach Redis instance to
* VPC to attach Fargate instance to
*/
vpc?: IVpc;
/**
Expand Down Expand Up @@ -131,7 +136,7 @@ export interface MeshServiceProps {
allowedIps?: string[];
/**
* Pass custom cpu scaling steps
* Default value:
* @default
* [
* { upper: 30, change: -1 },
* { lower: 50, change: +1 },
Expand Down Expand Up @@ -202,6 +207,31 @@ export interface MeshServiceProps {
* Optional manual overrides for nginx sidecar container
*/
nginxConfigOverride?: Partial<ecs.ContainerDefinitionOptions>;

/**
* Override cpu scaling options
*
* @default
* {
* period: Duration.minutes(1),
* statistic: "max",
* }
*/
cpuScalingOptions?: Partial<MetricOptions>;

/**
* Override cpu step scaling options
*
* @default
* {
* metric: cpuUtilization, // use cpuScalingOptions to modify
* scalingSteps: cpuScalingSteps, // use cpuScalingSteps to modify
* adjustmentType: AdjustmentType.CHANGE_IN_CAPACITY,
* evaluationPeriods: 3,
* datapointsToAlarm: 2,
* }
*/
cpuStepScalingOptions?: Partial<BasicStepScalingPolicyProps>;
}

export class MeshService extends Construct {
Expand Down Expand Up @@ -613,11 +643,21 @@ export class MeshService extends Construct {
{ lower: 85, change: +3 },
];

const cpuUtilization = this.service.metricCpuUtilization();
// These default options are based on testing
/// however they can be overwritten if required
const cpuUtilization = this.service.metricCpuUtilization({
period: Duration.minutes(1),
statistic: "max",
...props.cpuScalingOptions,
});

scaling.scaleOnMetric("auto-scale-cpu", {
metric: cpuUtilization,
scalingSteps: cpuScalingSteps,
adjustmentType: AdjustmentType.CHANGE_IN_CAPACITY,
evaluationPeriods: 3,
datapointsToAlarm: 2,
...props.cpuStepScalingOptions,
});
}
}
Loading