-
Notifications
You must be signed in to change notification settings - Fork 199
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
Improve error logging in DbtLocalBaseOperator #1004
Improve error logging in DbtLocalBaseOperator #1004
Conversation
Improve error logging when the `dbt` command returns a non-zero exit code. Instead of raising an `AirflowException` with the full output, log the output using the logger and then raise the exception with a concise error message. This makes the dbt output more readable and not in a single line.
✅ Deploy Preview for sunny-pastelito-5ecb04 canceled.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1004 +/- ##
==========================================
+ Coverage 95.65% 95.69% +0.03%
==========================================
Files 60 60
Lines 2925 2926 +1
==========================================
+ Hits 2798 2800 +2
+ Misses 127 126 -1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks much better, @davidsteinar , thanks a lot for the contribution!
Is there any chance we could add a test to make sure this improvement continues working as expected in the future?
@tatiana something like this? def test_handle_exception_subprocess():
"""
Test the handle_exception_subprocess method of the DbtLocalBaseOperator class.
"""
operator = DbtLocalBaseOperator(profile_config=None)
result = FullOutputSubprocessResult(exit_code=1, output="test", full_output=["n" * n for n in range(1, 1000)])
# Test when exit_code is non-zero
with pytest.raises(AirflowException) as err_context:
operator.handle_exception_subprocess(result)
assert len(err_context.value) < 100 # Ensure the error message is not too long |
Hi @davidsteinar I think you're in the right path - thank you! The one thing that could be improved is to use perhaps pytest Example: astronomer-cosmos/tests/test_cache.py Line 76 in cb2a27a
|
hi again @tatiana , better? def test_handle_exception_subprocess(caplog):
"""
Test the handle_exception_subprocess method of the DbtLocalBaseOperator class.
"""
operator = DbtLocalBaseOperator(profile_config=None)
result = FullOutputSubprocessResult(exit_code=1, output="test", full_output=["n" * n for n in range(1, 1000)])
caplog.set_level(logging.ERROR)
# Test when exit_code is non-zero
with pytest.raises(AirflowException) as err_context:
operator.handle_exception_subprocess(result)
assert len(str(err_context.value)) < 100 # Ensure the error message is not too long
assert len(caplog.text) > 1000 # Ensure the log message is not truncated |
Thanks, @davidsteinar , it's looking good. Could you please add it to: Once the tests are passing, we can merge this PR! Thanks a lot for your contribution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like unfortunately there is a minor conflict with main in the file tests/operators/test_local.py
. Could you please resolve the conflict and push the commit :) ?
Hi @pankajkoti , I fixed the conflict and a few small things to make the test run , all checks have passed now |
Thank you @davidsteinar for improving the exception and error logging. Appreciate the contribution and quick fixes 👏🏽 PR looks good to me. I'm going ahead with the merge cc: @tatiana |
Improve error logging when the `dbt` command returns a non-zero exit code. Instead of raising an `AirflowException` with the full output, log the output using the logger and then raise the exception with a concise error message. This makes the dbt output more readable and not in a single line as AirflowException logs message in a single line, and it can get very long. closes #1003 --------- Co-authored-by: David Steinar Asgrimsson <david-steinar.asgrimsson@kommuninvest.se> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Bug fixes * Fix the invocation mode for ``ExecutionMode.VIRTUALENV`` by @marco9663 in #1023 * Fix Cosmos ``enable_cache`` setting by @tatiana in #1025 * Make ``GoogleCloudServiceAccountDictProfileMapping`` dataset profile arg optional by @oliverrmaa and @pankajastro in #839 and #1017 * Athena profile mapping set ``aws_session_token`` in profile only if it exists by @pankajastro in #1022 Others * Update dbt and Airflow conflicts matrix by @tatiana in #1026 * Enable Python 3.12 unittest by @pankajastro in #1018 * Improve error logging in ``DbtLocalBaseOperator`` by @davidsteinar in #1004 * Add GitHub issue templates for bug reports and feature request by @pankajkoti in #1009 * Add more fields in bug template to reduce turnaround in issue triaging by @pankajkoti in #1027 * Fix ``dev/Dockerfile`` + Add ``uv pip install`` for faster build time by @dwreeves in #997 * Drop support for Airflow 2.3 by @pankajkoti in #994 * Update Astro Runtime image by @RNHTTR in #988 and #989 * Enable ruff F linting by @pankajastro in #985 * Move Cosmos Airflow configuration to settings.py by @pankajastro in #975 * Fix CI Issues by @tatiana in #1005 * Pre-commit hook updates in #1000, #1019 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Reeves <31971762+dwreeves@users.noreply.github.com> Co-authored-by: Pankaj Koti <pankajkoti699@gmail.com> Co-authored-by: davidsteinar <davidsteinar@gmail.com> Co-authored-by: David Steinar Asgrimsson <david-steinar.asgrimsson@kommuninvest.se> Co-authored-by: Marco Yuen <33394715+marco9663@users.noreply.github.com> Co-authored-by: Pankaj Singh <98807258+pankajastro@users.noreply.github.com> Co-authored-by: Ollie Ma <oliver.zheyi.ma@gmail.com>
Improve error logging when the `dbt` command returns a non-zero exit code. Instead of raising an `AirflowException` with the full output, log the output using the logger and then raise the exception with a concise error message. This makes the dbt output more readable and not in a single line as AirflowException logs message in a single line, and it can get very long. closes astronomer#1003 --------- Co-authored-by: David Steinar Asgrimsson <david-steinar.asgrimsson@kommuninvest.se> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Bug fixes * Fix the invocation mode for ``ExecutionMode.VIRTUALENV`` by @marco9663 in astronomer#1023 * Fix Cosmos ``enable_cache`` setting by @tatiana in astronomer#1025 * Make ``GoogleCloudServiceAccountDictProfileMapping`` dataset profile arg optional by @oliverrmaa and @pankajastro in astronomer#839 and astronomer#1017 * Athena profile mapping set ``aws_session_token`` in profile only if it exists by @pankajastro in astronomer#1022 Others * Update dbt and Airflow conflicts matrix by @tatiana in astronomer#1026 * Enable Python 3.12 unittest by @pankajastro in astronomer#1018 * Improve error logging in ``DbtLocalBaseOperator`` by @davidsteinar in astronomer#1004 * Add GitHub issue templates for bug reports and feature request by @pankajkoti in astronomer#1009 * Add more fields in bug template to reduce turnaround in issue triaging by @pankajkoti in astronomer#1027 * Fix ``dev/Dockerfile`` + Add ``uv pip install`` for faster build time by @dwreeves in astronomer#997 * Drop support for Airflow 2.3 by @pankajkoti in astronomer#994 * Update Astro Runtime image by @RNHTTR in astronomer#988 and astronomer#989 * Enable ruff F linting by @pankajastro in astronomer#985 * Move Cosmos Airflow configuration to settings.py by @pankajastro in astronomer#975 * Fix CI Issues by @tatiana in astronomer#1005 * Pre-commit hook updates in astronomer#1000, astronomer#1019 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Reeves <31971762+dwreeves@users.noreply.github.com> Co-authored-by: Pankaj Koti <pankajkoti699@gmail.com> Co-authored-by: davidsteinar <davidsteinar@gmail.com> Co-authored-by: David Steinar Asgrimsson <david-steinar.asgrimsson@kommuninvest.se> Co-authored-by: Marco Yuen <33394715+marco9663@users.noreply.github.com> Co-authored-by: Pankaj Singh <98807258+pankajastro@users.noreply.github.com> Co-authored-by: Ollie Ma <oliver.zheyi.ma@gmail.com>
Improve error logging when the
dbt
command returns a non-zero exit code. Instead of raising anAirflowException
with the full output, log the output using the logger and then raise the exception with a concise error message. This makes the dbt output more readable and not in a single line.Description
AirflowException logs message in a single line, can be very long.
Related Issue(s)
closes #1003
Breaking Change?
No