Skip to content

[AIRFLOW-6884] Make SageMakerTrainingOperator idempotent - #7598

Merged
kaxil merged 6 commits into
apache:masterfrom
BasPH:airflow-6884-sagemakertrainingoperator-idempotent
Mar 12, 2020
Merged

kaxil merged 6 commits into
apache:masterfrom
BasPH:airflow-6884-sagemakertrainingoperator-idempotent

Conversation

@BasPH

@BasPH BasPH commented Feb 29, 2020 •

Copy link
Copy Markdown
Contributor

The SageMakerTrainingOperator is currently not idempotent. AWS requires training jobs to have unique names, and training jobs cannot be deleted/updated. Rerunning a SageMakerTrainingOperator will currently raise an exception because it cannot create a training job with the same name.

Therefore I suggest to add an argument action_if_job_exists, which determines the behaviour in case the training job name already exists. Possible options are increment (default) and fail, where increment lists all training jobs prefixed with the given name and suffixes the name with length+1:

Rerunning will result in training job names:
mytrainingjob
mytrainingjob-2
mytrainingjob-3
....

(the training job name is returned - and thus in an XCom, so users can fetch the updated training job name in a successive task)

The fail mode will simply fail if a training job with the same name is encountered.

Additionally, this PR implements a generic method _list_request on the SageMakerHook, for performing list operations on boto3. All boto3 list_* methods follow the same structure and _list_request provides an easy interface to iteratively fetch all results (since AWS returns results in batches).


Issue link: AIRFLOW-6884

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.

@BasPH BasPH added the provider:amazon AWS/Amazon - related issues label Feb 29, 2020
@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #7598 into master will decrease coverage by 0.28%.
The diff coverage is 81.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7598      +/-   ##
==========================================
- Coverage   86.82%   86.53%   -0.29%     
==========================================
  Files         891      896       +5     
  Lines       42095    42740     +645     
==========================================
+ Hits        36549    36986     +437     
- Misses       5546     5754     +208
Impacted Files Coverage Δ
airflow/providers/amazon/aws/hooks/sagemaker.py 85.96% <76.47%> (-1.29%) ⬇️
...oviders/amazon/aws/operators/sagemaker_training.py 97.29% <93.33%> (-2.71%) ⬇️
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.69% <0%> (-25.21%) ⬇️
airflow/kubernetes/refresh_config.py 50.98% <0%> (-23.53%) ⬇️
airflow/utils/helpers.py 71.31% <0%> (-11.19%) ⬇️
airflow/__init__.py 92% <0%> (-8%) ⬇️
airflow/providers/google/cloud/operators/dlp.py 96.25% <0%> (-3.75%) ⬇️
... and 48 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 61a8bb6...05b51ce. Read the comment docs.

@kaxil
kaxil merged commit c0c5f11 into apache:master Mar 12, 2020
@BasPH
BasPH deleted the airflow-6884-sagemakertrainingoperator-idempotent branch March 30, 2020 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

provider:amazon AWS/Amazon - related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants