Skip to content

Commit

Permalink
CDK - migrate scaling policies from cloudformation (#8659)
Browse files Browse the repository at this point in the history
Co-authored-by: DanielCliftonGuardian <[email protected]>
  • Loading branch information
cemms1 and DanielCliftonGuardian authored Aug 23, 2023
1 parent 428a141 commit 4b3bbe1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
24 changes: 23 additions & 1 deletion dotcom-rendering/cdk/lib/dotcom-rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import {
import { GuClassicLoadBalancer } from '@guardian/cdk/lib/constructs/loadbalancing';
import type { App } from 'aws-cdk-lib';
import { CfnOutput, Duration } from 'aws-cdk-lib';
import { HealthCheck } from 'aws-cdk-lib/aws-autoscaling';
import {
AdjustmentType,
CfnScalingPolicy,
HealthCheck,
} from 'aws-cdk-lib/aws-autoscaling';
import { InstanceType, Peer } from 'aws-cdk-lib/aws-ec2';
import { LoadBalancingProtocol } from 'aws-cdk-lib/aws-elasticloadbalancing';
import { CfnInclude } from 'aws-cdk-lib/cloudformation-include';
Expand Down Expand Up @@ -220,6 +224,22 @@ export class DotcomRendering extends GuStack {

asg.attachToClassicLB(loadBalancer);

/** TODO - migrate these simple scaling policies
* @see https://github.com/guardian/dotcom-rendering/issues/8345#issuecomment-1647502598
*/
const scaleUpPolicy = new CfnScalingPolicy(this, 'ScaleUpPolicy', {
adjustmentType: AdjustmentType.PERCENT_CHANGE_IN_CAPACITY,
autoScalingGroupName: asg.autoScalingGroupName,
cooldown: '600',
scalingAdjustment: 100,
});
const scaleDownPolicy = new CfnScalingPolicy(this, 'ScaleDownPolicy', {
adjustmentType: AdjustmentType.CHANGE_IN_CAPACITY,
autoScalingGroupName: asg.autoScalingGroupName,
cooldown: '120',
scalingAdjustment: -1,
});

const yamlTemplateFilePath = join(
__dirname,
'../..',
Expand All @@ -232,6 +252,8 @@ export class DotcomRendering extends GuStack {
AutoscalingGroup: asg.autoScalingGroupName,
InternalLoadBalancer: loadBalancer.loadBalancerName,
InstanceRole: instanceRole.roleName,
ScaleUpPolicy: scaleUpPolicy.ref,
ScaleDownPolicy: scaleDownPolicy.ref,
},
});

Expand Down
22 changes: 6 additions & 16 deletions dotcom-rendering/cloudformation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ Parameters:
InstanceRole:
Description: Name of instance role
Type: String
ScaleDownPolicy:
Description: Ref of scale down policy
Type: AWS::AutoScaling::ScalingPolicy
ScaleUpPolicy:
Description: Ref of scale up policy
Type: AWS::AutoScaling::ScalingPolicy
# ! These params are not used but should be kept until the migration is finished
ELKStream:
Description: name of the kinesis stream to use to send logs to the central ELK stack
Expand Down Expand Up @@ -78,22 +84,6 @@ Resources:
Roles:
- Ref: InstanceRole

ScaleDownPolicy:
Type: AWS::AutoScaling::ScalingPolicy
Properties:
AdjustmentType: ChangeInCapacity
AutoScalingGroupName: !Ref AutoscalingGroup
Cooldown: '120'
ScalingAdjustment: '-1'

ScaleUpPolicy:
Type: AWS::AutoScaling::ScalingPolicy
Properties:
AdjustmentType: PercentChangeInCapacity
AutoScalingGroupName: !Ref AutoscalingGroup
Cooldown: '600'
ScalingAdjustment: '100'

LatencyScalingAlarm:
Condition: HasLatencyScalingAlarm
Properties:
Expand Down

0 comments on commit 4b3bbe1

Please sign in to comment.