Skip to content

Commit 28a580f

Browse files
ECS Scaling at 20% CPU usage.
Update ECS instance resources
1 parent c10b55b commit 28a580f

5 files changed

Lines changed: 84 additions & 19 deletions

File tree

dotcom-rendering/cdk/bin/cdk.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App } from 'aws-cdk-lib';
1+
import { App, Duration } from 'aws-cdk-lib';
22
import { InstanceClass, InstanceSize, InstanceType } from 'aws-cdk-lib/aws-ec2';
33
import type { RenderingCDKStackProps } from '../lib/renderingStack';
44
import { RenderingCDKStack } from '../lib/renderingStack';
@@ -115,6 +115,15 @@ export const TagPageRenderingPropsCODE: RenderingCDKStackProps = {
115115
imageIdentifier: getImageIdentifier(),
116116
taskCpu: 1024,
117117
taskMemoryLimitMiB: 2048,
118+
scaling: {
119+
minimumTasks: 1,
120+
maximumTasks: 9,
121+
cpuScaling: {
122+
targetValue: 20,
123+
scaleInCooldown: Duration.seconds(60),
124+
scaleOutCooldown: Duration.seconds(60),
125+
},
126+
},
118127
},
119128
};
120129

@@ -158,6 +167,15 @@ export const TagPageRenderingPropsPROD: RenderingCDKStackProps = {
158167
imageIdentifier: getImageIdentifier(),
159168
taskCpu: 2048,
160169
taskMemoryLimitMiB: 4096,
170+
scaling: {
171+
minimumTasks: 9,
172+
maximumTasks: 90,
173+
cpuScaling: {
174+
targetValue: 20,
175+
scaleInCooldown: Duration.seconds(60),
176+
scaleOutCooldown: Duration.seconds(60),
177+
},
178+
},
161179
},
162180
};
163181

