Skip to content

Commit

Permalink
Change Graph logger call sites (#4165)
Browse files Browse the repository at this point in the history
graph call sites for structured logging
  • Loading branch information
emmyoop authored and Nathaniel May committed Nov 9, 2021
1 parent 5b2562a commit 51d8440
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
45 changes: 45 additions & 0 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,48 @@ 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
spec_method: str
raw_spec: str

def cli_msg(self) -> str:
valid_selectors = ", ".join(self.selector_methods)
return (
f"The '{self.spec_method}' selector specified in {self.raw_spec} is "
f"invalid. Must be one of [{valid_selectors}]"
)


@dataclass
class MacroEventInfo(InfoLevel, CliEventABC):
msg: str
Expand Down Expand Up @@ -287,5 +329,8 @@ 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='')
15 changes: 9 additions & 6 deletions core/dbt/graph/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from .selector_methods import MethodManager
from .selector_spec import SelectionCriteria, SelectionSpec

from dbt.logger import GLOBAL_LOGGER as logger
from dbt.events.functions import fire_event
from dbt.events.types import (
SelectorAlertUpto3UnusedNodes, SelectorAlertAllUnusedNodes, SelectorReportInvalidSelector
)
from dbt.node_types import NodeType
from dbt.exceptions import (
InternalException,
Expand Down Expand Up @@ -85,11 +88,11 @@ def get_nodes_from_criteria(
try:
collected = self.select_included(nodes, spec)
except InvalidSelectorException:
valid_selectors = ", ".join(self.SELECTOR_METHODS)
logger.info(
f"The '{spec.method}' selector specified in {spec.raw} is "
f"invalid. Must be one of [{valid_selectors}]"
)
fire_event(SelectorReportInvalidSelector(
selector_methods=self.SELECTOR_METHODS,
spec_method=spec.method,
raw_spec=spec.raw
))
return set(), set()

neighbors = self.collect_specified_neighbors(spec, collected)
Expand Down

0 comments on commit 51d8440

Please sign in to comment.