-
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(apprunner): add HealthCheckConfiguration property in Service #27029
feat(apprunner): add HealthCheckConfiguration property in Service #27029
Conversation
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.
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.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
@@ -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) { |
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.
Can you please also add validation for HealthyThreshold
, Interval
, Timeout
, and UnhealthyThreshold
min/max values according to this spec?
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.
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.
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) { |
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.
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'); |
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.
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', () => { |
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 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.
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.
Thanks for the fast implementation 💪
Looks good overall!
Just a couple of changes on code cleanup and message formatting.
Thanks, I changed! |
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.
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}`); |
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.
interval
and timeout
should be converted with toSeconds()
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.
OK, I changed!
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, | ||
}, | ||
}); |
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'd like us to use an enum like class for this, because HTTP and TCP health checks have different props:
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
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.
Pull request has been modified.
cfcb72f
to
6664245
Compare
changed comments use bind
6664245
to
d0cd255
Compare
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). |
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
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