dotcom-rendering/cdk/lib/__snapshots__/renderingStack.test.ts.snap

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,7 @@ exports[`The RenderingCDKStack matches the snapshot for Tag Page Rendering CODE
21092109
"EcsTaskDefinitionTaskRoleB7B6D8DD",
21102110
],
21112111
"Properties": {
2112-
"MaxCapacity": 2,
2112+
"MaxCapacity": 9,
21132113
"MinCapacity": 1,
21142114
"ResourceId": {
21152115
"Fn::Join": [
@@ -3667,6 +3667,24 @@ systemctl start tag-page-rendering",
36673667
},
36683668
"Type": "AWS::IAM::InstanceProfile",
36693669
},
3670+
"tagpagerenderingCpuScaling1742C101": {
3671+
"Properties": {
3672+
"PolicyName": "TagPageRenderingCODEtagpagerenderingCpuScalingAFEBC723",
3673+
"PolicyType": "TargetTrackingScaling",
3674+
"ScalingTargetId": {
3675+
"Ref": "EcsServiceTaskCountTarget02FCCE22",
3676+
},
3677+
"TargetTrackingScalingPolicyConfiguration": {
3678+
"PredefinedMetricSpecification": {
3679+
"PredefinedMetricType": "ECSServiceAverageCPUUtilizationHighResolution",
3680+
},
3681+
"ScaleInCooldown": 60,
3682+
"ScaleOutCooldown": 60,
3683+
"TargetValue": 20,
3684+
},
3685+
},
3686+
"Type": "AWS::ApplicationAutoScaling::ScalingPolicy",
3687+
},
36703688
"tagpagerenderingEcsClusterE7696595": {
36713689
"Properties": {
36723690
"ClusterSettings": [
@@ -4260,8 +4278,8 @@ exports[`The RenderingCDKStack matches the snapshot for Tag Page Rendering PROD
42604278
"EcsTaskDefinitionTaskRoleB7B6D8DD",
42614279
],
42624280
"Properties": {
4263-
"MaxCapacity": 2,
4264-
"MinCapacity": 1,
4281+
"MaxCapacity": 90,
4282+
"MinCapacity": 9,
42654283
"ResourceId": {
42664284
"Fn::Join": [
42674285
"",
@@ -6261,6 +6279,24 @@ systemctl start tag-page-rendering",
62616279
},
62626280
"Type": "AWS::IAM::InstanceProfile",
62636281
},
6282+
"tagpagerenderingCpuScaling1742C101": {
6283+
"Properties": {
6284+
"PolicyName": "TagPageRenderingPRODtagpagerenderingCpuScaling4582D272",
6285+
"PolicyType": "TargetTrackingScaling",
6286+
"ScalingTargetId": {
6287+
"Ref": "EcsServiceTaskCountTarget02FCCE22",
6288+
},
6289+
"TargetTrackingScalingPolicyConfiguration": {
6290+
"PredefinedMetricSpecification": {
6291+
"PredefinedMetricType": "ECSServiceAverageCPUUtilizationHighResolution",
6292+
},
6293+
"ScaleInCooldown": 60,
6294+
"ScaleOutCooldown": 60,
6295+
"TargetValue": 20,
6296+
},
6297+
},
6298+
"Type": "AWS::ApplicationAutoScaling::ScalingPolicy",
6299+
},
62646300
"tagpagerenderingEcsClusterE7696595": {
62656301
"Properties": {
62666302
"ClusterSettings": [

dotcom-rendering/cdk/lib/renderingStack.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@guardian/cdk/lib/constructs/core';
99
import { GuCname } from '@guardian/cdk/lib/constructs/dns/dns-records';
1010
import { GuAllowPolicy } from '@guardian/cdk/lib/constructs/iam';
11+
import type { GuLoadBalancedAppExperimentalProps } from '@guardian/cdk/lib/experimental/patterns/gu-load-balanced-app';
1112
import { GuLoadBalancedAppExperimental } from '@guardian/cdk/lib/experimental/patterns/gu-load-balanced-app';
1213
import type { GuAsgCapacity } from '@guardian/cdk/lib/types';
1314
import { aws_cloudwatch, type App as CDKApp, Duration } from 'aws-cdk-lib';
@@ -67,6 +68,10 @@ export interface RenderingCDKStackProps extends Omit<GuStackProps, 'stack'> {
6768
* Memory in MB for ECS task
6869
*/
6970
taskMemoryLimitMiB: number;
71+
72+
scaling: NonNullable<
73+
GuLoadBalancedAppExperimentalProps['ecsProps']
74+
>['scaling'];
7075
};
7176
}
7277

@@ -218,6 +223,8 @@ export class RenderingCDKStack extends CDKStack {
218223
});
219224

220225
const { stack: guStack, region, account } = this;
226+
const { guApp, stage, instanceType, scaling, domainName, ecsProps } =
227+
props;
221228

222229
const artifactsBucket =
223230
GuDistributionBucketParameter.getInstance(this).valueAsString;
@@ -296,10 +303,7 @@ export class RenderingCDKStack extends CDKStack {
296303

297304
memoryLimitMiB: ecsProps.taskMemoryLimitMiB,
298305
cpu: ecsProps.taskCpu,
299-
scaling: {
300-
minimumTasks: 1,
301-
maximumTasks: 2,
302-
},
306+
scaling: ecsProps.scaling,
303307
},
304308

305309
// Route all traffic to EC2
@@ -312,7 +316,6 @@ export class RenderingCDKStack extends CDKStack {
312316

313317
if (app.ecsService) {
314318
const { taskDefinition } = app.ecsService;
315-
316319
const ecsEnvVars: Record<string, string> = {
317320
// Custom environment variables needed by the application
318321
NODE_ENV: 'production',

pnpm-lock.yaml

Lines changed: 17 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ blockExoticSubdeps: true
1212
catalog:
1313
'@aws-sdk/client-s3': 3.995.0
1414
'@aws-sdk/client-ssm': 3.995.0
15-
'@guardian/cdk': 64.6.0
15+
'@guardian/cdk': 64.7.0
1616
'@guardian/eslint-config': 14.0.1
1717
'@guardian/tsconfig': 1.0.1
1818
'@rollup/plugin-commonjs': 29.0.0

0 commit comments

Comments
 (0)