-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Refactor EventManager setup and interaction #9180
Merged
colin-rogers-dbt
merged 12 commits into
feature/decouple-adapters-from-core
from
moveEventLoggerSetupBackD
Dec 1, 2023
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2474722
moving types_pb2.py to common/events
colin-rogers-dbt 07743b7
merge
colin-rogers-dbt 252e3e3
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt ff9d519
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt bf079b1
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt 3187ded
Merge branch 'feature/decouple-adapters-from-core' of https://github.…
colin-rogers-dbt f6cd7e3
move event manager setup back to core, remove ref to global EVENT_MAN…
colin-rogers-dbt a5c2a63
move invocation_id from events to first class common concept
colin-rogers-dbt 27d049c
move lowercase utils to common
colin-rogers-dbt ef59fb2
move lowercase utils to common
colin-rogers-dbt d1cd262
ref CAPTURE_STREAM through method
colin-rogers-dbt b98a815
add changie
colin-rogers-dbt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from dbt.common.events.base_types import EventLevel | ||
from dbt.common.events.event_manager_client import get_event_manager | ||
from dbt.common.events.functions import get_stdout_config | ||
from dbt.common.events.logger import LineFormat | ||
|
||
# make sure event manager starts with a logger | ||
get_event_manager().add_logger( | ||
get_stdout_config(LineFormat.PlainText, True, EventLevel.INFO, False) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Since dbt-rpc does not do its own log setup, and since some events can | ||
# currently fire before logs can be configured by setup_event_logger(), we | ||
# create a default configuration with default settings and no file output. | ||
from dbt.common.events.event_manager import IEventManager, EventManager | ||
|
||
_EVENT_MANAGER: IEventManager = EventManager() | ||
|
||
|
||
def get_event_manager() -> IEventManager: | ||
global _EVENT_MANAGER | ||
return _EVENT_MANAGER | ||
|
||
|
||
def add_logger_to_manager(logger) -> None: | ||
global _EVENT_MANAGER | ||
_EVENT_MANAGER.add_logger(logger) | ||
|
||
|
||
def ctx_set_event_manager(event_manager: IEventManager) -> None: | ||
global _EVENT_MANAGER | ||
_EVENT_MANAGER = event_manager | ||
|
||
|
||
def cleanup_event_logger() -> None: | ||
# Reset to a no-op manager to release streams associated with logs. This is | ||
# especially important for tests, since pytest replaces the stdout stream | ||
# during test runs, and closes the stream after the test is over. | ||
_EVENT_MANAGER.loggers.clear() | ||
_EVENT_MANAGER.callbacks.clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of using "accessor" functions for the globals we still have, which will give us some flexibility to get away from actually using globals.
We use this pattern elsewhere (e.g. with fire_event) and I've wondered if we should make the nature of the functions more obvious by naming them with a "ctx_" prefix to make it clear we're accessing execution context?