Skip to content
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

Change Graph logger call sites #4165

Merged
merged 22 commits into from
Oct 29, 2021
Merged
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='')
31 changes: 11 additions & 20 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 All @@ -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):
Expand Down Expand Up @@ -103,11 +94,11 @@ def get_nodes_from_criteria(
try:
collected = self.select_included(nodes, spec)
except InvalidSelectorException:
valid_selectors = ", ".join(self.SELECTOR_METHODS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to move this into SelectorReportInvalidSelector?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to take the approach where the event represents all the necessary data, and the responsibility to turn data into human-readable strings is entirely up to the event methods. valid_selectors looks like it's entirely about turning data into strings so I moved it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Just want to make sure I'm consistent.

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