Repository navigation
[Core] Support one-event in python layer - #60858
Conversation
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces Cython bindings for the C++ RayEventRecorder, enabling events to be emitted from Python as part of the new ONE-Event framework. The changes are well-structured, with a clear separation between the Python public API, the Cython binding layer, and the C++ implementation. The new Python API in ray._common.observability is well-designed with an InternalEventBuilder for creating custom events. The C++ and Cython parts correctly handle memory management and cross-language calls. I have a few suggestions to improve maintainability. Overall, this is a solid contribution that sets up the foundation for eventing from Python.
| self, | ||
| source_type: int, | ||
| event_type: int, | ||
| severity: int = 3, # INFO = 3 (default) |
There was a problem hiding this comment.
The __init__ method uses a magic number 3 for the default severity. It would be more readable and maintainable to use the protobuf enum value directly. This avoids magic numbers and makes the code self-documenting. Please add from ray.core.generated.events_base_event_pb2 import RayEvent as RayEventProto to the imports at the top of the file and use RayEventProto.Severity.INFO here.
| severity: int = 3, # INFO = 3 (default) | |
| severity: int = RayEventProto.Severity.INFO, # INFO = 3 (default) |
| switch (event_type_) { | ||
| case rpc::events::RayEvent::SUBMISSION_JOB_DEFINITION_EVENT: { | ||
| auto *nested_event = event.mutable_submission_job_definition_event(); | ||
| if (!nested_event->ParseFromString(serialized_event_data_)) { | ||
| RAY_LOG(ERROR) << "Failed to parse SubmissionJobDefinitionEvent from serialized " | ||
| "data"; | ||
| } | ||
| break; | ||
| } | ||
| case rpc::events::RayEvent::SUBMISSION_JOB_LIFECYCLE_EVENT: { | ||
| auto *nested_event = event.mutable_submission_job_lifecycle_event(); | ||
| if (!nested_event->ParseFromString(serialized_event_data_)) { | ||
| RAY_LOG(ERROR) | ||
| << "Failed to parse SubmissionJobLifecycleEvent from serialized data"; | ||
| } | ||
| break; | ||
| } | ||
| default: | ||
| RAY_LOG(ERROR) << "Unsupported event type for Python event: " << event_type_; | ||
| break; | ||
| } |
There was a problem hiding this comment.
This switch statement for parsing the nested event message works, but it will require modification every time a new Python-emitted event type is added. For better maintainability and extensibility as the number of event types grows, consider refactoring this to a registration-based pattern, such as a map from EventType to a parsing function. This would allow new event types to be handled without changing this core serialization logic. For now, the switch is acceptable, but it's a point of potential future tech debt.
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
| rec = <EventRecorder>_event_recorder_instance | ||
| if rec._recorder.get() != NULL: | ||
| with nogil: | ||
| rec._recorder.get().Shutdown() |
There was a problem hiding this comment.
I think this results in Shutdown getting called twice since it's also in the destructor. I think this is probably fine though since it's idempotent
| serialized_data=self.serialize_event_data(), | ||
| nested_event_field_number=self._nested_event_field_number, | ||
| event_id=event_id if event_id is not None else b"", | ||
| timestamp_ns=timestamp_ns if timestamp_ns is not None else 0, |
There was a problem hiding this comment.
Nit: maybe cast to int here because it'll throw a TypeError if it's provided but not of the correct type, since the Cython needs int64_t.
|
@sampan-s-nayak This PR looks good to me, I don't have any substantial comments beyond what @MengjinYan already pointed out. I think this PR is good for final review / to merge once the last outstanding comments are addressed. |
Signed-off-by: sampan <[email protected]>
|
@MengjinYan @ryanaoleary addressed/replied to comments |
MengjinYan
left a comment
There was a problem hiding this comment.
Replied on the comment. Other than the comment, it looks good to me!
Signed-off-by: sampan <[email protected]>
|
@MengjinYan thanks, addressed |
| // Serialize the event data to a RayEvent proto. Returns a non-OK status when the | ||
| // event cannot be serialized (e.g., the nested event payload fails to parse). The | ||
| // recorder skips events that return a non-OK status. | ||
| virtual ray::StatusOr<ray::rpc::events::RayEvent> Serialize() && = 0; |
There was a problem hiding this comment.
StatusOr is the legacy way of returning status from a function.
StatusSetOr should be the current standard:
Line 73 in d155399
But to unblock future PRs, I'm okay with making the change in a followup PR.
Signed-off-by: sampan <[email protected]>
…nto job_events_missing_fields_2 Signed-off-by: sampan <[email protected]>
## Description Core fails to build binaries in [microcheck](https://buildkite.com/ray-project/microcheck/builds/44977#019dff0a-0312-4363-8a6f-7ac5c74513aa) right now due to a newly merged PR using an out of date asio target. Specifically, this PR moved the asio build target: #63042 This PR introduced a new file that uses the out-of-date target: #60858 This PR addresses this issue by updating the out-of-date `python_event_interface.h` to use the new target. ## Related issues ## Additional information Signed-off-by: davik <[email protected]> Co-authored-by: davik <[email protected]>
## Description Adds cython bindings for c++ rayEventRecorder and sets up the scaffolding required to emit events from python (using the new one-event framework). This will also be used to emit library events in the future refer: ray-project#61099 for example usage of this abstraction --------- Signed-off-by: sampan <[email protected]> Signed-off-by: Sampan S Nayak <[email protected]> Co-authored-by: sampan <[email protected]> Co-authored-by: Mengjin Yan <[email protected]>
…ect#63166) ## Description Core fails to build binaries in [microcheck](https://buildkite.com/ray-project/microcheck/builds/44977#019dff0a-0312-4363-8a6f-7ac5c74513aa) right now due to a newly merged PR using an out of date asio target. Specifically, this PR moved the asio build target: ray-project#63042 This PR introduced a new file that uses the out-of-date target: ray-project#60858 This PR addresses this issue by updating the out-of-date `python_event_interface.h` to use the new target. ## Related issues ## Additional information Signed-off-by: davik <[email protected]> Co-authored-by: davik <[email protected]>
## Description Adds cython bindings for c++ rayEventRecorder and sets up the scaffolding required to emit events from python (using the new one-event framework). This will also be used to emit library events in the future refer: ray-project#61099 for example usage of this abstraction --------- Signed-off-by: sampan <[email protected]> Signed-off-by: Sampan S Nayak <[email protected]> Co-authored-by: sampan <[email protected]> Co-authored-by: Mengjin Yan <[email protected]> Signed-off-by: Alexandr Plashchinsky <[email protected]>
…ect#63166) ## Description Core fails to build binaries in [microcheck](https://buildkite.com/ray-project/microcheck/builds/44977#019dff0a-0312-4363-8a6f-7ac5c74513aa) right now due to a newly merged PR using an out of date asio target. Specifically, this PR moved the asio build target: ray-project#63042 This PR introduced a new file that uses the out-of-date target: ray-project#60858 This PR addresses this issue by updating the out-of-date `python_event_interface.h` to use the new target. ## Related issues ## Additional information Signed-off-by: davik <[email protected]> Co-authored-by: davik <[email protected]> Signed-off-by: Alexandr Plashchinsky <[email protected]>
…der (#61099) ## Description this pr migrates submission job events to go through the events recorder framework ([proto changes](#60857) have already been merged). Uses the [python event recorder bindings](#60858) to emit these events from the python frontend (breaks the JobInfo object emitted by the export event framework into definition and lifecycle events). Events are emitted when: 1) [RAY_ENABLE_RAY_EVENT](https://github.com/sampan-s-nayak/ray/blob/76f7d63be2c9afe87e2197d99192e55e073c90c6/python/ray/_private/ray_constants.py#L727-L729) is true (needed for enabling the underlying c++ event recorder) 2) [RAY_ENABLE_PYTHON_RAY_EVENT_TYPES](https://github.com/sampan-s-nayak/ray/blob/76f7d63be2c9afe87e2197d99192e55e073c90c6/python/ray/_private/ray_constants.py#L712-L725) contains `SUBMISSION_JOB_DEFINITION_EVENT_TYPE` and `SUBMISSION_JOB_LIFECYCLE_EVENT_TYPE` note: when the ray event recorder path is enabled the old event export path is disabled --------- Signed-off-by: sampan <[email protected]> Signed-off-by: Sampan S Nayak <[email protected]> Co-authored-by: sampan <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]>
Description
Adds cython bindings for c++ rayEventRecorder and sets up the scaffolding required to emit events from python (using the new one-event framework). This will also be used to emit library events in the future
refer: #61099 for example usage of this abstraction
Related issues
Additional information