-
Notifications
You must be signed in to change notification settings - Fork 4k
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(autoscaling): health check configuration #3390
feat(autoscaling): health check configuration #3390
Conversation
* | ||
* This property required with ELB health check type. | ||
* | ||
* @default - |
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.
I couldn't find a current default value in the CloudFormation documentation. The API Reference mentions a default of 0. Should I use Duration.seconds(0)
in the JSDoc?
* | ||
* @default - HealthCheckConfiguration with defaults. | ||
*/ | ||
readonly healthCheck?: HealthCheckConfiguration; |
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.
This will lends itself nicely to a "union-like" API:
export interface Ec2HealthCheckOptions {
readonly grace?: Duration;
}
export interface ElbHealthCheckOptions {
readonly grace: Duration; // <-- required here
}
export class HealthCheck {
public static ec2(options: Ec2HealthCheckOptions = {}): HealthCheck {
return new HealthCheck('EC2', options.grace && options.grace.toSeconds());
}
public static elb(options: ElbHealthCheckOptions): HealthCheck {
return new HealthCheck('ELB', options.grace.toSeconds());
}
private constructor(public readonly type: string, public readonly gradePeriod?: number) { }
}
And then the usage is:
healthCheck: HealthCheck.ec2();
healthCheck: HealthCheck.ec2({ grace: Duration.minutes(5) });
healthCheck: HealthCheck.elb({ grace: Duration.minutes(5) }); // <-- required grace enforced by compiler
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.
That's a much cleaner API, thanks.
How would you feel about using a Partial<HealthCheckOptions>
instead of repeating the Options Interface?
export interface HealthCheckOptions {
readonly grace: Duration;
}
export class HealthCheck {
public static ec2(options: Partial<HealthCheckOptions> = {}): HealthCheck {
return new HealthCheck('EC2', options.grace && options.grace.toSeconds());
}
public static elb(options: HealthCheckOptions): HealthCheck {
return new HealthCheck('ELB', options.grace.toSeconds());
}
private constructor(public readonly type: string, public readonly gradePeriod?: number) { }
}
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.
Never mind, it seems like JSII doesn't support the Partial keyword:
09:46:31 - File change detected. Starting incremental compilation...
@aws-cdk/aws-autoscaling: lib/auto-scaling-group.ts:712:21 - error TS9999: JSII: Only string index maps are supported
@aws-cdk/aws-autoscaling: 712 public static ec2(options: Partial<HealthCheckOptions> = {}): HealthCheck {
@aws-cdk/aws-autoscaling: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
Done, thanks
/** | ||
* Configuration for health checks | ||
* | ||
* @default - HealthCheckConfiguration with defaults. |
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.
If healthCheck
is not specified, then there are no health checks, right? Fix the default description.
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.
I think the health check is mandatory. The CloudFormation documentation says EC2 is the default, and the API reference says the value is required.
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.
Got it, so we should say that EC2 with no grace period is the default.
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.
Done
private constructor(public readonly type: string, public readonly gracePeriod?: number) { } | ||
} | ||
|
||
export enum HealthCheckType { |
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.
No need to export this.
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.
Done
return new HealthCheck(HealthCheckType.ELB, options.grace.toSeconds()); | ||
} | ||
|
||
private constructor(public readonly type: string, public readonly gracePeriod?: number) { } |
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.
This could be a Duration
actually and converted at the usage site
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.
Done
@@ -397,6 +397,28 @@ export = { | |||
test.done(); | |||
}, | |||
|
|||
'can configure health check'(test: Test) { |
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.
add a test for ec2
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.
Done
/** | ||
* Configuration for health checks | ||
* | ||
* @default - HealthCheckConfiguration with defaults. |
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.
Got it, so we should say that EC2 with no grace period is the default.
/** | ||
* Specified the time Auto Scaling waits before checking the health status of an EC2 instance that has come into service | ||
* | ||
* @default - |
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.
I am assuming no grace is the default?
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.
Yeah, like I said in the original PR, the CloudFormation doc isn't explicit, but the API reference says the duration is 0 seconds.
I updated the JSDoc accordingly
This reverts commit c9a2c21.
The PR #3390 added AddCapacityOptions properties that return `@aws-cdk/aws-autoscaling.HealthCheck`, and `@aws-cdk/aws-ecs.HealthCheck` also exists. This caused the .NET code generation to emit ambiguous code that does not compile. Reverting as to enable a release. Related: aws/jsii#650
Implements missing Auto Scaling Group properties [HealthCheckType](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html#cfn-as-group-healthchecktype) and [HealthCheckGracePeriod](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html#cfn-as-group-healthcheckgraceperiod) They are grouped in a `healthCheck` object property. The constructor checks that the following requirement is fulfilled: > If you are adding an ELB health check, you must specify this property. Fixes #3381
Implements missing Auto Scaling Group properties [HealthCheckType](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html#cfn-as-group-healthchecktype) and [HealthCheckGracePeriod](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html#cfn-as-group-healthcheckgraceperiod) They are grouped in a `healthCheck` object property. The constructor checks that the following requirement is fulfilled: > If you are adding an ELB health check, you must specify this property. Fixes #3381
Implements missing Auto Scaling Group properties HealthCheckType and HealthCheckGracePeriod
They are grouped in a
healthCheck
object property.The constructor checks that the following requirement is fulfilled:
Fixes #3381
Please read the contribution guidelines and follow the pull-request checklist.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license