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

Fix automatic termination issue in EmrOperator by ensuring waiter_max_attempts is set for deferrable triggers #38658

Merged
merged 9 commits into from
May 21, 2024

Conversation

beobest2
Copy link
Contributor

@beobest2 beobest2 commented Apr 1, 2024

When running EMR jobs that require a long duration, setting the waiter_max_attempts in EmrOperator to a high value does not prevent the "waiter error: max attempts" error from occurring after a certain period.

[2024-03-27 16:42:08,646] Trigger failed:
Traceback (most recent call last):

  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/jobs/triggerer_job_runner.py", line 529, in cleanup_finished_triggers
    result = details["task"].result()
             ^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/jobs/triggerer_job_runner.py", line 601, in run_trigger
    async for event in trigger.run():

  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/providers/amazon/aws/triggers/base.py", line 143, in run
    await async_wait(

  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/providers/amazon/aws/utils/waiter_with_logging.py", line 133, in async_wait
    raise AirflowException("Waiter error: max attempts reached")

An issue has been identified with the AWS provider code.
The EmrOperator that calls this trigger does not allow users to input waiter_max_attempts, resulting in the application of the default value of 600.

airflow/providers/amazon/aws/triggers/emr.py

class EmrContainerTrigger(AwsBaseWaiterTrigger):
    """
    Poll for the status of EMR container until reaches terminal state.
    :param virtual_cluster_id: Reference Emr cluster id
    :param job_id:  job_id to check the state
    :param aws_conn_id: Reference to AWS connection id
    :param waiter_delay: polling period in seconds to check for the status
    """

    def __init__(
        self,
        virtual_cluster_id: str,
        job_id: str,
        aws_conn_id: str | None = "aws_default",
        poll_interval: int | None = None,  # deprecated
        waiter_delay: int = 30,
        waiter_max_attempts: int = 600,   # <- We can't modify this ..
    ):

In other words, if the poll_interval is set to 60 seconds, the job will terminate after 10 hours (1 minute * 600) regardless of the waiter_max_attempts value specified by the user.

To address this, modifications were made in EmrOperator to ensure that parameters provided by the user are also passed to the EmrContainerTrigger.

@boring-cyborg boring-cyborg bot added area:providers provider:amazon-aws AWS/Amazon - related issues labels Apr 1, 2024
Copy link

boring-cyborg bot commented Apr 1, 2024

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 Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

Copy link

@matcha-1atte matcha-1atte left a comment

Choose a reason for hiding this comment

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

👍

Copy link

@matcha-1atte matcha-1atte left a comment

Choose a reason for hiding this comment

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

Good.

@eladkal
Copy link
Contributor

eladkal commented Apr 9, 2024

can you add unit tests to cover this change?

@beobest2
Copy link
Contributor Author

@eladkal I have also added unit tests. Please review

@o-nikolas
Copy link
Contributor

Tests need to pass after your rebase from main. Otherwise looks good to merge

@o-nikolas
Copy link
Contributor

Running workflows again after recent commits

@beobest2
Copy link
Contributor Author

beobest2 commented May 3, 2024

@o-nikolas Previously, I was unable to properly test in my development environment because different dependency errors occurred. After solving the problem and running tests, I found that when deferrable is set to True, the call_count is not recorded as many times as the actual number of attempts we specified. Do you have an idea how can we verify the call_count in a unit test when using deferrable as it is now?

@o-nikolas
Copy link
Contributor

@o-nikolas Previously, I was unable to properly test in my development environment because different dependency errors occurred. After solving the problem and running tests, I found that when deferrable is set to True, the call_count is not recorded as many times as the actual number of attempts we specified. Do you have an idea how can we verify the call_count in a unit test when using deferrable as it is now?

CC @syedahsn

Copy link
Contributor

@syedahsn syedahsn left a comment

Choose a reason for hiding this comment

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

Left a couple of comments. Thanks for looking into this!

@beobest2 beobest2 force-pushed the fix_deferrable_trigger branch 2 times, most recently from 9d48300 to b992536 Compare May 16, 2024 15:27
Copy link
Contributor

@syedahsn syedahsn left a comment

Choose a reason for hiding this comment

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

LGTM

@vincbeck vincbeck merged commit 49b3871 into apache:main May 21, 2024
41 checks passed
Copy link

boring-cyborg bot commented May 21, 2024

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

RNHTTR pushed a commit to RNHTTR/airflow that referenced this pull request Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers provider:amazon-aws AWS/Amazon - related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants