From d6e6f9e63b204054b07bfd5f526cfda99e74591c Mon Sep 17 00:00:00 2001 From: akash1810 Date: Fri, 13 Sep 2024 15:31:17 +0100 Subject: [PATCH] docs(experimental-ec2-pattern): Update doc strings --- src/experimental/patterns/ec2-app.ts | 70 ++++++++++++++++++---------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/src/experimental/patterns/ec2-app.ts b/src/experimental/patterns/ec2-app.ts index eeebb9bf89..8f8ae48570 100644 --- a/src/experimental/patterns/ec2-app.ts +++ b/src/experimental/patterns/ec2-app.ts @@ -10,6 +10,26 @@ import type { GuEc2AppProps } from "../../patterns"; import { GuEc2App } from "../../patterns"; import { isSingletonPresentInStack } from "../../utils/singleton"; +/** + * An `Aspect` that adjusts the properties of an AutoScaling Group using an `AutoScalingRollingUpdate` update policy. + * + * It'll unset the `DesiredCapacity` of the ASG as a rolling update sets `Desired` back to the template version, + * undoing any changes that a scale-out event may have done. + * Having `DesiredCapacity` unset ensures the service remains at-capacity at all times. + * + * It'll also make the `MinInstancesInService` property dynamic via a CFN Parameter that Riff-Raff will set. + * The value depends on the current capacity of the ASG: + * - If the service is running normally, it'll be set to the `MinSize` capacity + * - If the service is partially scaled, it'll be set to the current `DesiredCapacity` + * - If the service is fully scaled, it'll be set to (at least) `MaxSize` - 1 + * + * @privateRemarks + * - Temporarily implemented as a singleton to ensure only one instance is added to a stack, + * else multiple attempts to add the same CFN Parameter will be made and fail. + * - Once out of experimental, instantiate this `Aspect` directly in {@link GuStack}. + * + * @see https://github.com/guardian/testing-asg-rolling-update + */ class HorizontallyScalingDeploymentProperties implements IAspect { public readonly stack: Stack; private static instance: HorizontallyScalingDeploymentProperties | undefined; @@ -49,16 +69,6 @@ class HorizontallyScalingDeploymentProperties implements IAspect { */ cfnAutoScalingGroup.desiredCapacity = undefined; - /* - An autoscaling group that horizontally scales should expose a CloudFormation Parameter linked to the - `MinInstancesInService` property of the rolling update policy. - - Riff-Raff will set this parameter during deployment. - The value depends on the current capacity of the ASG: - - If the service is running normally, it'll be set to the `Minimum` capacity - - If the service is partially scaled, it'll be set to the current `Desired` capacity - - If the service is fully scaled, it'll be set to (at least) `Maximum` - 1 - */ const minInstancesInService = new CfnParameter(guStack, `MinInstancesInServiceFor${autoScalingGroup.app}`, { type: "Number", default: parseInt(cfnAutoScalingGroup.minSize), @@ -76,6 +86,12 @@ class HorizontallyScalingDeploymentProperties implements IAspect { } } +/** + * An IAM Policy allowing the sending of a CloudFormation signal. + * + * @privateRemarks + * Implemented as a singleton as the resources can only be tightened at most to the CloudFormation stack. + */ class AsgRollingUpdatePolicy extends Policy { private static instance: AsgRollingUpdatePolicy | undefined; @@ -118,32 +134,37 @@ export interface GuEc2AppExperimentalProps extends Omit