From 66cece024978b61142e06c0b4dba73ba4a6a9b82 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Mon, 8 Nov 2021 14:31:34 -0600 Subject: [PATCH] updates associated with merging main - removed 3 new log call sites and replaced with structured logs - removed 2 unused struc logs --- core/dbt/events/types.py | 51 +++++++++++++++---------------------- core/dbt/graph/selector.py | 4 +-- core/dbt/parser/manifest.py | 11 ++++---- core/dbt/task/sql.py | 5 ++-- 4 files changed, 30 insertions(+), 41 deletions(-) diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py index ebb250e6ea9..fd608cc27fb 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -295,34 +295,6 @@ def cli_msg(self) -> str: return f"command return code={self.code}" -@dataclass -class SelectorAlertUpto3UnusedNodes(InfoLevel, CliEventABC): - node_names: List[str] - - def cli_msg(self) -> str: - summary_nodes_str = ("\n - ").join(self.node_names[:3]) - and_more_str = ( - f"\n - and {len(self.node_names) - 3} more" if len(self.node_names) > 4 else "" - ) - return ( - f"\nSome tests were excluded because at least one parent is not selected. " - f"Use the --greedy flag to include them." - f"\n - {summary_nodes_str}{and_more_str}" - ) - - -@dataclass -class SelectorAlertAllUnusedNodes(DebugLevel, CliEventABC): - node_names: List[str] - - def cli_msg(self) -> str: - debug_nodes_str = ("\n - ").join(self.node_names) - return ( - f"Full list of tests that were excluded:" - f"\n - {debug_nodes_str}" - ) - - @dataclass class SelectorReportInvalidSelector(InfoLevel, CliEventABC): selector_methods: dict @@ -728,6 +700,16 @@ def cli_msg(self) -> str: return f"Partial parsing: deleted exposure {self.unique_id}" +class PartialParsingProjectEnvVarsChanged(InfoLevel, CliEventABC): + def cli_msg(self) -> str: + return "Unable to do partial parsing because env vars used in dbt_project.yml have changed" + + +class PartialParsingProfileEnvVarsChanged(InfoLevel, CliEventABC): + def cli_msg(self) -> str: + return "Unable to do partial parsing because env vars used in profiles.yml have changed" + + @dataclass class InvalidDisabledSourceInTestNode(WarnLevel, CliEventABC): msg: str @@ -1767,6 +1749,14 @@ def cli_msg(self) -> str: return str(self.exc) +@dataclass +class SQlRunnerException(ShowException, DebugLevel, CliEventABC): + exc: Exception + + def cli_msg(self) -> str: + return f"Got an exception: {self.exc}" + + # since mypy doesn't run on every file we need to suggest to mypy that every # class gets instantiated. But we don't actually want to run this code. # making the conditional `if False` causes mypy to skip it as dead code so @@ -1803,8 +1793,6 @@ def cli_msg(self) -> str: SystemStdOutMsg(bmsg=b'') SystemStdErrMsg(bmsg=b'') SystemReportReturnCode(code=0) - SelectorAlertUpto3UnusedNodes(node_names=[]) - SelectorAlertAllUnusedNodes(node_names=[]) SelectorReportInvalidSelector(selector_methods={'': ''}, spec_method='', raw_spec='') MacroEventInfo(msg='') MacroEventDebug(msg='') @@ -1849,6 +1837,8 @@ def cli_msg(self) -> str: PartialParsingUpdateSchemaFile(file_id='') PartialParsingDeletedSource(unique_id='') PartialParsingDeletedExposure(unique_id='') + PartialParsingProjectEnvVarsChanged() + PartialParsingProfileEnvVarsChanged() InvalidDisabledSourceInTestNode(msg='') InvalidRefInTestNode(msg='') MessageHandleGenericException(build_path='', unique_id='', exc=Exception('')) @@ -1959,3 +1949,4 @@ def cli_msg(self) -> str: RetryExternalCall(attempt=0, max=0) GeneralWarningMsg(msg='', log_fmt='') GeneralWarningException(exc=Exception(''), log_fmt='') + SQlRunnerException(exc=Exception('')) diff --git a/core/dbt/graph/selector.py b/core/dbt/graph/selector.py index b7bd4be2cf3..9a4a69f2126 100644 --- a/core/dbt/graph/selector.py +++ b/core/dbt/graph/selector.py @@ -6,9 +6,7 @@ from .selector_spec import SelectionCriteria, SelectionSpec from dbt.events.functions import fire_event -from dbt.events.types import ( - SelectorAlertUpto3UnusedNodes, SelectorAlertAllUnusedNodes, SelectorReportInvalidSelector -) +from dbt.events.types import SelectorReportInvalidSelector from dbt.node_types import NodeType from dbt.exceptions import ( InternalException, diff --git a/core/dbt/parser/manifest.py b/core/dbt/parser/manifest.py index 33f0085b87d..90dd08111a2 100644 --- a/core/dbt/parser/manifest.py +++ b/core/dbt/parser/manifest.py @@ -27,7 +27,8 @@ PartialParsingFailedBecauseConfigChange, PartialParsingFailedBecauseProfileChange, PartialParsingFailedBecauseNewProjectDependency, PartialParsingFailedBecauseHashChanged, PartialParsingNotEnabled, ParsedFileLoadFailed, PartialParseSaveFileNotFound, - InvalidDisabledSourceInTestNode, InvalidRefInTestNode + InvalidDisabledSourceInTestNode, InvalidRefInTestNode, PartialParsingProjectEnvVarsChanged, + PartialParsingProfileEnvVarsChanged ) from dbt.logger import DbtProcessState from dbt.node_types import NodeType @@ -276,7 +277,7 @@ def load(self): file_dict = source_file.to_dict() fire_event(PartialParsingFile(file_dict=file_dict)) exc_info['parse_file_type'] = parse_file_type - fire_event(PartialParsingException()) + fire_event(PartialParsingException(exc_info=exc_info)) # Send event if dbt.tracking.active_user is not None: @@ -564,14 +565,12 @@ def is_partial_parsable(self, manifest: Manifest) -> Tuple[bool, Optional[str]]: reparse_reason = ReparseReason.profile_changed if self.manifest.state_check.project_env_vars_hash != \ manifest.state_check.project_env_vars_hash: - logger.info("Unable to do partial parsing because env vars " - "used in dbt_project.yml have changed") + fire_event(PartialParsingProjectEnvVarsChanged()) valid = False reparse_reason = ReparseReason.proj_env_vars_changed if self.manifest.state_check.profile_env_vars_hash != \ manifest.state_check.profile_env_vars_hash: - logger.info("Unable to do partial parsing because env vars " - "used in profiles.yml have changed") + fire_event(PartialParsingProfileEnvVarsChanged()) valid = False reparse_reason = ReparseReason.prof_env_vars_changed diff --git a/core/dbt/task/sql.py b/core/dbt/task/sql.py index 12d6ff7a066..446d53055b8 100644 --- a/core/dbt/task/sql.py +++ b/core/dbt/task/sql.py @@ -9,7 +9,8 @@ RemoteRunResult, ResultTable, ) -from dbt.logger import GLOBAL_LOGGER as logger +from dbt.events.functions import fire_event +from dbt.events.types import SQlRunnerException from dbt.task.compile import CompileRunner @@ -23,7 +24,7 @@ def __init__(self, config, adapter, node, node_index, num_nodes): ) def handle_exception(self, e, ctx): - logger.debug('Got an exception: {}'.format(e), exc_info=True) + fire_event(SQlRunnerException(exc=e)) if isinstance(e, dbt.exceptions.Exception): if isinstance(e, dbt.exceptions.RuntimeException): e.add_node(ctx.node)