Skip to content

Commit

Permalink
feat(elasticloadbalancingv2): more health check validations to NLB ta…
Browse files Browse the repository at this point in the history
…rget group (aws#3703) (aws#10205)


Add the following Health Check validations for Network Target Group:
 - `healthyThresholdCount` and `unhealthyThresholdCount` must the same
 - `healthyThresholdCount` and `unhealthyThresholdCount` must be between 2 and 10

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
yerzhan7 authored Sep 10, 2020
1 parent 287f808 commit e3f3332
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,28 @@ export class NetworkTargetGroup extends TargetGroupBase implements INetworkTarge
}
}

if (healthCheck.healthyThresholdCount) {
const thresholdCount = healthCheck.healthyThresholdCount;
if (thresholdCount < 2 || thresholdCount > 10) {
ret.push(`Healthy Threshold Count '${thresholdCount}' not supported. Must be a number between 2 and 10.`);
}
}

if (healthCheck.unhealthyThresholdCount) {
const thresholdCount = healthCheck.unhealthyThresholdCount;
if (thresholdCount < 2 || thresholdCount > 10) {
ret.push(`Unhealthy Threshold Count '${thresholdCount}' not supported. Must be a number between 2 and 10.`);
}
}

if (healthCheck.healthyThresholdCount && healthCheck.unhealthyThresholdCount &&
healthCheck.healthyThresholdCount !== healthCheck.unhealthyThresholdCount) {
ret.push([
`Healthy and Unhealthy Threshold Counts must be the same: ${healthCheck.healthyThresholdCount}`,
`is not equal to ${healthCheck.unhealthyThresholdCount}.`,
].join(' '));
}

if (!healthCheck.protocol) {
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,117 @@ describe('tests', () => {
});
}).toThrow();
});

test('Throws error for invalid health check interval', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'Vpc');

new elbv2.NetworkTargetGroup(stack, 'Group', {
vpc,
port: 80,
healthCheck: {
interval: cdk.Duration.seconds(5),
},
});

expect(() => {
app.synth();
}).toThrow(/Health check interval '5' not supported. Must be one of the following values '10,30'./);
});

test('Throws error for invalid health check protocol', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'Vpc');

new elbv2.NetworkTargetGroup(stack, 'Group', {
vpc,
port: 80,
healthCheck: {
protocol: elbv2.Protocol.UDP,
},
});

expect(() => {
app.synth();
}).toThrow(/Health check protocol 'UDP' is not supported. Must be one of \[HTTP, HTTPS, TCP\]/);
});

test('Throws error for health check path property when protocol does not support it', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'Vpc');

new elbv2.NetworkTargetGroup(stack, 'Group', {
vpc,
port: 80,
healthCheck: {
path: '/my-path',
protocol: elbv2.Protocol.TCP,
},
});

expect(() => {
app.synth();
}).toThrow(/'TCP' health checks do not support the path property. Must be one of \[HTTP, HTTPS\]/);
});

test('Throws error for invalid health check healthy threshold', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'Vpc');

new elbv2.NetworkTargetGroup(stack, 'Group', {
vpc,
port: 80,
healthCheck: {
protocol: elbv2.Protocol.TCP,
healthyThresholdCount: 11,
},
});

expect(() => {
app.synth();
}).toThrow(/Healthy Threshold Count '11' not supported. Must be a number between 2 and 10./);
});

test('Throws error for invalid health check unhealthy threshold', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'Vpc');

new elbv2.NetworkTargetGroup(stack, 'Group', {
vpc,
port: 80,
healthCheck: {
protocol: elbv2.Protocol.TCP,
unhealthyThresholdCount: 1,
},
});

expect(() => {
app.synth();
}).toThrow(/Unhealthy Threshold Count '1' not supported. Must be a number between 2 and 10./);
});

test('Throws error for unequal healthy and unhealthy threshold counts', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'Vpc');

new elbv2.NetworkTargetGroup(stack, 'Group', {
vpc,
port: 80,
healthCheck: {
protocol: elbv2.Protocol.TCP,
healthyThresholdCount: 5,
unhealthyThresholdCount: 3,
},
});

expect(() => {
app.synth();
}).toThrow(/Healthy and Unhealthy Threshold Counts must be the same: 5 is not equal to 3./);
});
});

0 comments on commit e3f3332

Please sign in to comment.