Skip to content

Commit

Permalink
feat(elbv2): add metrics to INetworkLoadBalancer and IApplicationLoad…
Browse files Browse the repository at this point in the history
…Balancer

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.
  • Loading branch information
Gustavo Muenz committed Jan 30, 2023
1 parent 660198b commit 3ff2ed6
Show file tree
Hide file tree
Showing 21 changed files with 1,877 additions and 97 deletions.
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-elasticloadbalancingv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,14 @@ const listener = elbv2.NetworkListener.fromLookup(this, 'ALBListener', {
listenerPort: 12345,
});
```

## Metrics

You may create metrics for each Load Balancer through the `metrics` attribute:

```ts
declare const alb: elbv2.IApplicationLoadBalancer;

const albMetrics: elbv2.IApplicationLoadBalancerMetrics = alb.metrics;
const metricConnectionCount: cloudwatch.Metric = albMetrics.activeConnectionCount();
```

0 comments on commit 3ff2ed6

Please sign in to comment.