Skip to content
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

Merged
merged 12 commits into from
Jul 25, 2019

Conversation

nmussy
Copy link
Contributor

@nmussy nmussy commented Jul 23, 2019

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:

If you are adding an ELB health check, you must specify this property.

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

@nmussy nmussy requested a review from a team as a code owner July 23, 2019 07:25
*
* This property required with ELB health check type.
*
* @default -
Copy link
Contributor Author

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?

@nmussy nmussy changed the title feat(autoscaling): health check configuration feat(auto-scaling): health check configuration Jul 23, 2019
*
* @default - HealthCheckConfiguration with defaults.
*/
readonly healthCheck?: HealthCheckConfiguration;
Copy link
Contributor

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

Copy link
Contributor Author

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) { }
}

Copy link
Contributor Author

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:                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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) { }
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nmussy nmussy changed the title feat(auto-scaling): health check configuration feat(autoscaling): health check configuration Jul 23, 2019
/**
* Configuration for health checks
*
* @default - HealthCheckConfiguration with defaults.
Copy link
Contributor

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 -
Copy link
Contributor

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?

Copy link
Contributor Author

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

@eladb eladb merged commit c9a2c21 into aws:master Jul 25, 2019
@nmussy nmussy deleted the feat-autoscaling-health-check-type branch July 25, 2019 12:27
RomainMuller added a commit that referenced this pull request Jul 25, 2019
RomainMuller added a commit that referenced this pull request Jul 25, 2019
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
RomainMuller pushed a commit that referenced this pull request Jul 25, 2019
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
mergify bot pushed a commit that referenced this pull request Aug 7, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autoscaling group should have health check type option
2 participants