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

Refactor monolithic ECS Operator into Operators, Sensors, and a Hook #25413

Merged
merged 7 commits into from
Aug 9, 2022

Conversation

ferruzzi
Copy link
Contributor

The current EcsOperator is monolithic, does not have a hook, nor any sensors. This PR adds an ECS hook, modifies the existing EcsOperator to use it, adds a handful of other operators and sensors. The functionality of the existing EcsOperator was changed as little as possible. A future refactor of that operator might not be a bad idea, but adding the hook and sensors is the main goal of this PR.

Other changes:

  • Moved some methods from the EcsOperator module into the new EcsHook module as that felt like a better home for them.
  • Removes some old code that has been deprecated for multiple major releases.
    • airflow/contrib/operators/ecs_operator.py was deprecated over 2 years ago
    • tests/providers/amazon/aws/operators/test_ecs_system.py is also a few years old and not a proper system test by current standards.
  • Deprecates the name EcsOperator in favor of EcsRunTaskOperator to match the standard naming conventions since there are now multiple ECS-related operators.

closes: #24826

@ferruzzi
Copy link
Contributor Author

Looks like I missed removing a deprecation somewhere, looking into it.

@ferruzzi
Copy link
Contributor Author

Sorry about that, all passing now. 👍

Copy link
Contributor

@eladkal eladkal left a comment

Choose a reason for hiding this comment

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

There are several places where code is removed.
We should deprecate first

@@ -1,30 +0,0 @@
#
Copy link
Contributor

@eladkal eladkal Jul 30, 2022

Choose a reason for hiding this comment

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

This file can be removed only in Airflow 3 as its part of Airflow core so we can not remove it yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it's so olllllldddddddd. Git Blame shows that it was deprecated at least 2 years ago. If it needs to stay, I'll add it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I revert this, what is the best way to handle it? Should I import all of the new ECS Operators fro this PR and add them to __all__, or only update the names of the ones which were already included in there?

Copy link
Contributor

@eladkal eladkal Aug 2, 2022

Choose a reason for hiding this comment

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

Regardless contrib files cant not be removed. In this specific case we must be backward compatible till Airflow 3

As for your question - in this file you need to support only classes that existed. We dont add new functionality

Copy link
Member

Choose a reason for hiding this comment

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

I have an idea for the future. Should we move alll the deprecated/contrib operators from 1.10 out to a separate "apache-contrib" package (when we split out providers).

That will allow to get rid of the contrib, and get rid of many 1.10 deprecations out of airlfow main repo at least (it can still be a dependency of Airflow package so that it is installed automatically when airflow is installed). @ashb @kaxil WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eladkal - @potiuk mentioned wanting to get a provider package release out and Amazon would be getting a major release, I'm hoping to get this in on that but I'm not really sure what needs to be done here now. Any help would be appreciated.

Copy link
Contributor

Choose a reason for hiding this comment

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

It will take me a few days to get to this

Copy link
Member

Choose a reason for hiding this comment

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

I can take this one. But you need to rebase @ferruzzi - this one has problems from few days back when we fixed Flask 2.2 compatibility:

image

Copy link
Contributor Author

@ferruzzi ferruzzi Aug 5, 2022

Choose a reason for hiding this comment

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

ACK. Will rebase and do a force-push. Done.

Thanks to both of you for the help.

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 was a bit confused on how that chain of depredations should play out, but now with #25543 I'm doubly confused on how the two will interact.

@ferruzzi
Copy link
Contributor Author

ferruzzi commented Aug 2, 2022

There are several places where code is removed. We should deprecate first

Unless I made a mistake, I only removed code which has been deprecated for quite some time.

[edit]
Check me if I've missed something:

Deleted:

  • airflow/contrib/operators/ecs_operator.py. Was included in the first version of airflow.tests.deprecated_classes from 6/19/20 so deprecated over two years ago (Discussed above, reverting this change)
  • 'airflow.providers.amazon.aws.operators.ecs.EcsOperator.execute._xcom_set`: "private" method replaced inline with xcom_push
  • ECSOperator deprecation class: git blame shows it has been deprecated for one major release on the provider package
  • ECSTaskLogFetcher deprecation class: same as above
  • ECSProtocol deprecation class: same as above
  • tests/providers/amazon/aws/operators/test_ecs_system.py - This is from before AIP-47 and not how system tests work now. Once these changes are merged a new AIP-47-compliant system test will be added, but this PR felt like it was getting a little out of hand without also making those changes.

