Skip to content

Commit

Permalink
Create LogNodeResult event
Browse files Browse the repository at this point in the history
  • Loading branch information
aranke committed Jan 7, 2025
1 parent 7106005 commit 11c42b9
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 302 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20250107-205838.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Create LogNodeResult event
time: 2025-01-07T20:58:38.821036Z
custom:
Author: aranke
Issue: ' '
17 changes: 16 additions & 1 deletion core/dbt/events/core_types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1355,8 +1355,23 @@ message LogTestResultMsg {
LogTestResult data = 2;
}

// Q008
message LogNodeResult {
NodeInfo node_info = 1;
string description = 2;
string status = 3;
int32 index = 4;
int32 total = 5;
float execution_time = 6;
map<string, string> status_to_message_map = 7;
}

message LogNodeResultMsg {
CoreEventInfo info = 1;
LogNodeResult data = 2;
}

// Skipped Q008, Q009, Q010
// Skipped Q009, Q010


// Q011
Expand Down
598 changes: 298 additions & 300 deletions core/dbt/events/core_types_pb2.py

Large diffs are not rendered by default.

31 changes: 30 additions & 1 deletion core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,36 @@ def status_to_level(cls, status):
return EventLevel.INFO


# Skipped Q008, Q009, Q010
class LogNodeResult(DynamicLevel):
def code(self) -> str:
return "Q008"

def message(self) -> str:
for status in self.status_to_message_map:
if self.status == status:
return self.status_to_message_map[status]

# Catch-all, we should never be here
return red(
f"Unknown status for {self.node_info.resource_type} '{self.node_info.unique_id}'"
)

@classmethod
def status_to_level(cls, status):
level_lookup = {
"success": EventLevel.INFO,
"no-op": EventLevel.INFO,
"error": EventLevel.ERROR,
"skipped": EventLevel.WARN,
"partial success": EventLevel.WARN,
}
if status in level_lookup:
return level_lookup[status]
else:
return EventLevel.INFO

Check warning on line 1371 in core/dbt/events/types.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/events/types.py#L1371

Added line #L1371 was not covered by tests


# Skipped Q009, Q010


class LogStartLine(InfoLevel):
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/events/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dbt.adapters.events.types import PluginLoadError, RollbackFailed
from dbt.events import core_types_pb2
from dbt.events.types import (
LogNodeResult,
LogStartLine,
LogTestResult,
MainEncounteredError,
Expand Down Expand Up @@ -185,3 +186,21 @@ def test_dynamic_level_events():
msg = msg_from_base_event(event, level=EventLevel.INFO)
assert msg
assert msg.info.level == "info"


def test_log_node_level():
event = LogNodeResult(
node_info={},
status="error",
index=1,
total=0,
status_to_message_map={
"error": "red(error message)",
"skipped": "yellow(skipped message)",
"success": "green(success message)",
},
)
msg = msg_from_base_event(event, level=LogNodeResult.status_to_level(event.status))
assert msg
assert msg.info.msg == "red(error message)"
assert msg.info.level == "error"
8 changes: 8 additions & 0 deletions tests/unit/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ def test_event_codes(self):
execution_time=0,
num_failures=0,
),
core_types.LogNodeResult(
description="",
status="",
index=0,
total=0,
execution_time=0,
status_to_message_map={},
),
core_types.LogStartLine(description="", index=0, total=0),
core_types.LogModelResult(
description="",
Expand Down

0 comments on commit 11c42b9

Please sign in to comment.