Skip to content

Commit

Permalink
feat AM-1945: modify mesh scaling rules
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOrangePuff committed Sep 30, 2024
1 parent cd8d654 commit 5bb50b9
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions packages/graphql-mesh-server/lib/fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ 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 {
/**
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
});
}
}

0 comments on commit 5bb50b9

Please sign in to comment.