Moved or Renamed and deprecated:

  • airflow.providers.amazon.aws.operators.ecs.EcsProtocol
  • airflow.providers.amazon.aws.operators.ecs.EcsTaskLogFetcher
  • airflow.providers.amazon.aws.operators.ecs.EcsOperator

Moved from operator to the new hook but not deprecated:

I feel these two are "private" methods, though they don't have the underscore. I can definitely add deprecation classes for them if you'd like.

  • airflow.providers.amazon.aws.operators.ecs.should_retry
  • airflow.providers.amazon.aws.operators.ecs.should_retry_eni

@ferruzzi
Copy link
Contributor Author

ferruzzi commented Aug 9, 2022

Rebased and fixed (??) the deprecation notice. This passes testing locally, let's see if it works.

@potiuk potiuk requested a review from eladkal August 9, 2022 17:53
@potiuk
Copy link
Member

potiuk commented Aug 9, 2022

If the tests pass, do you think we should be fine with releasing it in this upcoming wave of providers?

@potiuk
Copy link
Member

potiuk commented Aug 9, 2022

If the tests pass, do you think we should be fine with releasing it in this upcoming wave of providers?

Ah yeah. I see the comment now :)

@eladkal
Copy link
Contributor

eladkal commented Aug 9, 2022

If the tests pass, do you think we should be fine with releasing it in this upcoming wave of providers?

I wont have time today to review the code.. i didnt do full review when I left the comment.

If the PR is OK from your side dont let me get in the way :)
I can chime in tommorow if my review is required.

@ferruzzi
Copy link
Contributor Author

ferruzzi commented Aug 9, 2022

Alright, it just went green, so at least the CI is happy.

@jarek - My main reason for wanting it in this release was because it's removing deprecated code. Based on a chat with @eladkal, it doesn't sound like he thinks that's such a big deal. If you both think that isn't a good enough reason to hold up the release then by all means push on without it.

@potiuk
Copy link
Member

potiuk commented Aug 9, 2022

Hmm. Some conflicts after merging #25543 - will you rebase @ferruzzi ?

@ferruzzi ferruzzi force-pushed the ferruzzi/ecs-operator-cleanup branch from ea74ca3 to bbd6efb Compare August 9, 2022 20:46
@ferruzzi
Copy link
Contributor Author

ferruzzi commented Aug 9, 2022

@potiuk Rebase done, passes all CI and static tests locally

@potiuk potiuk merged commit 8a1b7d4 into apache:main Aug 9, 2022
@ephraimbuddy ephraimbuddy added the type:misc/internal Changelog: Misc changes that should appear in change log label Aug 15, 2022
Comment on lines +53 to +55
self.aws_conn_id = kwargs.get('aws_conn_id', DEFAULT_CONN_ID)
self.region = kwargs.get('region')
super().__init__(**kwargs)
Copy link
Contributor

@zachliu zachliu Aug 26, 2022

Choose a reason for hiding this comment

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

oh man, you passed all kwargs including the aws_conn_id to the BaseOperator
now 80% of my dags (i use EcsOperator heavily) are failing with

Broken DAG: [/usr/local/airflow/dags/my_dag.py] Traceback (most recent call last):
  File "/usr/local/airflow/.local/lib/python3.8/site-packages/airflow/models/baseoperator.py", line 390, in apply_defaults
    result = func(self, **kwargs, default_args=default_args)
  File "/usr/local/airflow/.local/lib/python3.8/site-packages/airflow/models/baseoperator.py", line 743, in __init__
    raise AirflowException(
airflow.exceptions.AirflowException: Invalid arguments were passed to EcsOperator (task_id: my-task). Invalid arguments were:
**kwargs: {'aws_conn_id': 'aws_default'}

is there a fix? will 2 simple pops do the job?

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm, #25989

@ephraimbuddy ephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) and removed type:misc/internal Changelog: Misc changes that should appear in change log labels Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) kind:documentation provider:amazon-aws AWS/Amazon - related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor/Review EcsOperator
6 participants