Skip to content

Creating on_warning_callback arg for better warning management#225

Merged
jlaneve merged 78 commits into
astronomer:mainfrom
CorsettiS:main
May 1, 2023
Merged

Creating on_warning_callback arg for better warning management#225
jlaneve merged 78 commits into
astronomer:mainfrom
CorsettiS:main

Conversation

@CorsettiS
Copy link
Copy Markdown
Contributor

@CorsettiS CorsettiS commented Apr 5, 2023

In airflow, errors are handled by default with callback functions and/or email alerts, however when we are integrating DBT with airflow, there is an extra case to consider: warnings
When running tests against a dataset, it would be really interesting to also add the possibility to communicate the WARN messages that got triggered in some way, since so far the WARNs can only be found inside the logs, which is no different from a blackbox for companies dealing with many DAGs. We should communicate if a warn is observed in the logs in a more transparent way.

To accomplish that, we can change the DbtTestOperator by adding 1 extra param to it

on_warning_callback (default = None)

(Updating after suggestion)

@CorsettiS CorsettiS requested a review from a team as a code owner April 5, 2023 17:12
Copy link
Copy Markdown
Contributor

@jlaneve jlaneve left a comment

Choose a reason for hiding this comment

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

Hey @CorsettiS, this is an amazing idea! I think it may be a bit too opinionated in terms of how we're handling the behavior when there's a warning. What do you think about the following:

  • instead of baking the send_slack_alert function directly into the package, what if we make a more general on_warning_callback? Or even an on_completion_callback where we pass in context about the dbt output and let the user decide what they'd like to do with it
  • add documentation about how to use the callback to send alerts on failure - that's where we can provide the code snippet on how to send a message in slack, for example

I think that'd be helpful to extend this functionality past slack - maybe someone wants to use the same pattern to send an email, etc.

What do you think?

@CorsettiS
Copy link
Copy Markdown
Contributor Author

Hey @CorsettiS, this is an amazing idea! I think it may be a bit too opinionated in terms of how we're handling the behavior when there's a warning. What do you think about the following:

  • instead of baking the send_slack_alert function directly into the package, what if we make a more general on_warning_callback? Or even an on_completion_callback where we pass in context about the dbt output and let the user decide what they'd like to do with it
  • add documentation about how to use the callback to send alerts on failure - that's where we can provide the code snippet on how to send a message in slack, for example

I think that'd be helpful to extend this functionality past slack - maybe someone wants to use the same pattern to send an email, etc.

What do you think?

hey @jlaneve I really liked the idea of creating a on_warning_callback. Guess I was too focused on my specific problem with slack. I will check during the week how feasible it is to implement it, adding some documentation on the way !

@CorsettiS CorsettiS changed the title Send WARN notifications from tests to slack Creating on_warning_callback arg for better warning management Apr 6, 2023
@CorsettiS
Copy link
Copy Markdown
Contributor Author

CorsettiS commented Apr 7, 2023

Since the image will only be rendered once the PR is merged, I will attach here an image of how the documentation would look like with it.
Screenshot 2023-04-07 at 18 48 48

Update (2022-04-08):

  • I have run many tests and so far everything worked
  • Recently improved the syntax to increase code performance

@jlaneve I am done on this side. If there is anything you would recommend me to change, I am all ears.

Update (2022-04-13):

  • I have merged the latest commits (including the Docker & K8s versions).
  • For the Local executor, the changes are working fine. I could not create the test env locally for the docker & k8s ones tho, which made it not possible for me to create the proper adaptions. Furthermore, I feel that even if I could test locally, I would have to tackle the problem in a total different way due to the way the new operators work. As of now, I will leave this feature available only for the Local execution mode then. If anyone feels interested in adapting the code, feel free to do it, otherwise I may look it up in a future date to adapt it to the other execution modes

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2023

Codecov Report

Patch coverage: 56.31% and project coverage change: -2.34 ⚠️

Comparison is base (400c01a) 79.76% compared to head (07ff0d3) 77.42%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #225      +/-   ##
==========================================
- Coverage   79.76%   77.42%   -2.34%     
==========================================
  Files          28       30       +2     
  Lines        1003     1094      +91     
==========================================
+ Hits          800      847      +47     
- Misses        203      247      +44     
Impacted Files Coverage Δ
...providers/dbt/core/utils/adapted_subprocesshook.py 30.23% <30.23%> (ø)
cosmos/providers/dbt/core/operators/local.py 48.50% <40.90%> (-2.78%) ⬇️
cosmos/providers/dbt/core/utils/warn_parsing.py 92.85% <92.85%> (ø)
cosmos/providers/dbt/core/operators/docker.py 69.76% <100.00%> (+0.35%) ⬆️
cosmos/providers/dbt/core/operators/kubernetes.py 72.04% <100.00%> (+0.30%) ⬆️
cosmos/providers/dbt/dag.py 75.00% <100.00%> (ø)
cosmos/providers/dbt/render.py 94.56% <100.00%> (+0.05%) ⬆️
cosmos/providers/dbt/task_group.py 75.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment thread cosmos/providers/dbt/core/utils/warn_parsing.py
@CorsettiS CorsettiS requested a review from jlaneve April 29, 2023 12:10
Copy link
Copy Markdown
Contributor

@jlaneve jlaneve left a comment

Choose a reason for hiding this comment

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

just one more small change - then this is good to merge! thank you for iterating on this

Comment thread cosmos/providers/dbt/core/utils/adapted_subprocesshook.py Outdated
@CorsettiS CorsettiS requested a review from jlaneve May 1, 2023 05:37
@jlaneve jlaneve merged commit df9d039 into astronomer:main May 1, 2023
tatiana added a commit that referenced this pull request Sep 18, 2025
[Giovanni Corsetti
Silva](https://www.linkedin.com/in/giovanni-corsetti/) (@corsettigyg
@CorsettiS @giovannicorsetti) is a Core Data Platform Data Engineer at
[Get Your Guide](https://www.getyourguide.com/). He's a Brazilian based
in Berlin (Germany) and has been an early adopter of Cosmos, using it
regularly throughout his career.

Not only has he been using Cosmos since the early stages, but he has
consistently improved Cosmos since April 2023:

<img width="494" height="249" alt="Screenshot 2025-09-17 at 16 39 49"
src="https://github.com/user-attachments/assets/ff9b0055-7df6-47a4-8efa-83a30d5aee99"
/>
] m. ,
<img width="492" height="252" alt="Screenshot 2025-09-17 at 16 40 11"
src="https://github.com/user-attachments/assets/8402d883-eff4-46aa-9ae7-afe35bd39a6e"
/>

<img width="499" height="256" alt="Screenshot 2025-09-17 at 16 39 23"
src="https://github.com/user-attachments/assets/c6b84245-aae1-46e6-99e3-552553619dd9"
/>

His contributions include new features, enhancements, bug fixes and also
improvements on the local dev setup, as it can see in some of the many
contributions he's done to the project so far:

* #1787
* #1761
* #1695 
* #1693 
* #1663
* #1571
* #1449
* #1099
* #1091
* #419
* #402
* #355 
* #354 
* #225 

Additionally, he has been interacting with users in the #airflow-dbt
Slack channel in a very collaborative and supportive way.

We want to promote him as a Cosmos committer and maintainer for all
these, recognising his constant efforts and achievements towards our
community. Thank you very much, @corsettigyg!

From this moment, you have write permissions on the repo:
<img width="884" height="93" alt="Screenshot 2025-09-18 at 14 34 07"
src="https://github.com/user-attachments/assets/abcc8c42-87cf-4b32-a7be-81127190d164"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants