Skip to content

Commit 7998eeb

Browse files
authored
chore(elasticloadbalancingv2): specific 5XX CloudWatch metrics for ALB (#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*
1 parent 64afa72 commit 7998eeb

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,26 @@ export enum HttpCodeElb {
753753
* The number of HTTP 5XX server error codes that originate from the load balancer.
754754
*/
755755
ELB_5XX_COUNT = 'HTTPCode_ELB_5XX_Count',
756+
757+
/**
758+
* The number of HTTP 500 server error codes that originate from the load balancer.
759+
*/
760+
ELB_500_COUNT = 'HTTPCode_ELB_500_Count',
761+
762+
/**
763+
* The number of HTTP 502 server error codes that originate from the load balancer.
764+
*/
765+
ELB_502_COUNT = 'HTTPCode_ELB_502_Count',
766+
767+
/**
768+
* The number of HTTP 503 server error codes that originate from the load balancer.
769+
*/
770+
ELB_503_COUNT = 'HTTPCode_ELB_503_Count',
771+
772+
/**
773+
* The number of HTTP 504 server error codes that originate from the load balancer.
774+
*/
775+
ELB_504_COUNT = 'HTTPCode_ELB_504_Count',
756776
}
757777

758778
/**

packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/load-balancer.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,29 @@ describe('tests', () => {
684684
}
685685
});
686686

687+
test.each([
688+
elbv2.HttpCodeElb.ELB_500_COUNT,
689+
elbv2.HttpCodeElb.ELB_502_COUNT,
690+
elbv2.HttpCodeElb.ELB_503_COUNT,
691+
elbv2.HttpCodeElb.ELB_504_COUNT,
692+
])('use specific load balancer generated 5XX metrics', (metricName) => {
693+
// GIVEN
694+
const stack = new cdk.Stack();
695+
const vpc = new ec2.Vpc(stack, 'Stack');
696+
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc });
697+
698+
// WHEN
699+
const metric = lb.metrics.httpCodeElb(metricName);
700+
701+
// THEN
702+
expect(metric.namespace).toEqual('AWS/ApplicationELB');
703+
expect(metric.statistic).toEqual('Sum');
704+
expect(metric.metricName).toEqual(metricName);
705+
expect(stack.resolve(metric.dimensions)).toEqual({
706+
LoadBalancer: { 'Fn::GetAtt': ['LB8A12904C', 'LoadBalancerFullName'] },
707+
});
708+
});
709+
687710
test('loadBalancerName', () => {
688711
// GIVEN
689712
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)