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

[AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs #7400

Merged
merged 6 commits into from Feb 17, 2020

Conversation

MarkYHZhang
Copy link
Contributor

@MarkYHZhang MarkYHZhang commented Feb 11, 2020

Added MLEngineTrainingJobFailureOperator with cancel_job hook for MLEngine.


Issue link: AIRFLOW-6759

Make sure to mark the boxes below before creating PR: [x]

  • Description above provides context of the change
  • Commit message/PR title starts with [AIRFLOW-NNNN]. AIRFLOW-NNNN = JIRA ID*
  • Unit tests coverage for changes (not needed for documentation changes)
  • Commits follow "How to write a good git commit message"
  • Relevant documentation is updated including usage instructions.
  • I will engage committers as explained in Contribution Workflow Example.

* For document-only changes commit message can start with [AIRFLOW-XXXX].


In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.
Read the Pull Request Guidelines for more information.

@boring-cyborg boring-cyborg bot added the provider:google Google (including GCP) related issues label Feb 11, 2020
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 11, 2020

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

  • Pay attention to the quality of your code (flake8, pylint 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.
    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://apache-airflow-slack.herokuapp.com/

@turbaszek turbaszek requested review from turbaszek and mik-laj and removed request for turbaszek February 11, 2020 16:11
Cancels a MLEngine job.

:param project_id: The Google Cloud project id within which MLEngine
job will be launched. If set to None or missing, the default project_id from the GCP

Choose a reason for hiding this comment

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

This comment (describing the behaviour when project_id is None) is inconsistent with the code below.

Added types for `job_id`

Co-Authored-By: Tomek Urbaszek <turbaszek@gmail.com>
training job. (templated)
:type job_id: str
:param project_id: The Google Cloud project name within which MLEngine training job should run.
If set to None or missing, the default project_id from the GCP connection is used. (templated)

Choose a reason for hiding this comment

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

Same as the comment above, it seems like the code raises an error if project_id is none/missing.

Copy link
Member

Choose a reason for hiding this comment

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

All operators except BigQuery allow passing project_id as a parameter. However, if this parameter is omitted, the default value will be read from the credentials.
https://github.com/apache/airflow/blob/97a429f/airflow/providers/google/cloud/hooks/base.py#L334-L360
It is very difficult to authorize and not get project_id. This is not even possible with production deployment. You may not have project_id when using gcloud for authorization only.

template_fields = [
'_project_id',
'_job_id',
]
Copy link
Member

Choose a reason for hiding this comment

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

Let use tuple here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an option, but I thought it'd be better to maintain consistency between the operators (all other ones uses an array). Unless, there is some other non-style related reasons?

Copy link
Member

Choose a reason for hiding this comment

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

It varies. But in my opinion, this is immutable field :)

if not self._project_id:
raise AirflowException('Google Cloud project id is required.')
if not self._job_id:
raise AirflowException(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise AirflowException(

No need for that as job_id is required parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uhmm, I'm not super sure why it was raised either, but I see the same checking in MLEngineStartBatchPredictionJobOperator and MLEngineStartTrainingJobOperator. And I thought I better include it as well 😅

Copy link
Member

Choose a reason for hiding this comment

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

MLEngineOperators are not best ones :D

cleaner formating

Co-Authored-By: Tomek Urbaszek <turbaszek@gmail.com>
@codecov-io
Copy link

codecov-io commented Feb 11, 2020

Codecov Report

Merging #7400 into master will decrease coverage by 0.13%.
The diff coverage is 87.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7400      +/-   ##
==========================================
- Coverage    86.5%   86.37%   -0.14%     
==========================================
  Files         873      878       +5     
  Lines       40725    41189     +464     
==========================================
+ Hits        35231    35576     +345     
- Misses       5494     5613     +119
Impacted Files Coverage Δ
airflow/providers/google/cloud/hooks/mlengine.py 82.25% <82.35%> (ø) ⬆️
...rflow/providers/google/cloud/operators/mlengine.py 89.66% <92.85%> (+0.15%) ⬆️
airflow/kubernetes/volume_mount.py 44.44% <0%> (-55.56%) ⬇️
airflow/kubernetes/volume.py 52.94% <0%> (-47.06%) ⬇️
airflow/kubernetes/pod_launcher.py 47.18% <0%> (-45.08%) ⬇️
...viders/cncf/kubernetes/operators/kubernetes_pod.py 69.38% <0%> (-24.23%) ⬇️
airflow/kubernetes/refresh_config.py 50.98% <0%> (-23.53%) ⬇️
airflow/utils/sqlalchemy.py 84.93% <0%> (-11.74%) ⬇️
airflow/config_templates/airflow_local_settings.py 65.38% <0%> (-6.36%) ⬇️
airflow/stats.py 85.29% <0%> (-5.19%) ⬇️
... and 28 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0fa964...e815aac. Read the comment docs.

@turbaszek turbaszek merged commit 2c9345a into apache:master Feb 17, 2020
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 17, 2020

Awesome work, congrats on your first merged pull request!

galuszkak pushed a commit to FlyrInc/apache-airflow that referenced this pull request Mar 5, 2020
…pache#7400)

* [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

* Update airflow/providers/google/cloud/hooks/mlengine.py

Added types for `job_id`

Co-Authored-By: Tomek Urbaszek <turbaszek@gmail.com>

* Updates cancel_job doc

* Update airflow/providers/google/cloud/hooks/mlengine.py

cleaner formating

Co-Authored-By: Tomek Urbaszek <turbaszek@gmail.com>

* removed redundant error checking

Co-authored-by: Tomek Urbaszek <turbaszek@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
provider:google Google (including GCP) related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants