Uh oh!
There was an error while loading. Please reload this page.
Added retry to ECS Operator - #14263
Conversation
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
|
Uh oh!
There was an error while loading. Please reload this page.
markhopson
commented
Feb 18, 2021
@turbaszek Thanks for the feedback. I also saw some checks fail (i.e. |
markhopson
commented
Feb 26, 2021
@turbaszek just a friendly bump to see what the next steps are here |
| from airflow.providers.amazon.aws.models.exceptions import ECSOperatorError | ||
| from airflow.utils.log.logging_mixin import LoggingMixin | ||
| ECS_QUOTA_ERROR_REASONS = [ |
There was a problem hiding this comment.
Since these are ECS specific they shouldn't really be in the base_aws module.
There was a problem hiding this comment.
Not sure what to do here. It feels weird to move this to ecs.py if I have code in base_aws.py that catches ECSOperatorError. For now, I've moved this variable into the is_permissible_error() scope to clarify intent. Any suggestions are welcomed.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| """ | ||
| def decorator_f(self): | ||
| quota_retry = getattr(self, 'quota_retry', None) |
There was a problem hiding this comment.
Not sure about this parameter name -- it seems very specific to EcsOperator only.
There was a problem hiding this comment.
Good point. Hm I've changed it to retry_args to be more generic, but I'm open to any suggestions.
Uh oh!
There was an error while loading. Please reload this page.
markhopson
commented
Mar 6, 2021
@ashb Friendly bump here |
ashb
commented
Mar 6, 2021
Thanks, I'll take a look on Monday |
| return self.get_client_type("iam").get_role(RoleName=role)["Role"]["Arn"] | ||
| @staticmethod | ||
| def retry(fun: Callable): |
There was a problem hiding this comment.
If we change this to
defretry(should_retry: Callable[[Exception], bool], fun: Callable)Then the retry_if_permissible_error can move out of BaseAWS in to ECSHook, used like this:
defshould_retry(exception: Exception):
"""Check if exception is related to ECS resource quota (CPU, MEM)."""returnisinstance(exception, ECSOperatorError) andany(
quota_reasoninfailure['reason']
forquota_reasonin ['RESOURCE:MEMORY', 'RESOURCE:CPU']
forfailureinexception.failures
)
...
@AwsBaseHook.retry(should_retry)def_start_task(self):There was a problem hiding this comment.
I wish I thought of this. I've made this change.
| limit. | ||
| """ | ||
| def decorator_f(self): |
There was a problem hiding this comment.
| defdecorator_f(self): | |
| @functools.wraps | |
| defdecorator_f(self, *args, **kwargs): |
ashb
commented
Mar 8, 2021
@markhopson See the review I just left -- I think that gives us a way to have the base retry functionality in the base hook, without having to put any service specific login in there. WDYT? |
markhopson
commented
Mar 10, 2021
@ashb Good tip. I like it. I've made the change. |
The Workflow run is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*. |
The Workflow run is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*. |
markhopson
commented
Mar 15, 2021
@ashb Friendly bump. |
ashb
left a comment
There was a problem hiding this comment.
Code looks good @markhopson
Could you fix up the static checks please?
The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest master or amend the last commit of the PR, and push it with --force-with-lease. |
ashb
commented
Mar 19, 2021
TestECSOperator.test_execute_with_failures is now failing becuase the type of the exception it throws has changed -- I think that's fine, and the tests just need updating. I haven't look in detail at the code/test though. |
Awesome work, congrats on your first merged pull request! |
This PR allows users to enable retry-behaviour for
ECSOperator._start_task.This feature was discussed briefly: here #13725
The design was lifted from
hooks/base_google.py. There's 2 main differences with my AWS implementation ...the user can configure the retry with a param
quota_retry(Dict) that is passed in to theECSOperatorthe user can configure the retry without tenacity (e.g. passing in
max=300andmultiplier=1instead oftenacity.wait_exponential(multiplier=1, max=300)