-
Notifications
You must be signed in to change notification settings - Fork 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
[Logging] Add timestamp_ns to core context #49259
[Logging] Add timestamp_ns to core context #49259
Conversation
Signed-off-by: Gene Su <[email protected]>
Signed-off-by: Gene Su <[email protected]>
Signed-off-by: Gene Su <[email protected]>
timestamp_ns = int(record.created * 1e9) | ||
setattr(record, LogKey.TIMESTAMP_NS.value, timestamp_ns) |
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.
We need to see how this works with _setup_log_record_factory
in python/ray/_private/ray_logging/logging_config.py
cc @kevin85421
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.
sg, added a test case for it. The timestamp_ns
still works as expected
…rd_factory() and in CoreContextFilter Signed-off-by: Gene Su <[email protected]>
…) which applies to all log records Signed-off-by: Gene Su <[email protected]>
Signed-off-by: Gene Su <[email protected]>
python/ray/_private/log.py
Outdated
@@ -1,6 +1,9 @@ | |||
import logging | |||
import threading | |||
from typing import Union | |||
import time | |||
|
|||
LOG_KEY_TIMESTAMP_NS = "timestamp_ns" |
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.
Why do we need to define LOG_KEY_TIMESTAMP_NS
here instead of using the one in logging_config.py
? Are there any circular dependencies?
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.
Yea, all those code runs in init, we can't import LogKey
before all modules are fully initialized. The one way to break the circular dependencies is to define this first and reuse it everywhere
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.
Got it. If @jjyao is okay with this, I am fine with it.
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.
Is it possible to move the import to a local import within the _setup_log_record_factory
function to avoid circular dependencies, if any?
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.
Not possible, due to this was call when Ray is importing and we can't import partially imported modules
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.
But to be honest, we probably don't care about timestamp_ns
being in LogKey
or not, since it's not used anywhere expect for setting up log record factory here. Maybe we can just drop it from LogKey
altogether if both of you don't mind
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.
Overall, it looks good to me. I left some minor comments.
@@ -89,3 +92,21 @@ def generate_logging_config(): | |||
# See https://github.com/ray-project/ray/pull/31858 for related PR | |||
rllib_logger = logging.getLogger("ray.rllib") | |||
rllib_logger.setLevel(logging.WARN) | |||
|
|||
# Set up the LogRecord factory. |
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.
Separate the logic into a function so that it is easy to unit test, and we can write tests such as class TestSetupLogRecordFactory
.
python/ray/_private/log.py
Outdated
@@ -1,6 +1,9 @@ | |||
import logging | |||
import threading | |||
from typing import Union | |||
import time | |||
|
|||
LOG_KEY_TIMESTAMP_NS = "timestamp_ns" |
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.
Got it. If @jjyao is okay with this, I am fine with it.
Signed-off-by: Gene Su <[email protected]>
python/ray/_private/log.py
Outdated
@@ -1,6 +1,9 @@ | |||
import logging | |||
import threading | |||
from typing import Union | |||
import time | |||
|
|||
LOG_KEY_TIMESTAMP_NS = "timestamp_ns" |
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.
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.
In product, we use timestamp_ns
field to determine the timestamp at ingestion time and show on the UI. The existing version of Ray is already producing this field and will be used in the log viewer. Yes, we can accept a new field _ray_timestamp_ns
, but we will always need to support timestamp_ns
to be compatible with older versions of Ray regardless, and this adds more complexity on the product logic to needing to first check the existence of _ray_timestamp_ns
and then check the existence of timestamp_ns
before populating the timestamp.
Also, I don't think we should worry about the collision at all since with or without the changes in this PR, timestamp_ns
is already populating the same way using log record factory. The only difference is before this change, the timestamp_ns
field is only added when Ray Core's LoggingConfig
is used, but after this change the timestamp_ns
field will be added when Ray is imported.
…on the formatters Signed-off-by: Gene Su <[email protected]>
Signed-off-by: Gene Su <[email protected]>
Signed-off-by: Gene Su <[email protected]>
Why are these changes needed?
Adding
timestamp_ns
to core context so all structured logs, including the ones from each library, will have this attribute.Related issue number
Closes https://github.com/anyscale/product/issues/32223
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.