Skip to content

Commit

Permalink
Add additional logging information to capture skipped ephemeral model…
Browse files Browse the repository at this point in the history
… info (#10390)
  • Loading branch information
gshank authored Jul 3, 2024
1 parent b10fa79 commit a309283
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 64 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240701-131750.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Additional logging for skipped ephemeral models
time: 2024-07-01T13:17:50.827788-04:00
custom:
Author: gshank
Issue: "10389"
15 changes: 14 additions & 1 deletion core/dbt/events/core_types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1903,14 +1903,27 @@ message EndOfRunSummaryMsg {
EndOfRunSummary data = 2;
}

// Skipped Z031, Z032, Z033
// Skipped Z031, Z032

// Z033
message MarkSkippedChildren {
string unique_id = 1;
string status = 2;
RunResultMsg run_result = 3;
}

message MarkSkippedChildrenMsg {
CoreEventInfo info = 1;
MarkSkippedChildren data = 2;
}

// Z034
message LogSkipBecauseError {
string schema = 1;
string relation = 2;
int32 index = 3;
int32 total = 4;
string status = 5;
}

message LogSkipBecauseErrorMsg {
Expand Down
126 changes: 65 additions & 61 deletions core/dbt/events/core_types_pb2.py

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,15 +1856,29 @@ def message(self) -> str:
return message


# Skipped Z031, Z032, Z033
# Skipped Z031, Z032


class MarkSkippedChildren(DebugLevel):
def code(self) -> str:
return "Z033"

def message(self) -> str:
msg = (
f"Marking all children of '{self.unique_id}' to be skipped "
f"because of status '{self.status}'. "
)
if self.run_result.message:
msg = msg + f" Reason: {self.run_result.message}."
return msg


class LogSkipBecauseError(ErrorLevel):
def code(self) -> str:
return "Z034"

def message(self) -> str:
msg = f"SKIP relation {self.schema}.{self.relation} due to ephemeral model error"
msg = f"SKIP relation {self.schema}.{self.relation} due to ephemeral model status '{self.status}'"
return format_fancy_output_line(
msg=msg, status=red("ERROR SKIP"), index=self.index, total=self.total
)
Expand Down
3 changes: 3 additions & 0 deletions core/dbt/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,18 @@ def on_skip(self):
if not self.node.is_ephemeral_model:
# if this model was skipped due to an upstream ephemeral model
# failure, print a special 'error skip' message.
# Include skip_cause NodeStatus
if self._skip_caused_by_ephemeral_failure():
fire_event(
LogSkipBecauseError(
schema=schema_name,
relation=node_name,
index=self.node_index,
total=self.num_nodes,
status=self.skip_cause.status,
)
)
# skip_cause here should be the run_result from the ephemeral model
print_run_result_error(result=self.skip_cause, newline=False)
if self.skip_cause is None: # mypy appeasement
raise DbtInternalError(
Expand Down
8 changes: 8 additions & 0 deletions core/dbt/task/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
EndRunResult,
GenericExceptionOnRun,
LogCancelLine,
MarkSkippedChildren,
NodeFinished,
NodeStart,
NothingToDo,
Expand Down Expand Up @@ -436,6 +437,13 @@ def _mark_dependent_errors(
) -> None:
if self.graph is None:
raise DbtInternalError("graph is None in _mark_dependent_errors")
fire_event(
MarkSkippedChildren(
unique_id=node_id,
status=result.status,
run_result=result.to_msg_dict(),
)
)
for dep_node_id in self.graph.get_dependent_nodes(UniqueId(node_id)):
self._skipped_children[dep_node_id] = cause

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ def test_event_codes(self):
core_types.SQLCompiledPath(path=""),
core_types.CheckNodeTestFailure(relation_name=""),
core_types.EndOfRunSummary(num_errors=0, num_warnings=0, keyboard_interrupt=False),
core_types.MarkSkippedChildren(unique_id="", status="skipped"),
core_types.LogSkipBecauseError(schema="", relation="", index=0, total=0),
core_types.EnsureGitInstalled(),
core_types.DepsCreatingLocalSymlink(),
Expand Down

0 comments on commit a309283

Please sign in to comment.