Skip to content

Commit

Permalink
Merge pull request #2255 from guardian/add-asg-group-metrics-by-default
Browse files Browse the repository at this point in the history
feat: Add useful ASG group metrics (`TOTAL_INSTANCES`, etc) by default
  • Loading branch information
rtyley committed May 14, 2024
2 parents 19779d7 + c8400c9 commit 176c326
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/nice-cups-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@guardian/cdk": patch
---

Add useful ASG group metrics (TOTAL_INSTANCES, etc) by default
4 changes: 3 additions & 1 deletion src/constructs/autoscaling/asg.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Tags, Token } from "aws-cdk-lib";
import { AutoScalingGroup } from "aws-cdk-lib/aws-autoscaling";
import { AutoScalingGroup, GroupMetric, GroupMetrics } from "aws-cdk-lib/aws-autoscaling";
import type { AutoScalingGroupProps, CfnAutoScalingGroup } from "aws-cdk-lib/aws-autoscaling";
import { LaunchTemplate, OperatingSystemType, UserData } from "aws-cdk-lib/aws-ec2";
import type { InstanceType, ISecurityGroup, MachineImageConfig } from "aws-cdk-lib/aws-ec2";
Expand Down Expand Up @@ -85,6 +85,7 @@ export class GuAutoScalingGroup extends GuAppAwareConstruct(AutoScalingGroup) {
imageId = new GuAmiParameter(scope, { app }),
imageRecipe,
instanceType,
groupMetrics = [new GroupMetrics(GroupMetric.TOTAL_INSTANCES, GroupMetric.IN_SERVICE_INSTANCES)],
minimumInstances,
maximumInstances,
role = new GuInstanceRole(scope, { app }),
Expand Down Expand Up @@ -139,6 +140,7 @@ export class GuAutoScalingGroup extends GuAppAwareConstruct(AutoScalingGroup) {
launchTemplate,
maxCapacity: maximumInstances ?? minimumInstances * 2,
minCapacity: minimumInstances,
groupMetrics: groupMetrics,

// Omit userData, instanceType, blockDevices & role from asgProps
// As this are specified by the LaunchTemplate and must not be duplicated
Expand Down
18 changes: 18 additions & 0 deletions src/patterns/ec2-app/__snapshots__/base.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ exports[`the GuEC2App pattern can produce a restricted EC2 app locked to specifi
},
},
"MaxSize": "2",
"MetricsCollection": [
{
"Granularity": "1Minute",
"Metrics": [
"GroupTotalInstances",
"GroupInServiceInstances",
],
},
],
"MinSize": "1",
"Tags": [
{
Expand Down Expand Up @@ -1095,6 +1104,15 @@ exports[`the GuEC2App pattern should produce a functional EC2 app with minimal a
},
},
"MaxSize": "2",
"MetricsCollection": [
{
"Granularity": "1Minute",
"Metrics": [
"GroupTotalInstances",
"GroupInServiceInstances",
],
},
],
"MinSize": "1",
"Tags": [
{
Expand Down

0 comments on commit 176c326

Please sign in to comment.