From 0c0f3936959b2ceb3b63306ee0b731026541e02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christophe=20Boug=C3=A8re?= Date: Fri, 2 Apr 2021 00:23:46 +0200 Subject: [PATCH] feat(elasticloadbalancingv2): add grpc code matcher for alb closes #13947 --- .../aws-elasticloadbalancingv2/README.md | 4 ++++ .../lib/shared/base-target-group.ts | 13 ++++++++++++- .../test/alb/target-group.test.ts | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/README.md b/packages/@aws-cdk/aws-elasticloadbalancingv2/README.md index b04d39e1862d7..76a6b7e1ddd5c 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/README.md +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/README.md @@ -283,6 +283,10 @@ const tg = new elbv2.ApplicationTargetGroup(stack, 'TG', { port: 50051, protocol: elbv2.ApplicationProtocol.HTTP, protocolVersion: elbv2.ApplicationProtocolVersion.GRPC, + healthCheck: { + enabled: true, + healthyGrpcCodes: '0-99', + }, vpc, }); ``` diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts index 5e569fd8213ca..175f63ddc4d3d 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts @@ -136,6 +136,16 @@ export interface HealthCheck { */ readonly unhealthyThresholdCount?: number; + /** + * GRPC code to use when checking for a successful response from a target. + * + * You can specify values between 0 and 99. You can specify multiple values + * (for example, "0,1") or a range of values (for example, "0-5"). + * + * @default - 12 + */ + readonly healthyGrpcCodes?: string; + /** * HTTP code to use when checking for a successful response from a target. * @@ -259,7 +269,8 @@ export abstract class TargetGroupBase extends CoreConstruct implements ITargetGr healthyThresholdCount: cdk.Lazy.number({ produce: () => this.healthCheck?.healthyThresholdCount }), unhealthyThresholdCount: cdk.Lazy.number({ produce: () => this.healthCheck?.unhealthyThresholdCount }), matcher: cdk.Lazy.any({ - produce: () => this.healthCheck?.healthyHttpCodes !== undefined ? { + produce: () => this.healthCheck?.healthyHttpCodes !== undefined || this.healthCheck?.healthyGrpcCodes !== undefined ? { + grpcCode: this.healthCheck.healthyGrpcCodes, httpCode: this.healthCheck.healthyHttpCodes, } : undefined, }), diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/target-group.test.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/target-group.test.ts index ea028b543096f..f4b1212942dd6 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/target-group.test.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/target-group.test.ts @@ -166,11 +166,29 @@ describe('tests', () => { new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', { vpc, protocolVersion: elbv2.ApplicationProtocolVersion.GRPC, + healthCheck: { + enabled: true, + healthyGrpcCodes: '0-99', + interval: cdk.Duration.seconds(255), + timeout: cdk.Duration.seconds(192), + healthyThresholdCount: 29, + unhealthyThresholdCount: 27, + path: '/arbitrary', + }, }); // THEN expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { ProtocolVersion: 'GRPC', + HealthCheckEnabled: true, + HealthCheckIntervalSeconds: 255, + HealthCheckPath: '/arbitrary', + HealthCheckTimeoutSeconds: 192, + HealthyThresholdCount: 29, + Matcher: { + GrpcCode: '0-99', + }, + UnhealthyThresholdCount: 27, }); });