Skip to content

[Core] Support one-event in python layer - #60858

Merged
MengjinYan merged 44 commits into
masterfrom
job_events_missing_fields_2
May 6, 2026
Merged

MengjinYan merged 44 commits into
masterfrom
job_events_missing_fields_2

Conversation

@sampan-s-nayak

@sampan-s-nayak sampan-s-nayak commented Feb 9, 2026 •

Copy link
Copy Markdown
Contributor

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

Link related issues: "Fixes #1234", "Closes #1234", or "Related to #1234".

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

@sampan-s-nayak
sampan-s-nayak requested review from a team, edoakes and jjyao as code owners February 9, 2026 07:55
@sampan-s-nayak sampan-s-nayak changed the title [Core] add cythin bindings for rayEventRecorder [Core] add cython bindings for rayEventRecorder Feb 9, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
severity: int = 3, # INFO = 3 (default)
severity: int = RayEventProto.Severity.INFO, # INFO = 3 (default)

Comment on lines +65 to +85
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

@sampan-s-nayak sampan-s-nayak changed the title [Core] add cython bindings for rayEventRecorder [Core] Support one-event in python layer Feb 9, 2026
@sampan-s-nayak
sampan-s-nayak marked this pull request as draft February 9, 2026 08:54
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
@sampan-s-nayak sampan-s-nayak added the go add ONLY when ready to merge, run all tests label Feb 10, 2026
@sampan-s-nayak
sampan-s-nayak marked this pull request as ready for review February 17, 2026 07:42
Comment thread python/ray/includes/event_recorder.pxi Resolved
@ray-gardener ray-gardener Bot added the community-contribution Contributed by the community label Feb 17, 2026
Signed-off-by: sampan <[email protected]>
rec = <EventRecorder>_event_recorder_instance
if rec._recorder.get() != NULL:
with nogil:
rec._recorder.get().Shutdown()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ryanaoleary

Copy link
Copy Markdown
Contributor

@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.

@sampan-s-nayak

Copy link
Copy Markdown
Contributor Author

@MengjinYan @ryanaoleary addressed/replied to comments

@MengjinYan MengjinYan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replied on the comment. Other than the comment, it looks good to me!

Signed-off-by: sampan <[email protected]>
@sampan-s-nayak

Copy link
Copy Markdown
Contributor Author

@MengjinYan thanks, addressed

@MengjinYan MengjinYan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

// 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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StatusOr is the legacy way of returning status from a function.

StatusSetOr should be the current standard:

// USAGE EXAMPLE FOR StatusSetOr

But to unblock future PRs, I'm okay with making the change in a followup PR.

@MengjinYan
MengjinYan merged commit 4d86c9a into master May 6, 2026
3 checks passed
@MengjinYan
MengjinYan deleted the job_events_missing_fields_2 branch May 6, 2026 18:44
edoakes pushed a commit that referenced this pull request May 6, 2026
## 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]>
Lucas61000 pushed a commit to Lucas61000/ray that referenced this pull request May 15, 2026
## 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]>
Lucas61000 pushed a commit to Lucas61000/ray that referenced this pull request May 15, 2026
…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]>
alexandrplashchinsky pushed a commit to alexandrplashchinsky/ray-alex that referenced this pull request May 29, 2026
## 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]>
alexandrplashchinsky pushed a commit to alexandrplashchinsky/ray-alex that referenced this pull request May 29, 2026
…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]>
sampan-s-nayak added a commit that referenced this pull request Oct 26, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community go add ONLY when ready to merge, run all tests unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ray fails to serialize self-reference objects

4 participants