Skip to content

Fix Spark submit standalone status polling to use correct REST endpoint - #71949

Merged
eladkal merged 29 commits into
apache:mainfrom
hunnguye:fix/spark-submit-standalone-status-polling
Oct 8, 2026
Merged

eladkal merged 29 commits into
apache:mainfrom
hunnguye:fix/spark-submit-standalone-status-polling

Conversation

@hunnguye

@hunnguye hunnguye commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Short Description

Using the SparkSubmitOperator to submit an applicaiton to a Spark standalone cluster results in Failed to poll for the driver status 10 times: returncode = 1 even though the job finished correctly on the spark Server side.
The issue is caused by the current driver-status polling logic, which derives its behavior from the configured master URL but does not sufficiently distinguish between a master URL pointing to the RPC endpoint on port 7077 and one pointing to the REST endpoint on port 6066.

Changes:

  • add a rest_endpoint attribute into the connection dictionary, this contains the correct rest endpoint only if there is exactly one master endpoint
  • modified and extend _build_spark_driver_kill_command and _build_track_driver_status_command to apply the corrected rest_endpoint logic with minimal change to current behaviour if available, else fallback to using the spark submit binary without the rest endpoint
  • new rest_endpoint information has also been applied to the the operator job status request

Tests:

  • extended test cases with separate connection id for the rpc endpoint at 7077 and HA multiple master endpoints
  • fully tested against live spark standalone cluster successfully (status polling, killing, job retry)
  • developed using the breeze enviroment

Notes

  • operators/spark_submit.py assumes a comma separated list of master urls, but as I understand that is not possible as the hook itself always assumes a single url. I therefore ignored that assumption.
  • Although the kill operation could be handled entirely through the REST endpoint, I preserved the existing binary kill command to avoid unintended side effects.

Was generative AI tooling used to co-author this PR?
  • [X ] Yes (ChatGPT for brainstorming. I wrote most of the code, ChatGPT refactored minimally)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@boring-cyborg

boring-cyborg Bot commented Aug 21, 2026

Copy link
Copy Markdown

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
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks 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

@hunnguye hunnguye changed the title Fix/spark submit standalone status polling #71939 Fix/spark submit standalone status polling #71881 Aug 21, 2026
@hunnguye

Copy link
Copy Markdown
Contributor Author

I did notice PR #71939. However, by that point I had already finished the implementation on my side and only had testing left.

I believe both approaches are very similar. My implementation additionally reuses the REST endpoint logic in operator/spark_submit.py to avoid duplicating the endpoint construction.

One notable difference I noticed is that my implementation uses a POST request to kill the driver, following Spark's REST API behavior. PR #71939 appears to use DELETE. I'm not sure whether DELETE is also supported here, but POST is what I tested successfully against the Spark Standalone REST endpoint.

Besides that there are some minor implementation differences.
I’d be happy to compare the approaches and collaborate on a combined solution.

@aaron-y-chen aaron-y-chen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi, thanks for the contribution! I've contributed to the Spark provider in the past too, so I hope these review comments are helpful :)

Also, please fix the CI errors. The PR can't be merged until all CI checks pass.

@hunnguye

Copy link
Copy Markdown
Contributor Author

Thanks for your supportive insights and review!

@hunnguye

Copy link
Copy Markdown
Contributor Author

Although _StandaloneSparkSubmitBackend.get_job_status() supports multiple master URLs in connection["master"], I chose to follow the hook’s current assumption that connection["master"] contains a single URL and constructed connection["rest_endpoint"] accordingly.

I could also have added support for rest_endpoint to handle either a single URL or a comma-separated list of master urls, but that would conflict with the assumption above. I think doing this properly would also require refactoring the usages of connection["master"], either always assume a comma separated list of master url of datatype string or already providing a list of master urls (which results in just one element if not in HA). However, that feels outside the scope of this PR.

@hunnguye hunnguye changed the title Fix/spark submit standalone status polling #71881 Fix Spark submit standalone status polling to use correct REST endpoint Sep 4, 2026

@aaron-y-chen aaron-y-chen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall it looks good, please help fix the CI error, and I have one more comment :)

@aaron-y-chen aaron-y-chen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall, LGTM. Thanks for your hard work! :)
It needs another look from a committer who is familiar with Spark.

@shahar1

shahar1 commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Note to reviewer: #71939 is a competing PR

@Nataneljpwd Nataneljpwd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great, a little hard to choose between the competing pr's, if you could answer my questions it would be appreciated, thank you!

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me!

@eladkal
eladkal merged commit 88b83d1 into apache:main Oct 8, 2026
@boring-cyborg

ghost commented Oct 8, 2026

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SparkSubmitOperator fails to poll driver status in Spark Standalone cluster mode

5 participants