Skip to content

Commit 906e07c

Browse files
MichelleArkChenyuLInxQMalcolm
authored
Add node_checksum to node_info on structured logs (#11368)
* update node_info to include node checksum * changelog entry * Discard changes to dev-requirements.txt --------- Co-authored-by: Chenyu Li <chenyulee777@gmail.com> Co-authored-by: Quigley Malcolm <quigley.malcolm@dbtlabs.com>
1 parent 6a954e2 commit 906e07c

File tree

6 files changed

+818
-786
lines changed

6 files changed

+818
-786
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Under the Hood
2+
body: Add node_checksum to node_info on structured logs
3+
time: 2025-03-07T10:17:58.375007-05:00
4+
custom:
5+
Author: michelleark
6+
Issue: "11372"

core/dbt/contracts/graph/nodes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def node_info(self):
234234
"alias": getattr(self, "alias", None),
235235
"relation_name": getattr(self, "relation_name", None),
236236
},
237+
"node_checksum": getattr(getattr(self, "checksum", None), "checksum", None),
237238
}
238239
return node_info
239240

core/dbt/events/core_types.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ message NodeInfo {
3939
string node_finished_at = 8;
4040
google.protobuf.Struct meta = 9;
4141
NodeRelation node_relation = 10;
42+
string node_checksum = 11;
4243
}
4344

4445
// TimingInfoMsg

core/dbt/events/core_types_pb2.py

Lines changed: 774 additions & 774 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/functional/logging/test_meta_logging.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ def models():
1414
return {"model1.sql": model1, "model2.sql": model2, "model3.sql": model3}
1515

1616

17-
# This test checks that various events contain node_info,
18-
# which is supplied by the log_contextvars context manager
19-
def test_meta(project, logs_dir):
17+
def run_and_capture_node_info_logs(logs_dir):
2018
run_dbt(["--log-format=json", "run"])
2119

2220
# get log file
@@ -35,12 +33,35 @@ def test_meta(project, logs_dir):
3533
if "node_info" not in log_dct["data"]:
3634
continue
3735

38-
print(f"--- log_dct: {log_dct}")
39-
node_info = log_dct["data"]["node_info"]
40-
node_path = node_info["node_path"]
41-
if node_path == "model1.sql":
42-
assert node_info["meta"] == {}
43-
elif node_path == "model2.sql":
44-
assert node_info["meta"] == {"owners": ["team1", "team2"]}
45-
elif node_path == "model3.sql":
46-
assert node_info["meta"] == {"key": 1}
36+
yield log_dct["data"]["node_info"]
37+
38+
39+
# This test checks that various events contain node_info,
40+
# which is supplied by the log_contextvars context manager
41+
def test_meta(project, logs_dir):
42+
for node_info_log in run_and_capture_node_info_logs(logs_dir):
43+
if node_info_log["unique_id"] == "model.test.model1":
44+
assert node_info_log["meta"] == {}
45+
elif node_info_log["unique_id"] == "model.test.model2":
46+
assert node_info_log["meta"] == {"owners": ["team1", "team2"]}
47+
elif node_info_log["unique_id"] == "model.test.model3":
48+
assert node_info_log["meta"] == {"key": 1}
49+
50+
51+
def test_checksum(project, logs_dir):
52+
for node_info_log in run_and_capture_node_info_logs(logs_dir):
53+
if node_info_log["unique_id"] == "model.test.model1":
54+
assert (
55+
node_info_log["node_checksum"]
56+
== "7a72de8ca68190cc1f3a600b99ad24ce701817a5674222778845eb939c64aa76"
57+
)
58+
elif node_info_log["unique_id"] == "model.test.model2":
59+
assert (
60+
node_info_log["node_checksum"]
61+
== "4e5b7658359b9a7fec6aa3cbad98ab07725927ccce59ec6e511e599e000b0fd3"
62+
)
63+
elif node_info_log["unique_id"] == "model.test.model3":
64+
assert (
65+
node_info_log["node_checksum"]
66+
== "99c67d153920066d43168cc495240f185cec9d8cd552e7778e08437e66f44da7"
67+
)

tests/unit/events/test_types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def test_node_info_events():
129129
"alias": "some_alias",
130130
"relation_name": "some.relation.name",
131131
},
132+
"node_checksum": "some_checksum",
132133
}
133134
event = LogStartLine(
134135
description="some description",
@@ -151,6 +152,8 @@ def test_node_info_events():
151152
assert event.node_info.node_relation.database == ""
152153
assert event.node_info.node_relation.relation_name == "some_schema.some_alias"
153154

155+
assert event.node_info.node_checksum == "some_checksum"
156+
154157

155158
def test_extra_dict_on_event(monkeypatch):
156159

0 commit comments

Comments
 (0)