-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow dbt show
and dbt compile
to output JSON without extra logs
#9958
base: main
Are you sure you want to change the base?
Conversation
core/dbt/task/compile.py
Outdated
fire_event(compiled_node_event) | ||
else: | ||
# Cleaner to leave as print than to mutate the logger not to print timestamps. | ||
print(compiled_node_event.message()) |
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.
We can use the new PrintEvent being added to dbt-common.
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.
Awesome! I'll check out dbt-labs/dbt-common#130 and give PrintEvent
a try.
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.
Note to self: see #10131 for an example how to use PrintEvent
.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9958 +/- ##
==========================================
- Coverage 89.14% 89.09% -0.06%
==========================================
Files 183 183
Lines 23553 23559 +6
==========================================
- Hits 20996 20989 -7
- Misses 2557 2570 +13
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@b-per FYI this and dbt-labs/dbt-common#216 are meant to solve your request in #9840 |
resolves #9840
Problem
As described in #9840:
dbt list
uses the--quiet
flag to isolate the desired output from the log output, allowing the results to be piped or redirected.But currently,
dbt show
anddbt compile
do not work similarly. Rather, the--quiet
flag suppresses all output.Latest Solution
The latest solution uses dbt-labs/dbt-common#216 so that
CompiledNode
andShowNode
keep their same event names in the JSON logs, but also allow it to be emitted without timestamps even when--quiet
.When
--quiet
, also skips any extraneous output like:Previewing node 'my_model':
Previewing inline node:
Compiled node 'my_model' is:
Compiled inline node is:
Initial Solution
The initial solution adopted the same exact approach as
dbt list
here, and basically copy-pasted from there.Similar to how #10131 stopped using
ListCmdOut
in favor ofPrintEvent
, this PR stopped usingCompiledNode
andShowNode
in favor ofPrintEvent
.👉 So any consumers relying on
CompiledNode
orShowNode
existing with JSON logs wouldn't see those anymore but would see onlyPrintEvent
instead. So I switched to the latest solution, to avoid any unintentional breakage for anyone creating and parsing JSON logs fordbt show
/dbt compile
.Before vs. after
Scenarios:
show
vs.compile
--select
vs.--inline
--quiet
vs.--no-quiet
--output text
vs.json
--log-format text
vs.json
Example for initial solution
logs/dbt.log
before:logs/dbt.log
after:Checklist