-
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
CT 1998 use google protobuf to enable more flexible dictionaries #7190
Changes from all commits
241062e
cfce5aa
e30f1a5
42ddcf5
03f1c00
dbe2253
b49a1b8
f177944
4a7374d
152d797
640ba24
ef935c6
cce665e
49febc6
7ce4536
b18d664
1e00f05
9babfa3
008387f
2ec2472
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Features | ||
body: Switch from betterproto to google protobuf and enable more flexible meta dictionary | ||
in logs | ||
time: 2023-03-18T16:43:26.782738-04:00 | ||
custom: | ||
Author: gshank | ||
Issue: "6832" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
core/dbt/include/index.html binary | ||
tests/functional/artifacts/data/state/*/manifest.json binary | ||
core/dbt/events/types_pb2.py binary |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,10 @@ | |
from dbt.exceptions import DbtInternalError | ||
from dbt.events.functions import fire_event | ||
from dbt.events.types import TimingInfoCollected | ||
from dbt.events.proto_types import RunResultMsg, TimingInfoMsg | ||
from dbt.events.contextvars import get_node_info | ||
from dbt.events.helpers import datetime_to_json_string | ||
from dbt.logger import TimingProcessor | ||
from dbt.utils import lowercase, cast_to_str, cast_to_int, cast_dict_to_dict_of_strings | ||
from dbt.utils import lowercase, cast_to_str, cast_to_int | ||
from dbt.dataclass_schema import dbtClassMixin, StrEnum | ||
|
||
import agate | ||
|
@@ -45,11 +45,13 @@ def begin(self): | |
def end(self): | ||
self.completed_at = datetime.utcnow() | ||
|
||
def to_msg(self): | ||
timsg = TimingInfoMsg( | ||
name=self.name, started_at=self.started_at, completed_at=self.completed_at | ||
) | ||
return timsg | ||
def to_msg_dict(self): | ||
msg_dict = {"name": self.name} | ||
if self.started_at: | ||
msg_dict["started_at"] = datetime_to_json_string(self.started_at) | ||
if self.completed_at: | ||
msg_dict["completed_at"] = datetime_to_json_string(self.completed_at) | ||
return msg_dict | ||
|
||
|
||
# This is a context manager | ||
|
@@ -67,7 +69,7 @@ def __exit__(self, exc_type, exc_value, traceback): | |
with TimingProcessor(self.timing_info): | ||
fire_event( | ||
TimingInfoCollected( | ||
timing_info=self.timing_info.to_msg(), node_info=get_node_info() | ||
timing_info=self.timing_info.to_msg_dict(), node_info=get_node_info() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In practice, do we expect this change (nested message → nested dict) to be breaking in any way? My sense is that it looks the same, if the event is being serialized to JSON, which is our only official current interface for consuming structured logs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should have the same output. In betterproto we had to provide the pre-constructed sub-messages (which is the way python works) and with google protobuf, you can't. |
||
) | ||
) | ||
|
||
|
@@ -129,16 +131,17 @@ def __pre_deserialize__(cls, data): | |
data["failures"] = None | ||
return data | ||
|
||
def to_msg(self): | ||
msg = RunResultMsg() | ||
msg.status = str(self.status) | ||
msg.message = cast_to_str(self.message) | ||
msg.thread = self.thread_id | ||
msg.execution_time = self.execution_time | ||
msg.num_failures = cast_to_int(self.failures) | ||
msg.timing_info = [ti.to_msg() for ti in self.timing] | ||
msg.adapter_response = cast_dict_to_dict_of_strings(self.adapter_response) | ||
return msg | ||
def to_msg_dict(self): | ||
msg_dict = { | ||
"status": str(self.status), | ||
"message": cast_to_str(self.message), | ||
"thread": self.thread_id, | ||
"execution_time": self.execution_time, | ||
"num_failures": cast_to_int(self.failures), | ||
"timing_info": [ti.to_msg_dict() for ti in self.timing], | ||
"adapter_response": self.adapter_response, | ||
} | ||
return msg_dict | ||
|
||
|
||
@dataclass | ||
|
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.
nice!!