Skip to content

Commit cb889bc

Browse files
feat(elbv2): add metrics to INetworkLoadBalancer and IApplicationLoadBalancer (#23853)
By moving the metrics methods to the `INetworkLoadBalancer` and `IApplicationLoadBalancer` interfaces it allows to create these metrics also for LBs that are imported via the `fromXXX` methods. To create the metrics for LBs requires only the full name of the LB. This attribute is available at the constructs returned by the `fromXXX` methods. To solve this problem I did: - Introduce a new interface for each LB type: `INetworkLoadBalancerMetrics`, `IApplicationLoadBalancerMetrics` - Create a concrete implementation for the new interfaces (1 for each): `NetworkLoadBalancerMetrics` and `ApplicationLoadBalancerMetrics` - Make each concrete implementation of each Load Balancer to also provide a `metrics` field. The concrete implementations of the load balancers are: `ImportedApplicationLoadBalancer`, `LookedUpApplicationLoadBalancer`, `ApplicationLoadBalancer` (and the same for the NLB classes). I chose to create a new interface because code can be reused across the 3 concrete implementations of each Load Balancer. I deprecated the `metricXXX()` methods of each load balancer because I think it is cleaner to access metrics through the new `metrics` attribute/interface. This task is a step in the direction to fix #10850, but I'd like to get feedback and merge this PR first before proceeding into the `TargetGroup` constructs. PS: I'm learning Typescript, so please, tell me if I'm doing something wrong here. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent e646ad5 commit cb889bc

21 files changed

+1877
-97
lines changed

packages/@aws-cdk/aws-elasticloadbalancingv2/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -604,3 +604,14 @@ const listener = elbv2.NetworkListener.fromLookup(this, 'ALBListener', {
604604
listenerPort: 12345,
605605
});
606606
```
607+
608+
## Metrics
609+
610+
You may create metrics for each Load Balancer through the `metrics` attribute:
611+
612+
```ts
613+
declare const alb: elbv2.IApplicationLoadBalancer;
614+
615+
const albMetrics: elbv2.IApplicationLoadBalancerMetrics = alb.metrics;
616+
const metricConnectionCount: cloudwatch.Metric = albMetrics.activeConnectionCount();
617+
```

0 commit comments

Comments
 (0)