diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py index e6e717f19d7..0a182d33b03 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -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 @@ -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='') diff --git a/core/dbt/graph/selector.py b/core/dbt/graph/selector.py index f2026621eb9..f937dc83b95 100644 --- a/core/dbt/graph/selector.py +++ b/core/dbt/graph/selector.py @@ -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, @@ -30,21 +33,9 @@ def alert_non_existence(raw_spec, nodes): def alert_unused_nodes(raw_spec, node_names): - summary_nodes_str = ("\n - ").join(node_names[:3]) - debug_nodes_str = ("\n - ").join(node_names) - and_more_str = f"\n - and {len(node_names) - 3} more" if len(node_names) > 4 else "" - summary_msg = ( - 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}" - ) - logger.info(summary_msg) + fire_event(SelectorAlertUpto3UnusedNodes(node_names=node_names)) if len(node_names) > 4: - debug_msg = ( - f"Full list of tests that were excluded:" - f"\n - {debug_nodes_str}" - ) - logger.debug(debug_msg) + fire_event(SelectorAlertAllUnusedNodes(node_names=node_names)) def can_select_indirectly(node): @@ -103,11 +94,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)