-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Ecs service module health check settings #47217
Ecs service module health check settings #47217
Conversation
…time with a botocore version check and some initial testing
Hi @stefanhorning, thank you for submitting this pull-request! |
@stefanhorning, just so you are aware we have a dedicated Working Group for aws. |
The test
|
def health_check_setable(self, params): | ||
load_balancers = params.get('loadBalancers', []) | ||
# check if botocore (and thus boto3) is new enough for using the healthCheckGracePeriodSeconds parameter | ||
return len(load_balancers) > 0 and LooseVersion(botocore.__version__) >= LooseVersion('1.9.0') |
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.
AnsibleAWSModule has a function to check boto3/botocore versions you can use here.
return len(load_balancers) > 0 and LooseVersion(botocore.__version__) >= LooseVersion('1.9.0') | |
return len(load_balancers) > 0 and self.module.botocore_at_least('1.9.0') |
@ryansb applied your recommended changes, also build is green now. Anything else I should do? |
ready_for_review |
ready_for_review |
@@ -466,7 +481,8 @@ def main(): | |||
security_groups=dict(type='list'), | |||
assign_public_ip=dict(type='bool'), | |||
)), | |||
launch_type=dict(required=False, choices=['EC2', 'FARGATE']) | |||
launch_type=dict(required=False, choices=['EC2', 'FARGATE']), | |||
health_check_grace_period_seconds=dict(required=False, type='int', default=30) |
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.
Isn't healthcheck grace period 0 seconds by default? Why would it default to 30 here?
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.
Couldn't find any docs on what values are allowed. However I assume I had a reason setting it to 30, probably if setting it there is a minimum. It's long ago I actually implented this, but I can recheck if you want.
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.
healthCheckGracePeriodSeconds (integer) -- The period of time, in seconds, that the Amazon ECS service scheduler should ignore unhealthy Elastic Load Balancing target health checks after a task has first started. This is only valid if your service is configured to use a load balancer. If your service's tasks take a while to start and respond to Elastic Load Balancing health checks, you can specify a health check grace period of up to 7,200 seconds during which the ECS service scheduler ignores health check status. This grace period can prevent the ECS service scheduler from marking tasks as unhealthy and stopping them before they have time to come up.
I've also checked some of my services that were created before health check grace period was added and the return for it is 0. Having 30 seconds be the default wouldn't be a "problem" for me, but it would be a change from what I think is current behavior and not what I would expect.
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.
Yes, I saw those docs already unfortunaltely they didn't say anything about the minimum value. But if you say it's 0 I will simply change that.
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.
However looking at the code again it's actually an optional value, hence if you don't provide the parameter health_check_grace_period_seconds
it won't actually be set (no matter what the default value is). I guess I just followed the pattern of the few lines above to always set a sane default if the param is required=False
.
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.
Just to clarify, I ran through a quick test omitting health check grace period with default at 30 and it looks like it gets set even when I omit in yaml.
But I see you dropped it, so I think this looks good. I'll give it another look over shortly and put a full review in if I can.
Thanks.
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.
Everything looks good to me except the required botocore version.
I wouldn't have noticed except I looked at implementing this feature too. A little testing and searching through botocore commits suggested it needed 1.8.20 instead of 1.9.0. Not that it would break anything, but to be thorough :)
@@ -121,6 +121,11 @@ | |||
required: false | |||
version_added: 2.7 | |||
choices: ["EC2", "FARGATE"] | |||
health_check_grace_period_seconds: | |||
description: | |||
- Seconds to wait before health checking the freshly added/updated services. This option requires botocore >= 1.9.0. |
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.
Not sure if something else happened in 1.9.0, but I think health check grace period was added to botocore in 1.8.20.
boto/botocore@a110e8d#diff-48d02f400bc4e82bd35bf470ad45ef20R1145
This is the blame for 1.8.20 showing the addition of HealthCheckGracePeriodSeconds to ecs service. I couldn't find anything newer that would make it need 1.9.0.
def health_check_setable(self, params): | ||
load_balancers = params.get('loadBalancers', []) | ||
# check if botocore (and thus boto3) is new enough for using the healthCheckGracePeriodSeconds parameter | ||
return len(load_balancers) > 0 and self.module.botocore_at_least('1.9.0') |
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.
Same thing here as above. Testing with botocore 1.8.19 fails when trying to use healthcheck grace period and succeeds on 1.8.20
Otherwise, looks good.
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 testing, I will update it now
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.
Looks good to me. Hopefully this helps.
shipit
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 looks good to me - there are a couple of longer lines in this PR which I'd welcome shortening just to keep consistent (they go off edge of the github PR review which makes them noticeable) but that is not a blocker.
I'll run the test suite before giving it my full approval, but if anyone does that before me, then I'm happy for this to be merged as is.
|
@@ -401,19 +406,24 @@ def create_service(self, service_name, cluster_name, task_definition, load_balan | |||
params['networkConfiguration'] = network_configuration | |||
if launch_type: | |||
params['launchType'] = launch_type | |||
if self.health_check_setable(params): | |||
params['healthCheckGracePeriodSeconds'] = health_check_grace_period_seconds |
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 suspect this would pass tests if this only set the value if the parameter wasn't None
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 guess this was broken by removing the default value as requested by @ezmac
Will try to add a better check soonish.
No worries @stefanhorning - I'm just testing the fix now, I'll push it to your branch if it fixes it |
rebuild_merge |
Merged for inclusion in 2.8. Thanks @stefanhorning for getting this over the line and @ezmac for the reviews |
* Added feature health_check_grace_period_seconds to ecs_service, this time with a botocore version check and some initial testing * Only set health_check_grace_period_seconds when loadbalancers are defined * Removed leftover commas and fix in test * Removed blank line * Minor improvements for ecs_service module * Removed default (30) for health_check_grace_period_seconds param * Changed botocore version allowed to 1.8.20 for health check param. * Fix empty healthcheck failure
SUMMARY
Added health check grace period to ecs_service module. New attempt after closing this PR way back:
#39289 and none of the other PRs got merged.
ISSUE TYPE
COMPONENT NAME
module ecs_service.py
ADDITIONAL INFORMATION
Added backwards compatibility this time with a check for the botocore version. Also makes sure the healthCheckGracePeriodSeconds param is only applied when loadbalancers are configured (as creation otherwise fails). Added some initial tests.