Skip to content

Commit

Permalink
only log events in cache.py when flag is set set (#4369)
Browse files Browse the repository at this point in the history
flag is --log-cache-events
  • Loading branch information
emmyoop authored Nov 30, 2021
1 parent 284ac9b commit d75ed96
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
5 changes: 5 additions & 0 deletions core/dbt/events/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def level_tag(self) -> str:
return "error"


class Cache():
# Events with this class will only be logged when the `--log-cache-events` flag is passed
pass


@dataclass
class Node():
node_path: str
Expand Down
5 changes: 4 additions & 1 deletion core/dbt/events/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from colorama import Style
from datetime import datetime
import dbt.events.functions as this # don't worry I hate it too.
from dbt.events.base_types import Cli, Event, File, ShowException, NodeInfo
from dbt.events.base_types import Cli, Event, File, ShowException, NodeInfo, Cache
from dbt.events.types import EventBufferFull, T_Event
import dbt.flags as flags
# TODO this will need to move eventually
Expand Down Expand Up @@ -262,6 +262,9 @@ def send_exc_to_logger(
# (i.e. - mutating the event history, printing to stdout, logging
# to files, etc.)
def fire_event(e: Event) -> None:
# skip logs when `--log-cache-events` is not passed
if isinstance(e, Cache) and not flags.LOG_CACHE_EVENTS:
return
# if and only if the event history deque will be completely filled by this event
# fire warning that old events are now being dropped
global EVENT_HISTORY
Expand Down
28 changes: 14 additions & 14 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from dbt import ui
from dbt.events.base_types import (
Cli, Event, File, DebugLevel, InfoLevel, WarnLevel, ErrorLevel, ShowException, NodeInfo
Cli, Event, File, DebugLevel, InfoLevel, WarnLevel, ErrorLevel, ShowException, NodeInfo, Cache
)
from dbt.events.format import format_fancy_output_line, pluralize
from dbt.node_types import NodeType
Expand Down Expand Up @@ -636,7 +636,7 @@ def message(self) -> str:
# TODO pretty sure this is only ever called in dead code
# see: core/dbt/adapters/cache.py _add_link vs add_link
@dataclass
class UncachedRelation(DebugLevel, Cli, File):
class UncachedRelation(DebugLevel, Cli, File, Cache):
dep_key: _ReferenceKey
ref_key: _ReferenceKey
code: str = "E022"
Expand All @@ -650,7 +650,7 @@ def message(self) -> str:


@dataclass
class AddLink(DebugLevel, Cli, File):
class AddLink(DebugLevel, Cli, File, Cache):
dep_key: _ReferenceKey
ref_key: _ReferenceKey
code: str = "E023"
Expand All @@ -660,7 +660,7 @@ def message(self) -> str:


@dataclass
class AddRelation(DebugLevel, Cli, File):
class AddRelation(DebugLevel, Cli, File, Cache):
relation: _CachedRelation
code: str = "E024"

Expand All @@ -676,7 +676,7 @@ def fields_to_json(self, val: Any) -> Any:


@dataclass
class DropMissingRelation(DebugLevel, Cli, File):
class DropMissingRelation(DebugLevel, Cli, File, Cache):
relation: _ReferenceKey
code: str = "E025"

Expand All @@ -685,7 +685,7 @@ def message(self) -> str:


@dataclass
class DropCascade(DebugLevel, Cli, File):
class DropCascade(DebugLevel, Cli, File, Cache):
dropped: _ReferenceKey
consequences: Set[_ReferenceKey]
code: str = "E026"
Expand All @@ -695,7 +695,7 @@ def message(self) -> str:


@dataclass
class DropRelation(DebugLevel, Cli, File):
class DropRelation(DebugLevel, Cli, File, Cache):
dropped: _ReferenceKey
code: str = "E027"

Expand All @@ -704,7 +704,7 @@ def message(self) -> str:


@dataclass
class UpdateReference(DebugLevel, Cli, File):
class UpdateReference(DebugLevel, Cli, File, Cache):
old_key: _ReferenceKey
new_key: _ReferenceKey
cached_key: _ReferenceKey
Expand All @@ -716,7 +716,7 @@ def message(self) -> str:


@dataclass
class TemporaryRelation(DebugLevel, Cli, File):
class TemporaryRelation(DebugLevel, Cli, File, Cache):
key: _ReferenceKey
code: str = "E029"

Expand All @@ -725,7 +725,7 @@ def message(self) -> str:


@dataclass
class RenameSchema(DebugLevel, Cli, File):
class RenameSchema(DebugLevel, Cli, File, Cache):
old_key: _ReferenceKey
new_key: _ReferenceKey
code: str = "E030"
Expand All @@ -735,7 +735,7 @@ def message(self) -> str:


@dataclass
class DumpBeforeAddGraph(DebugLevel, Cli, File):
class DumpBeforeAddGraph(DebugLevel, Cli, File, Cache):
# large value. delay not necessary since every debug level message is logged anyway.
dump: Dict[str, List[str]]
code: str = "E031"
Expand All @@ -745,7 +745,7 @@ def message(self) -> str:


@dataclass
class DumpAfterAddGraph(DebugLevel, Cli, File):
class DumpAfterAddGraph(DebugLevel, Cli, File, Cache):
# large value. delay not necessary since every debug level message is logged anyway.
dump: Dict[str, List[str]]
code: str = "E032"
Expand All @@ -755,7 +755,7 @@ def message(self) -> str:


@dataclass
class DumpBeforeRenameSchema(DebugLevel, Cli, File):
class DumpBeforeRenameSchema(DebugLevel, Cli, File, Cache):
# large value. delay not necessary since every debug level message is logged anyway.
dump: Dict[str, List[str]]
code: str = "E033"
Expand All @@ -765,7 +765,7 @@ def message(self) -> str:


@dataclass
class DumpAfterRenameSchema(DebugLevel, Cli, File):
class DumpAfterRenameSchema(DebugLevel, Cli, File, Cache):
# large value. delay not necessary since every debug level message is logged anyway.
dump: Dict[str, List[str]]
code: str = "E034"
Expand Down
10 changes: 7 additions & 3 deletions core/dbt/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
PRINTER_WIDTH = 80
WHICH = None
INDIRECT_SELECTION = None
LOG_CACHE_EVENTS = None

# Global CLI defaults. These flags are set from three places:
# CLI args, environment variables, and user_config (profiles.yml).
Expand All @@ -51,7 +52,8 @@
"FAIL_FAST": False,
"SEND_ANONYMOUS_USAGE_STATS": True,
"PRINTER_WIDTH": 80,
"INDIRECT_SELECTION": 'eager'
"INDIRECT_SELECTION": 'eager',
"LOG_CACHE_EVENTS": False
}


Expand Down Expand Up @@ -99,7 +101,7 @@ def set_from_args(args, user_config):
USE_EXPERIMENTAL_PARSER, STATIC_PARSER, WRITE_JSON, PARTIAL_PARSE, \
USE_COLORS, STORE_FAILURES, PROFILES_DIR, DEBUG, LOG_FORMAT, INDIRECT_SELECTION, \
VERSION_CHECK, FAIL_FAST, SEND_ANONYMOUS_USAGE_STATS, PRINTER_WIDTH, \
WHICH
WHICH, LOG_CACHE_EVENTS

STRICT_MODE = False # backwards compatibility
# cli args without user_config or env var option
Expand All @@ -122,6 +124,7 @@ def set_from_args(args, user_config):
SEND_ANONYMOUS_USAGE_STATS = get_flag_value('SEND_ANONYMOUS_USAGE_STATS', args, user_config)
PRINTER_WIDTH = get_flag_value('PRINTER_WIDTH', args, user_config)
INDIRECT_SELECTION = get_flag_value('INDIRECT_SELECTION', args, user_config)
LOG_CACHE_EVENTS = get_flag_value('LOG_CACHE_EVENTS', args, user_config)


def get_flag_value(flag, args, user_config):
Expand Down Expand Up @@ -165,5 +168,6 @@ def get_flag_dict():
"fail_fast": FAIL_FAST,
"send_anonymous_usage_stats": SEND_ANONYMOUS_USAGE_STATS,
"printer_width": PRINTER_WIDTH,
"indirect_selection": INDIRECT_SELECTION
"indirect_selection": INDIRECT_SELECTION,
"log_cache_events": LOG_CACHE_EVENTS
}

0 comments on commit d75ed96

Please sign in to comment.