-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Clarify logging_config_class contract and document REMOTE_TASK_LOG
#67104
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
Open
jason810496
wants to merge
7
commits into
apache:main
Choose a base branch
from
jason810496:refactor/logging/clarify-logging-config-class-core
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4545abc
Clarify ``logging_config_class`` contract and document REMOTE_TASK_LOG
jason810496 c2e8be9
Fix CI error
jason810496 741be32
CI: Fix pyproject.toml
jason810496 55d027b
Fix pyproject.toml
jason810496 daa1c04
Drop LOGGING_CONFIG dict from remote logging docs section
jason810496 d5341a4
Clarify user-defined logging config detection and simplify warning tests
jason810496 9282def
Default remote_task_log to None and clarify empty logging_config_clas…
jason810496 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -36,7 +36,7 @@ class _ActiveLoggingConfig: | |||||
| """Private class to hold active logging config variables.""" | ||||||
|
|
||||||
| logging_config_loaded: bool = False | ||||||
| remote_task_log: RemoteLogIO | None | ||||||
| remote_task_log: RemoteLogIO | None = None | ||||||
| default_remote_conn_id: str | None = None | ||||||
|
|
||||||
| @classmethod | ||||||
|
|
@@ -120,6 +120,44 @@ def load_logging_config() -> tuple[dict[str, Any], str]: | |||||
| ) or DEFAULT_LOGGING_CONFIG_PATH | ||||||
|
|
||||||
|
|
||||||
| def _warn_if_missing_remote_task_log(logging_class_path: str) -> None: | ||||||
| """ | ||||||
| Warn if ``[logging] remote_logging`` is on but the user module exposes no remote IO. | ||||||
|
|
||||||
| Runs *after* ``dictConfig`` has constructed handlers, so deprecated | ||||||
| self-registration in provider task handlers (Elasticsearch, OpenSearch) has | ||||||
| already had its chance to populate ``_ActiveLoggingConfig.remote_task_log``. | ||||||
| Only fires for user-defined ``logging_config_class`` values; the stock | ||||||
| fallback is exempt. | ||||||
|
|
||||||
| :param logging_class_path: the resolved ``[logging] logging_config_class`` | ||||||
| dotted path (already defaulted to :data:`DEFAULT_LOGGING_CONFIG_PATH`). | ||||||
| """ | ||||||
| # An empty path is not a meaningful override -- ``_get_logging_config()`` treats it the | ||||||
| # same as unset and falls back to ``DEFAULT_LOGGING_CONFIG_PATH``, so it must not be | ||||||
| # treated as a user-defined logging config class here either. | ||||||
| has_user_defined_logging_config_class = ( | ||||||
| bool(logging_class_path) and logging_class_path != DEFAULT_LOGGING_CONFIG_PATH | ||||||
| ) | ||||||
| remote_logging_enabled = conf.getboolean("logging", "remote_logging", fallback=False) | ||||||
| if not (has_user_defined_logging_config_class and remote_logging_enabled): | ||||||
| return | ||||||
| if _ActiveLoggingConfig.remote_task_log is not None: | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think this condition statement may be replaced by |
||||||
| return | ||||||
| # Strip the trailing ``.<config_attr>`` to leave the enclosing module path. | ||||||
| # ``logging_class_path`` should always be dotted since ``import_string`` | ||||||
| # would have raised otherwise, but guard the access defensively. | ||||||
| parts = logging_class_path.rsplit(".", 1) | ||||||
| modpath = parts[0] if len(parts) == 2 else logging_class_path | ||||||
| log.warning( | ||||||
| "[logging] remote_logging is enabled but the user-defined logging module %r " | ||||||
| "does not expose a REMOTE_TASK_LOG attribute, so remote task-log read-back is " | ||||||
| "disabled. Define REMOTE_TASK_LOG (a RemoteLogIO instance) at module scope " | ||||||
| "to enable it.", | ||||||
| modpath, | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def configure_logging(): | ||||||
| from airflow._shared.logging import configure_logging, init_log_folder, translate_config_values | ||||||
|
|
||||||
|
|
@@ -171,6 +209,16 @@ def configure_logging(): | |||||
| # otherwise Airflow would silently fall back on the default config | ||||||
| raise e | ||||||
|
|
||||||
| # Runs after dictConfig so deprecated handler self-registration (ES/OS) has | ||||||
| # had its chance to populate _ActiveLoggingConfig.remote_task_log. | ||||||
| # The trailing `or DEFAULT_LOGGING_CONFIG_PATH` also covers an explicit | ||||||
| # `logging_config_class = ""`, which conf.get() would otherwise return as-is. | ||||||
| logging_class_path = ( | ||||||
| conf.get("logging", "logging_config_class", fallback=DEFAULT_LOGGING_CONFIG_PATH) | ||||||
|
jason810496 marked this conversation as resolved.
|
||||||
| or DEFAULT_LOGGING_CONFIG_PATH | ||||||
| ) | ||||||
| _warn_if_missing_remote_task_log(logging_class_path) | ||||||
|
|
||||||
| validate_logging_config() | ||||||
|
|
||||||
| new_folder_permissions = int( | ||||||
|
|
||||||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.