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-6843] Add delete_option_kwargs to delete_namespaced_pod #7523

Merged
merged 20 commits into from
Feb 26, 2020

Conversation

petedejoy
Copy link
Contributor

@petedejoy petedejoy commented Feb 24, 2020


Issue link: AIRFLOW-6843

If you're using the Kubernetes executor, Amazon EKS deletes pods very quickly after tasks complete. This can be an issue if you're scraping Airflow logs from a service like FluentD, as it means that the task pod gets deleted before FluentD can pick up logs for fast-running (or fast-failing) tasks.

The kube_client_request_args environment variable is passed to the delete_namespaced_pod client request, but we need a way to pass the grace_period_seconds param (and potentially others) to the V1DeleteOptions included in the body of the request. Towards that objective, I've created a delete_option_kwargs object that can be set via an Airflow environment variable. This is object is then passed to the V1DeleteOptions of the delete_namespaced_pods request.

This can be set via an AIRFLOW__KUBERNETES__DELETE_OPTION_KWARGS env var. The value should be JSON and can contain any of the options available in the Kube client V1DeleteOptions class.
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 area:Scheduler including HA (high availability) scheduler k8s labels Feb 24, 2020
@dimberman
Copy link
Contributor

@petedejoy can you fix the conflicts?

@dimberman dimberman changed the title [AIRFLOW-6843] Add delete_option_kwargs to V1DeleteOptions of kube client delete_namespaced_pod request [AIRFLOW-6843] Add delete_option_kwargs to delete_namespaced_pod Feb 24, 2020
@dimberman dimberman self-requested a review February 24, 2020 16:29
@dimberman
Copy link
Contributor

@petedejoy if you want a unit test for this, you can set the timeout to 15 seconds and make sure that once a pod completes it stays up for 15 seconds. @kaxil do you think a test is necessary here?

@codecov-io
Copy link

codecov-io commented Feb 25, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@b6a11c1). Click here to learn what that means.
The diff coverage is 93.18%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #7523   +/-   ##
=========================================
  Coverage          ?   86.85%           
=========================================
  Files             ?      896           
  Lines             ?    42638           
  Branches          ?        0           
=========================================
  Hits              ?    37035           
  Misses            ?     5603           
  Partials          ?        0
Impacted Files Coverage Δ
airflow/utils/helpers.py 82.6% <100%> (ø)
airflow/settings.py 93.66% <100%> (ø)
airflow/models/dagbag.py 89.61% <100%> (ø)
...s/google/cloud/example_dags/example_stackdriver.py 100% <100%> (ø)
airflow/models/taskinstance.py 95.17% <100%> (ø)
...ow/providers/microsoft/azure/hooks/azure_cosmos.py 76.72% <100%> (ø)
airflow/providers/amazon/aws/hooks/s3.py 96.6% <100%> (ø)
...ow/providers/google/cloud/operators/stackdriver.py 100% <100%> (ø)
airflow/models/dag.py 91.37% <100%> (ø)
airflow/utils/log/logging_mixin.py 95.38% <100%> (ø)
... and 7 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 b6a11c1...e13f6c1. Read the comment docs.

@kaxil kaxil requested a review from ashb February 25, 2020 00:04
https://github.com/kubernetes-client/python/blob/41f11a09995efcd0142e25946adc7591431bfb2f/kubernetes/client/models/v1_delete_options.py#L19
version_added: ~
type: string
example: "{{\"grace_period_seconds\": 10}}"
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't affect the output, but could be done as:

Suggested change
example: "{{\"grace_period_seconds\": 10}}"
example: '{{"grace_period_seconds": 10}}'

Also: OH GOD. Do we show this as { or {{ when we render the docs. Becasuse it needs to be { -- {{ is only needed in default_airflow.cfg because that is a template, but we should show in our docs is not templated/formated.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we need to update the pre-commit script to replace { with {{ and } with }} so that this and the default_airflow.cfg are correct.

Copy link
Member

Choose a reason for hiding this comment

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

It is tricky because of task_log_prefix_template = {{ti.dag_id}}-{{ti.task_id}}-{{execution_date}}-{{try_number}}. It would replcae it too task_log_prefix_template = {{{{ti.dag_id}}}}-{{{{ti.task_id}}}}-{{{{execution_date}}}}-{{{{try_number}}}}

Maybe we need to update the pre-commit script to replace { with {{ and } with }} so that this and the default_airflow.cfg are correct.

Copy link
Member

Choose a reason for hiding this comment

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

Updated !

setup.py Outdated Show resolved Hide resolved
This reverts commit a4438f7.
@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@b6a11c1). Click here to learn what that means.
The diff coverage is 93.18%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #7523   +/-   ##
=========================================
  Coverage          ?   86.85%           
=========================================
  Files             ?      896           
  Lines             ?    42638           
  Branches          ?        0           
=========================================
  Hits              ?    37035           
  Misses            ?     5603           
  Partials          ?        0
Impacted Files Coverage Δ
airflow/utils/helpers.py 82.6% <100%> (ø)
airflow/settings.py 93.66% <100%> (ø)
airflow/models/dagbag.py 89.61% <100%> (ø)
...s/google/cloud/example_dags/example_stackdriver.py 100% <100%> (ø)
airflow/models/taskinstance.py 95.17% <100%> (ø)
...ow/providers/microsoft/azure/hooks/azure_cosmos.py 76.72% <100%> (ø)
airflow/providers/amazon/aws/hooks/s3.py 96.6% <100%> (ø)
...ow/providers/google/cloud/operators/stackdriver.py 100% <100%> (ø)
airflow/models/dag.py 91.37% <100%> (ø)
airflow/utils/log/logging_mixin.py 95.38% <100%> (ø)
... and 7 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 b6a11c1...e13f6c1. Read the comment docs.

@kaxil kaxil requested review from dimberman and ashb February 25, 2020 23:58
@kaxil kaxil merged commit 676c851 into apache:master Feb 26, 2020
galuszkak pushed a commit to FlyrInc/apache-airflow that referenced this pull request Mar 5, 2020
@ashb ashb added this to the Airflow 1.10.12 milestone Jul 15, 2020
kaxil pushed a commit that referenced this pull request Aug 14, 2020
kaxil pushed a commit that referenced this pull request Aug 15, 2020
kaxil pushed a commit that referenced this pull request Aug 15, 2020
cfei18 pushed a commit to cfei18/incubator-airflow that referenced this pull request Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:dev-tools area:Scheduler including HA (high availability) scheduler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants