Skip to content

Commit

Permalink
feat(asg): Collect all ASG level metrics
Browse files Browse the repository at this point in the history
Collect all ASG level metrics as standard.
These metrics should come at no extra cost.

See https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-metrics.html.

To collect a subset instead, use the escape hatch mechanism:

```ts
declare const asg: AutoScalingGroup;

const cfnAsg = asg.node.defaultChild as CfnAutoScalingGroup;

cfnAsg.metricsCollection = [
  {
    granularity: "1Minute",
    metrics: [
      // A subset of metrics
    ],
  },
];
```
  • Loading branch information
akash1810 committed Sep 12, 2024
1 parent a47d5f1 commit 43dc653
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
27 changes: 27 additions & 0 deletions .changeset/rare-geese-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
"@guardian/cdk": minor
---

feat(asg) Collect all ASG level metrics

This change should have no cost impact:

> Group metrics are available at one-minute granularity at no additional charge, but you must enable them.
> https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-metrics.html.
If it does, or if you only want a subset, the escape hatch mechanism can be used:

```ts
declare const asg: AutoScalingGroup;

const cfnAsg = asg.node.defaultChild as CfnAutoScalingGroup;

cfnAsg.metricsCollection = [
{
granularity: "1Minute",
metrics: [
// A subset of metrics
],
},
];
```
4 changes: 2 additions & 2 deletions src/constructs/autoscaling/asg.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Duration } from "aws-cdk-lib";
import { Tags, Token } from "aws-cdk-lib";
import { AutoScalingGroup, GroupMetric, GroupMetrics } from "aws-cdk-lib/aws-autoscaling";
import { AutoScalingGroup, GroupMetrics } from "aws-cdk-lib/aws-autoscaling";
import type { AutoScalingGroupProps, CfnAutoScalingGroup } from "aws-cdk-lib/aws-autoscaling";
import { LaunchTemplate, OperatingSystemType } from "aws-cdk-lib/aws-ec2";
import type { InstanceType, ISecurityGroup, MachineImageConfig, UserData } from "aws-cdk-lib/aws-ec2";
Expand Down Expand Up @@ -88,7 +88,7 @@ export class GuAutoScalingGroup extends GuAppAwareConstruct(AutoScalingGroup) {
imageId = new GuAmiParameter(scope, { app }),
imageRecipe,
instanceType,
groupMetrics = [new GroupMetrics(GroupMetric.TOTAL_INSTANCES, GroupMetric.IN_SERVICE_INSTANCES)],
groupMetrics = [GroupMetrics.all()],
minimumInstances,
maximumInstances,
role = new GuInstanceRole(scope, { app }),
Expand Down
8 changes: 0 additions & 8 deletions src/patterns/ec2-app/__snapshots__/base.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ exports[`the GuEC2App pattern can produce a restricted EC2 app locked to specifi
"MetricsCollection": [
{
"Granularity": "1Minute",
"Metrics": [
"GroupTotalInstances",
"GroupInServiceInstances",
],
},
],
"MinSize": "1",
Expand Down Expand Up @@ -1108,10 +1104,6 @@ exports[`the GuEC2App pattern should produce a functional EC2 app with minimal a
"MetricsCollection": [
{
"Granularity": "1Minute",
"Metrics": [
"GroupTotalInstances",
"GroupInServiceInstances",
],
},
],
"MinSize": "1",
Expand Down

0 comments on commit 43dc653

Please sign in to comment.