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

Kubernetes on warning callback #673

Merged
merged 12 commits into from
Nov 22, 2023

Conversation

david-mag
Copy link
Contributor

@david-mag david-mag commented Nov 14, 2023

Description

In order to make on_warning_callback work with pod operators, we need to read the logs of the dbt test runs. This is done by making sure the pod is kept alive, and on_success_callback the log is read and anlayzed for warnings.
Afterwards the pod is cleaned up, based on the original settings from the user.

If on_warning_callback is not set, everything stays the way it always was.

I've tested the changes in my dev environment, but haven't added any new tests, since this would be something (I think) we would need to add integration tests for.

Checklist

  • I have made corresponding changes to the documentation (if required)
  • I have added tests that prove my fix is effective or that my feature works

@david-mag david-mag requested a review from a team as a code owner November 14, 2023 22:20
@david-mag david-mag requested a review from a team November 14, 2023 22:20
Copy link

netlify bot commented Nov 14, 2023

👷 Deploy Preview for amazing-pothos-a3bca0 processing.

Name Link
🔨 Latest commit af2314e
🔍 Latest deploy log https://app.netlify.com/sites/amazing-pothos-a3bca0/deploys/655d6560f3f37d00087ae378

@dosubot dosubot bot added area:execution Related to the execution environment/mode, like Docker, Kubernetes, Local, VirtualEnv, etc dbt:test Primarily related to dbt test command or functionality execution:kubernetes Related to Kubernetes execution environment labels Nov 14, 2023
Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (a83911f) 92.88% compared to head (f91ac6c) 92.93%.

❗ Current head f91ac6c differs from pull request most recent head af2314e. Consider uploading reports for the commit af2314e to get more accurate results

Files Patch % Lines
cosmos/operators/kubernetes.py 95.74% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #673      +/-   ##
==========================================
+ Coverage   92.88%   92.93%   +0.04%     
==========================================
  Files          55       55              
  Lines        2248     2292      +44     
==========================================
+ Hits         2088     2130      +42     
- Misses        160      162       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@tatiana tatiana left a comment

Choose a reason for hiding this comment

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

Hey, @david-mag, this looks very good - it's great to have feature parity to use on_warning_callback on Kubernetes.

I'm apprehensive about the need for tests. An integration test would be ideal - and we could do that once #535 is completed.

In the meantime, how would you feel about adding some unit tests to the new methods and the class constructor?

@david-mag
Copy link
Contributor Author

david-mag commented Nov 15, 2023

I've added some unit-tests that (I hope) will cover my additions to the DbtTestKubernetesOperator. I had to, however, add a condition to skip the test for airflow version 2.3, because there the OnFinishAction from airflow.providers.cncf.kubernetes.utils.pod_manager doesn't exist yet.

So using on_warning_callback will only be possible from airflow version 2.4 and up.

@tatiana tatiana added this to the 1.2.5 milestone Nov 16, 2023
Copy link
Collaborator

@tatiana tatiana left a comment

Choose a reason for hiding this comment

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

@david-mag thanks for the contribution!

This will improve K8s users experience!

There will be scenarios when OnFinishAction won't be defined. If the user sets on_warning_callback and uses ExecutionMode.KUBERNETES, DbtTestKubernetesOperator will only work if users use apache-airflow-providers-cncf-kubernetes >= 7.4.0. I believe this is a fine compromise, considering that before this PR on_warning_callback wasn't working for any version of the provider when users used ExecutionMode.KUBERNETES.

@tatiana tatiana merged commit 0b538a5 into astronomer:main Nov 22, 2023
39 checks passed
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 22, 2023
This was referenced Nov 23, 2023
@tatiana
Copy link
Collaborator

tatiana commented Nov 23, 2023

pull bot pushed a commit to pgoslatara/astronomer-cosmos that referenced this pull request Nov 24, 2023
Bug fixes

* Fix running models that use alias while supporting dbt versions by
@binhnq94 in astronomer#662
* Make profiles_yml_path optional for ExecutionMode.DOCKER and
KUBERNETES by @MrBones757 in astronomer#681
* Prevent overriding dbt profile fields with profile args of type or
method by @jbandoro in astronomer#702
* Fix LoadMode.DBT_LS fail when dbt outputs WarnErrorOptions by
@adammarples in astronomer#692
* Add support for env vars in RenderConfig for dbt ls parsing by
@jbandoro in astronomer#690
* Add support for Kubernetes on_warning_callback by @david-mag in astronomer#673
* Fix ExecutionConfig.dbt_executable_path to use ``default_factory`` by
@jbandoro in astronomer#678

Others

* Docs fix: example DAG in the README and docs/index by @tatiana in astronomer#705
* Docs improvement: highlight DAG examples in README by @iancmoritz and
@jlaneve in astronomer#695

(cherry picked from commit 2878d6a)
arojasb3 pushed a commit to arojasb3/astronomer-cosmos that referenced this pull request Jul 14, 2024
To make `on_warning_callback` work with pod operators, we need
to read the logs of the dbt test runs. This is done by ensuring the
pod is kept alive, and `on_success_callback` the log is read and
analysed for warnings.

Afterwards, the pod is cleaned up based on the original settings from
the user.

If `on_warning_callback` is not set, everything stays the way it always
was.

This feature only work with `apache-airflow-providers-cncf-kubernetes >= 7.4.0`.
arojasb3 pushed a commit to arojasb3/astronomer-cosmos that referenced this pull request Jul 14, 2024
Bug fixes

* Fix running models that use alias while supporting dbt versions by
@binhnq94 in astronomer#662
* Make profiles_yml_path optional for ExecutionMode.DOCKER and
KUBERNETES by @MrBones757 in astronomer#681
* Prevent overriding dbt profile fields with profile args of type or
method by @jbandoro in astronomer#702
* Fix LoadMode.DBT_LS fail when dbt outputs WarnErrorOptions by
@adammarples in astronomer#692
* Add support for env vars in RenderConfig for dbt ls parsing by
@jbandoro in astronomer#690
* Add support for Kubernetes on_warning_callback by @david-mag in astronomer#673
* Fix ExecutionConfig.dbt_executable_path to use ``default_factory`` by
@jbandoro in astronomer#678

Others

* Docs fix: example DAG in the README and docs/index by @tatiana in astronomer#705
* Docs improvement: highlight DAG examples in README by @iancmoritz and
@jlaneve in astronomer#695

(cherry picked from commit 2878d6a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:execution Related to the execution environment/mode, like Docker, Kubernetes, Local, VirtualEnv, etc dbt:test Primarily related to dbt test command or functionality execution:kubernetes Related to Kubernetes execution environment size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants