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(apprunner): add HealthCheckConfiguration property in Service #27029

Merged
merged 15 commits into from
Sep 27, 2023

Conversation

go-to-k
Copy link
Contributor

@go-to-k go-to-k commented Sep 6, 2023

This PR adds HealthCheckConfiguration property in Service construct.

Closes #26972.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the admired-contributor [Pilot] contributed between 13-24 PRs to the CDK label Sep 6, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team September 6, 2023 08:40
@github-actions github-actions bot added the p2 label Sep 6, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. labels Sep 6, 2023
@go-to-k go-to-k changed the title feat(apprunner): add HealthCheckConfiguration property feat(apprunner): add HealthCheckConfiguration property in Service Sep 6, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 6, 2023 10:45

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@go-to-k go-to-k marked this pull request as ready for review September 6, 2023 10:57
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Sep 6, 2023
@@ -1074,6 +1147,10 @@ export class Service extends cdk.Resource implements iam.IGrantable {
throw new Error('configurationValues cannot be provided if the ConfigurationSource is Repository');
}

if (this.props.healthCheckConfiguration?.path && this.props.healthCheckConfiguration?.protocol !== HealthCheckProtocolType.HTTP) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please also add validation for HealthyThreshold, Interval, Timeout, and UnhealthyThreshold min/max values according to this spec?

Copy link
Contributor Author

@go-to-k go-to-k Sep 7, 2023

Choose a reason for hiding this comment

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

@lpizzinidev

Thanks for your review! I missed!

I changed them, please see again.

2a11dc4

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Sep 6, 2023
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!
Looks good overall, just a small addition on parameter validation.

@@ -1074,6 +1147,35 @@ export class Service extends cdk.Resource implements iam.IGrantable {
throw new Error('configurationValues cannot be provided if the ConfigurationSource is Repository');
}

if (this.props.healthCheckConfiguration?.path !== undefined) {
Copy link
Contributor

@lpizzinidev lpizzinidev Sep 7, 2023

Choose a reason for hiding this comment

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

The implementation is correct.
We should create a separate function to handle the logic to keep the constructor cleaner, something like:

private validateHealthCheckConfiguration(healthCheckConfiguration?: HealthCheckConfiguration) {
    // Add guard to avoid using ? on every successive control
    if (!healthCheckConfiguration) return; 
    // Validate parameters...
}

}
if (this.props.healthCheckConfiguration?.healthyThreshold !== undefined) {
if (this.props.healthCheckConfiguration?.healthyThreshold < 1 || this.props.healthCheckConfiguration?.healthyThreshold > 20) {
throw new Error('healthyThreshold must be greater than or equal to 1 and less than or equal to 20');
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add the received value in the error message as a feedback to the user and make the message more concise:

throw new Error(`healthyThreshold must be between 1 and 20, got ${healthCheckConfiguration.healthyThreshold}`);

}).toThrow('path length must be greater than 0');
});

test('OK if healthyThreshold is 1 in healthCheckConfiguration', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should only leave the unit tests for the failing cases of validation, we are already checking that the implementation is working in the Service has healthCheckConfiguration test.
Adding test cases for checking limit values is a bit redundant in my opinion.

Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

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

Thanks for the fast implementation 💪
Looks good overall!
Just a couple of changes on code cleanup and message formatting.

@go-to-k
Copy link
Contributor Author

go-to-k commented Sep 7, 2023

Thanks, I changed!

9e84888

Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

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

Thanks!
One last change on the formatting of the durations in the validation message

}
if (healthCheckConfiguration.interval !== undefined) {
if (healthCheckConfiguration.interval.toSeconds() < 1 || healthCheckConfiguration.interval.toSeconds() > 20) {
throw new Error(`interval must be between 1 and 20 seconds, got ${healthCheckConfiguration.interval}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

interval and timeout should be converted with toSeconds()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I changed!

629b131

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 7, 2023
Comment on lines 224 to 237
new apprunner.Service(this, 'Service', {
source: apprunner.Source.fromEcrPublic({
imageConfiguration: { port: 8000 },
imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
}),
healthCheckConfiguration: {
healthyThreshold: 5,
interval: Duration.seconds(10),
path: '/',
protocol: apprunner.HealthCheckProtocolType.HTTP,
timeout: Duration.seconds(10),
unhealthyThreshold: 10,
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like us to use an enum like class for this, because HTTP and TCP health checks have different props:

Suggested change
new apprunner.Service(this, 'Service', {
source: apprunner.Source.fromEcrPublic({
imageConfiguration: { port: 8000 },
imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
}),
healthCheckConfiguration: {
healthyThreshold: 5,
interval: Duration.seconds(10),
path: '/',
protocol: apprunner.HealthCheckProtocolType.HTTP,
timeout: Duration.seconds(10),
unhealthyThreshold: 10,
},
});
new apprunner.Service(this, 'Service', {
source: apprunner.Source.fromEcrPublic({
imageConfiguration: { port: 8000 },
imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
}),
healthCheck: apprunner.HealthCheck.http({
healthyThreshold: 5,
interval: Duration.seconds(10),
path: '/',
timeout: Duration.seconds(10),
unhealthyThreshold: 10,
}),
});

Have a look at appmesh.HealthCheck

Copy link
Contributor Author

@go-to-k go-to-k Sep 23, 2023

Choose a reason for hiding this comment

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

@mrgrain

I changed to use the HealthCheck class like appmesh.HealthCheck.

d0cd255

70c125e

@mrgrain mrgrain removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 21, 2023
@mergify mergify bot dismissed mrgrain’s stale review September 23, 2023 13:59

Pull request has been modified.

@go-to-k go-to-k force-pushed the feat/apprunner-custom-health-endpoint branch from cfcb72f to 6664245 Compare September 23, 2023 14:02
changed comments

use bind
@go-to-k go-to-k force-pushed the feat/apprunner-custom-health-endpoint branch from 6664245 to d0cd255 Compare September 23, 2023 14:09
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 23, 2023
@mergify
Copy link
Contributor

mergify bot commented Sep 27, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 27, 2023
@mergify
Copy link
Contributor

mergify bot commented Sep 27, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 5938fd1
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 4e8c9c4 into aws:main Sep 27, 2023
8 checks passed
@mergify
Copy link
Contributor

mergify bot commented Sep 27, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(apprunner-alpha): (Allow specify custom health endpoint)
5 participants