Skip to content

Commit

Permalink
chore(elasticloadbalancingv2): specific 5XX CloudWatch metrics for ALB (
Browse files Browse the repository at this point in the history
#30659)

### Reason for this change
ALB supports metrics for specific load balancer generated 5XX level error metrics.
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-cloudwatch-metrics.html

However, they are currently not included in `HttpCodeElb`, so the `metrics.httpCodeElb` method is not available and `metrics.custom` must be used.
```ts
let alb: IApplicationLoadBalancer;
alb.metrics.httpCodeElb(HttpCodeElb.ELB_5XX_COUNT); // we can do this
alb.metrics.httpCodeElb(HttpCodeElb.ELB_500_COUNT); // currently we cannot do this
alb.metrics.custom("HTTPCode_ELB_500_Count");
```

Adding the metric names to `HttpCodeElb` makes it easier to understand as it can be configured in the same way as `HTTPCode_ELB_5XX_Count`.

### Description of changes
Add metrics names to `HttpCodeElb`.



### Description of how you validated changes



### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
sakurai-ryo committed Jul 24, 2024
1 parent 64afa72 commit 7998eeb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,26 @@ export enum HttpCodeElb {
* The number of HTTP 5XX server error codes that originate from the load balancer.
*/
ELB_5XX_COUNT = 'HTTPCode_ELB_5XX_Count',

/**
* The number of HTTP 500 server error codes that originate from the load balancer.
*/
ELB_500_COUNT = 'HTTPCode_ELB_500_Count',

/**
* The number of HTTP 502 server error codes that originate from the load balancer.
*/
ELB_502_COUNT = 'HTTPCode_ELB_502_Count',

/**
* The number of HTTP 503 server error codes that originate from the load balancer.
*/
ELB_503_COUNT = 'HTTPCode_ELB_503_Count',

/**
* The number of HTTP 504 server error codes that originate from the load balancer.
*/
ELB_504_COUNT = 'HTTPCode_ELB_504_Count',
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,29 @@ describe('tests', () => {
}
});

test.each([
elbv2.HttpCodeElb.ELB_500_COUNT,
elbv2.HttpCodeElb.ELB_502_COUNT,
elbv2.HttpCodeElb.ELB_503_COUNT,
elbv2.HttpCodeElb.ELB_504_COUNT,
])('use specific load balancer generated 5XX metrics', (metricName) => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc });

// WHEN
const metric = lb.metrics.httpCodeElb(metricName);

// THEN
expect(metric.namespace).toEqual('AWS/ApplicationELB');
expect(metric.statistic).toEqual('Sum');
expect(metric.metricName).toEqual(metricName);
expect(stack.resolve(metric.dimensions)).toEqual({
LoadBalancer: { 'Fn::GetAtt': ['LB8A12904C', 'LoadBalancerFullName'] },
});
});

test('loadBalancerName', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 7998eeb

Please sign in to comment.