-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(elasticloadbalancingv2): health check interval greater than timeout #29075
Changes from all commits
604a8ef
f4693ff
94f9c2f
26276b8
bfa2b3d
649dae2
6375b3e
69b92d4
7e84d68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,6 +280,7 @@ export abstract class TargetGroupBase extends Construct implements ITargetGroup | |
this.targetGroupName = this.resource.attrTargetGroupName; | ||
this.defaultPort = additionalProps.port; | ||
|
||
this.node.addValidation({ validate: () => this.validateHealthCheck() }); | ||
this.node.addValidation({ validate: () => this.validateTargetGroup() }); | ||
} | ||
|
||
|
@@ -351,6 +352,22 @@ export abstract class TargetGroupBase extends Construct implements ITargetGroup | |
|
||
return ret; | ||
} | ||
|
||
protected validateHealthCheck(): string[] { | ||
const ret = new Array<string>(); | ||
|
||
const intervalSeconds = this.healthCheck.interval?.toSeconds(); | ||
const timeoutSeconds = this.healthCheck.timeout?.toSeconds(); | ||
|
||
if (intervalSeconds && timeoutSeconds) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this work as expected if either intervalSeconds or timeoutSeconds equals to zero? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (intervalSeconds < timeoutSeconds) { | ||
// < instead of <= for backwards compatibility, see discussion in https://github.com/aws/aws-cdk/pull/26031 | ||
ret.push('Health check interval must be greater than or equal to the timeout; received interval ' + | ||
`${intervalSeconds}, timeout ${timeoutSeconds}.`); | ||
} | ||
} | ||
return ret; | ||
} | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,45 @@ describe('tests', () => { | |
}).toThrow(/Health check interval '3' not supported. Must be between 5 and 300./); | ||
}); | ||
|
||
test('Throws error for health check interval less than timeout', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add an edge case test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test for this. See discussion above on why we chose to allow them to be equal. |
||
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(10), | ||
timeout: cdk.Duration.seconds(20), | ||
}, | ||
}); | ||
|
||
expect(() => { | ||
app.synth(); | ||
}).toThrow('Health check interval must be greater than or equal to the timeout; received interval 10, timeout 20.'); | ||
}); | ||
|
||
// for backwards compatibility these can be equal, see discussion in https://github.com/aws/aws-cdk/pull/26031 | ||
test('No error for health check interval == timeout', () => { | ||
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(10), | ||
timeout: cdk.Duration.seconds(10), | ||
}, | ||
}); | ||
|
||
expect(() => { | ||
app.synth(); | ||
}).not.toThrow(); | ||
}); | ||
|
||
test('targetGroupName unallowed: more than 32 characters', () => { | ||
// GIVEN | ||
const app = new cdk.App(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving this validation to
shared