-
Notifications
You must be signed in to change notification settings - Fork 7.8k
use cached contexts for access logs in request path #55166
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f2f1070
use orjson for json log formatter
abrarsheikh 65b5883
use cached contexts for access logs
abrarsheikh b0f0863
Merge branch 'master' into abrar-logging-context
abrarsheikh 6f0d7bf
remove orjson
abrarsheikh 0b0abec
fix the order
abrarsheikh 072fef2
Merge branch 'master' of github.com:ray-project/ray into abrar-loggin…
abrarsheikh ac58aaa
add debug logs
abrarsheikh 76ce6a7
revert wrong todo comment
abrarsheikh 19099bd
info to debug
abrarsheikh 0fdff60
add comments
abrarsheikh 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,55 @@ | ||
| import logging | ||
| from typing import Any, Dict | ||
|
|
||
| import ray | ||
| from ray._private.ray_logging.constants import LogKey | ||
|
|
||
|
|
||
| class CoreContextFilter(logging.Filter): | ||
| def filter(self, record): | ||
| TASK_LEVEL_LOG_KEYS = [ | ||
| LogKey.TASK_ID.value, | ||
| LogKey.TASK_NAME.value, | ||
| LogKey.TASK_FUNCTION_NAME.value, | ||
| ] | ||
|
|
||
| @classmethod | ||
| def get_ray_core_logging_context(cls) -> Dict[str, Any]: | ||
| """ | ||
| Get the ray core logging context as a dict. | ||
| Only use this function if you need include the attributes to the log record | ||
| yourself by bypassing the filter. | ||
| """ | ||
| if not ray.is_initialized(): | ||
| # There is no additional context if ray is not initialized | ||
| return True | ||
| return {} | ||
|
|
||
| runtime_context = ray.get_runtime_context() | ||
| setattr(record, LogKey.JOB_ID.value, runtime_context.get_job_id()) | ||
| setattr(record, LogKey.WORKER_ID.value, runtime_context.get_worker_id()) | ||
| setattr(record, LogKey.NODE_ID.value, runtime_context.get_node_id()) | ||
| ray_core_logging_context = { | ||
| LogKey.JOB_ID.value: runtime_context.get_job_id(), | ||
| LogKey.WORKER_ID.value: runtime_context.get_worker_id(), | ||
| LogKey.NODE_ID.value: runtime_context.get_node_id(), | ||
| } | ||
| if runtime_context.worker.mode == ray.WORKER_MODE: | ||
| actor_id = runtime_context.get_actor_id() | ||
| if actor_id is not None: | ||
| setattr(record, LogKey.ACTOR_ID.value, actor_id) | ||
| task_id = runtime_context.get_task_id() | ||
| if task_id is not None: | ||
| setattr(record, LogKey.TASK_ID.value, task_id) | ||
| task_name = runtime_context.get_task_name() | ||
| if task_name is not None: | ||
| setattr(record, LogKey.TASK_NAME.value, task_name) | ||
| task_function_name = runtime_context.get_task_function_name() | ||
| if task_function_name is not None: | ||
| setattr(record, LogKey.TASK_FUNCTION_NAME.value, task_function_name) | ||
| actor_name = runtime_context.get_actor_name() | ||
| if actor_name is not None: | ||
| setattr(record, LogKey.ACTOR_NAME.value, actor_name) | ||
| ray_core_logging_context[ | ||
| LogKey.ACTOR_ID.value | ||
| ] = runtime_context.get_actor_id() | ||
| ray_core_logging_context[ | ||
| LogKey.TASK_ID.value | ||
| ] = runtime_context.get_task_id() | ||
| ray_core_logging_context[ | ||
| LogKey.TASK_NAME.value | ||
| ] = runtime_context.get_task_name() | ||
| ray_core_logging_context[ | ||
| LogKey.TASK_FUNCTION_NAME.value | ||
| ] = runtime_context.get_task_function_name() | ||
| ray_core_logging_context[ | ||
| LogKey.ACTOR_NAME.value | ||
| ] = runtime_context.get_actor_name() | ||
| return ray_core_logging_context | ||
|
|
||
| def filter(self, record): | ||
| context = self.get_ray_core_logging_context() | ||
| for key, value in context.items(): | ||
| if value is not None: | ||
| setattr(record, key, value) | ||
| return True | ||
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.