Repository navigation
[Core] Support publishing Submission job events using ray event recorder - #61099
Conversation
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
…nto job_events_missing_fields_3 Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request successfully integrates the Ray event recorder framework into the job submission system, enabling the emission of job definition and lifecycle events. The implementation follows the existing pattern for actor and node events, using a priority-based approach where the new framework takes precedence when enabled. The addition of an end-to-end test ensures the correctness of event emission and capture. I have provided a few suggestions to improve the efficiency of protobuf timestamp handling and to ensure robust initialization of the event recorder.
| now = time.time() | ||
| transition.timestamp.CopyFrom( | ||
| Timestamp(seconds=int(now), nanos=int((now % 1) * 1e9)) | ||
| ) |
There was a problem hiding this comment.
Instead of creating a new Timestamp object and using CopyFrom, you can use the FromMilliseconds method directly on the existing transition.timestamp object. This is more efficient and avoids manual nanosecond calculations which can sometimes suffer from floating-point precision issues.
| now = time.time() | |
| transition.timestamp.CopyFrom( | |
| Timestamp(seconds=int(now), nanos=int((now % 1) * 1e9)) | |
| ) | |
| transition.timestamp.FromMilliseconds(int(time.time() * 1000)) |
| if ray_constants.RAY_ENABLE_RAY_EVENT: | ||
| try: | ||
| from ray._raylet import initialize_event_recorder | ||
|
|
||
| initialize_event_recorder( | ||
| aggregator_address=self._dashboard_agent.ip, | ||
| aggregator_port=self._dashboard_agent.grpc_port, | ||
| node_ip=self._dashboard_agent.ip, | ||
| node_id_hex=self._dashboard_agent.node_id, | ||
| max_buffer_size=10000, | ||
| ) | ||
| logger.info("Initialized ray event recorder in JobAgent.") | ||
| except Exception: | ||
| logger.warning( | ||
| "Failed to initialize ray event recorder in JobAgent.", | ||
| exc_info=True, | ||
| ) |
There was a problem hiding this comment.
The initialize_event_recorder call is placed within the run method of JobAgent. While this works for initialization, consider if a corresponding shutdown_event_recorder call is needed when the agent or module stops, similar to the implementation in JobSupervisor. This ensures that any buffered events are flushed before the process exits.
Signed-off-by: sampan <[email protected]>
…elds_3 Signed-off-by: sampan <[email protected]>
…ss attribute Cython cdef class types are immutable — setting EventRecorder._instance at module scope raises TypeError at runtime. Use a module-level _event_recorder_instance variable with global declarations instead. Signed-off-by: sampan <[email protected]>
…elds_3 Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Signed-off-by: sampan <[email protected]>
Fixes #65608. ## Problem `JobManager` records the head's GCS address at construction and passes it to every detached `JobSupervisor`, which builds its own `GcsClient` from it: ```python # job_manager.py self._gcs_address = gcs_client.address ... supervisor = self._supervisor_actor_cls.options(...).remote( submission_id, entrypoint, metadata or {}, self._gcs_address, self._cluster_id_hex, self._logs_dir, ) # job_supervisor.py gcs_client = GcsClient(address=gcs_address, cluster_id=cluster_id_hex) ``` With GCS fault tolerance the head pod can be replaced while a job keeps running on a worker. The worker's raylet and CoreWorker reconnect through the stable head service, but the supervisor's separately constructed client stays pinned to the old address. When the entrypoint exits with code 0, `put_status(SUCCEEDED)` times out, the broad exception handler writes `FAILED`, and the job is reported as `JOB_SUPERVISOR_ACTOR_DIED` despite having succeeded. ## Fix Use the GCS client already configured for the worker process hosting the actor, which reconnects through the stable head service: ```python gcs_client = ray._private.worker.global_worker.gcs_client ``` `gcs_address` and `cluster_id_hex` existed only to build that client, so they are removed from the supervisor's signature and from the `JobManager` side. The same file already uses worker-local state a few lines below (`ray._private.worker.global_worker.node`), so this follows existing practice here. Net -4 lines. ## Not a duplicate `#65027` also concerns jobs during GCS failover, but patches `job_manager.py`'s monitor loop to retry transient gRPC errors. This patches `job_supervisor.py`'s client construction. They are complementary: retries in the monitor cannot help a supervisor whose own client is pinned to an address nothing is listening on. No other open PR references #65608. `gh pr list --search "job_supervisor"` and `--search "JobSupervisor gcs"` surfaced only #65006, #47166, #61099 and #65027, none of which touch this client construction. ## Testing Added `test_job_succeeds_when_manager_gcs_address_is_stale` in `python/ray/dashboard/modules/job/tests/test_job_manager.py`. The full reported path needs KubeRay with GCS FT and a head replacement; the essential condition is that the address the manager recorded is unusable while the worker's own client still works. `_StaleAddressGcsClient` wraps the live client and reports `127.0.0.1:1`, which is reserved and never bound. ``` python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -k stale -q ``` - on master: `1 failed` — the supervisor cannot persist the terminal status - with this change: `1 passed` in 12.70s Surrounding tests that exercise supervisor construction, job submission, supervisor logging and the existing failover path: ``` python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -q -p no:randomly \ -k "stale or network_fault_tolerance or supervisor_log_json or supervisor_logs_saved \ or submit_no_ray_address or get_all_job_info" 7 passed, 63 deselected in 82.54s ``` Lint, using the repo's own configuration: ``` pre-commit run --files python/ray/dashboard/modules/job/job_supervisor.py \ python/ray/dashboard/modules/job/job_manager.py \ python/ray/dashboard/modules/job/tests/test_job_manager.py ruff / pydoclint / black / Ray docstyle / semgrep / import order: all Passed ``` I did not get a clean full-module run locally: `test_job_manager.py` in its entirety stalls on this machine shortly after start (pytest idle at 0% CPU, no Ray processes alive) both with and without this change, so it looks unrelated to it. Happy to run anything specific a reviewer wants. Ray installed as `ray[default]` 2.58.0 with `python/ray/setup-dev.py` symlinks; tested on macOS (Apple silicon). ## Out of scope The `except Exception` handler in `JobSupervisor.run` reclassifies a failure to *persist* an already-known result as `JOB_ENTRYPOINT_COMMAND_START_ERROR`. That is a real second defect, but transient-error handling in this area is the subject of #65027, so it is left alone here to avoid a collision. ## AI usage AI assistance was used for the investigation, the code change, and the test. I reviewed every changed line, ran the commands above myself, and can explain and defend the change. Signed-off-by: Roshan Sharma <[email protected]>
machichima
left a comment
There was a problem hiding this comment.
Doing the first pass and leave a few comments
| # Mapping from JobStatus name to SubmissionJobLifecycleEvent.State enum value. | ||
| _JOB_STATUS_TO_PROTO_STATE = { | ||
| "PENDING": SubmissionJobLifecycleEvent.State.PENDING, | ||
| "RUNNING": SubmissionJobLifecycleEvent.State.RUNNING, | ||
| "STOPPED": SubmissionJobLifecycleEvent.State.STOPPED, | ||
| "SUCCEEDED": SubmissionJobLifecycleEvent.State.SUCCEEDED, | ||
| "FAILED": SubmissionJobLifecycleEvent.State.FAILED, | ||
| } | ||
|
|
||
|
|
||
| def job_status_to_proto_state( | ||
| status_name: str, | ||
| ) -> Optional[int]: | ||
| """Convert a JobStatus name to the proto State enum value. | ||
|
|
||
| Returns None if the status name is not recognized. | ||
| """ | ||
| return _JOB_STATUS_TO_PROTO_STATE.get(status_name) |
There was a problem hiding this comment.
I'm thinking if we can do this here directly and do not need an extra _JOB_STATUS_TO_PROTO_STATE map
value = SubmissionJobLifecycleEvent.State.DESCRIPTOR.values_by_name.get(
status_name
)
return value.number if value is not None else NoneSimilar to what we have here:
ray/python/ray/dashboard/modules/job/common.py
Lines 409 to 413 in 944e1a4
| agent_info_raw = await self._job_info_client._gcs_client.async_internal_kv_get( | ||
| f"{DASHBOARD_AGENT_ADDR_NODE_ID_PREFIX}{driver_node_id}".encode(), | ||
| namespace=KV_NAMESPACE_DASHBOARD, | ||
| ) | ||
| if agent_info_raw: | ||
| _, _, grpc_port = json.loads(agent_info_raw) |
There was a problem hiding this comment.
Just curious, I think we only need grpc_port here? Are we able to get through ray._private.worker.global_worker.node using node.metrics_agent_port?
node = ray._private.worker.global_worker.nodeThere was a problem hiding this comment.
yeah I think we can do this as we start the dashboard agent with metrics-export-port set https://github.com/sampan-s-nayak/ray/blob/08603fa400c8312449261fc6b6566e162e01b251/python/ray/_private/services.py#L1862-L1883
| entrypoint_num_cpus=job_info.entrypoint_num_cpus, | ||
| entrypoint_num_gpus=job_info.entrypoint_num_gpus, | ||
| entrypoint_memory=job_info.entrypoint_memory, | ||
| entrypoint_resources=job_info.entrypoint_resources, |
There was a problem hiding this comment.
curious, do we need to set session_name?
There was a problem hiding this comment.
yeah I think we should
| entrypoint_memory=job_info.entrypoint_memory, | ||
| entrypoint_resources=job_info.entrypoint_resources, | ||
| ) | ||
| EventRecorder.emit(builder.build()) |
There was a problem hiding this comment.
Should we log warning if it return false?
ray/python/ray/includes/event_recorder.pxi
Lines 194 to 204 in 944e1a4
| ) | ||
| self._submission_id = submission_id | ||
| self._state = state | ||
| self._message = message |
There was a problem hiding this comment.
Saw this previous bot review comment: #61099 (comment), I think it's valid. Should we change message to default to "" rather than None and pass it to super().__init__() directly?
Signed-off-by: sampan <[email protected]>
…g_fields_3 Signed-off-by: sampan <[email protected]> # Conflicts: # python/ray/dashboard/modules/job/job_manager.py # python/ray/dashboard/modules/job/job_supervisor.py
…oject#65686) Fixes ray-project#65608. ## Problem `JobManager` records the head's GCS address at construction and passes it to every detached `JobSupervisor`, which builds its own `GcsClient` from it: ```python # job_manager.py self._gcs_address = gcs_client.address ... supervisor = self._supervisor_actor_cls.options(...).remote( submission_id, entrypoint, metadata or {}, self._gcs_address, self._cluster_id_hex, self._logs_dir, ) # job_supervisor.py gcs_client = GcsClient(address=gcs_address, cluster_id=cluster_id_hex) ``` With GCS fault tolerance the head pod can be replaced while a job keeps running on a worker. The worker's raylet and CoreWorker reconnect through the stable head service, but the supervisor's separately constructed client stays pinned to the old address. When the entrypoint exits with code 0, `put_status(SUCCEEDED)` times out, the broad exception handler writes `FAILED`, and the job is reported as `JOB_SUPERVISOR_ACTOR_DIED` despite having succeeded. ## Fix Use the GCS client already configured for the worker process hosting the actor, which reconnects through the stable head service: ```python gcs_client = ray._private.worker.global_worker.gcs_client ``` `gcs_address` and `cluster_id_hex` existed only to build that client, so they are removed from the supervisor's signature and from the `JobManager` side. The same file already uses worker-local state a few lines below (`ray._private.worker.global_worker.node`), so this follows existing practice here. Net -4 lines. ## Not a duplicate `ray-project#65027` also concerns jobs during GCS failover, but patches `job_manager.py`'s monitor loop to retry transient gRPC errors. This patches `job_supervisor.py`'s client construction. They are complementary: retries in the monitor cannot help a supervisor whose own client is pinned to an address nothing is listening on. No other open PR references ray-project#65608. `gh pr list --search "job_supervisor"` and `--search "JobSupervisor gcs"` surfaced only ray-project#65006, ray-project#47166, ray-project#61099 and ray-project#65027, none of which touch this client construction. ## Testing Added `test_job_succeeds_when_manager_gcs_address_is_stale` in `python/ray/dashboard/modules/job/tests/test_job_manager.py`. The full reported path needs KubeRay with GCS FT and a head replacement; the essential condition is that the address the manager recorded is unusable while the worker's own client still works. `_StaleAddressGcsClient` wraps the live client and reports `127.0.0.1:1`, which is reserved and never bound. ``` python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -k stale -q ``` - on master: `1 failed` — the supervisor cannot persist the terminal status - with this change: `1 passed` in 12.70s Surrounding tests that exercise supervisor construction, job submission, supervisor logging and the existing failover path: ``` python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -q -p no:randomly \ -k "stale or network_fault_tolerance or supervisor_log_json or supervisor_logs_saved \ or submit_no_ray_address or get_all_job_info" 7 passed, 63 deselected in 82.54s ``` Lint, using the repo's own configuration: ``` pre-commit run --files python/ray/dashboard/modules/job/job_supervisor.py \ python/ray/dashboard/modules/job/job_manager.py \ python/ray/dashboard/modules/job/tests/test_job_manager.py ruff / pydoclint / black / Ray docstyle / semgrep / import order: all Passed ``` I did not get a clean full-module run locally: `test_job_manager.py` in its entirety stalls on this machine shortly after start (pytest idle at 0% CPU, no Ray processes alive) both with and without this change, so it looks unrelated to it. Happy to run anything specific a reviewer wants. Ray installed as `ray[default]` 2.58.0 with `python/ray/setup-dev.py` symlinks; tested on macOS (Apple silicon). ## Out of scope The `except Exception` handler in `JobSupervisor.run` reclassifies a failure to *persist* an already-known result as `JOB_ENTRYPOINT_COMMAND_START_ERROR`. That is a real second defect, but transient-error handling in this area is the subject of ray-project#65027, so it is left alone here to avoid a collision. ## AI usage AI assistance was used for the investigation, the code change, and the test. I reviewed every changed line, ran the commands above myself, and can explain and defend the change. Signed-off-by: Roshan Sharma <[email protected]>
Signed-off-by: sampan <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b7ed61b. Configure here.
| // For static information associated with this event, see SubmissionJobDefinitionEvent. | ||
| message SubmissionJobLifecycleEvent { | ||
| // NOTE: keep in sync with JobStatus in | ||
| // python/ray/dashboard/modules/job/common.py. |
There was a problem hiding this comment.
Proto change needs fault-tolerance review
Low Severity
.proto files.
Please review the RPC fault-tolerance & idempotency standards guide here:
https://github.com/ray-project/ray/tree/master/doc/source/core/internals/rpc-fault-tolerance.md
Triggered by project rule: Bugbot Rules
Reviewed by Cursor Bugbot for commit b7ed61b. Configure here.
|
@MengjinYan thanks, addressed comments + updated description |
The dashboard agent exits via os._exit on SIGTERM and is SIGKILLed by the raylet on normal shutdown, so the atexit hook never runs. The supervisor keeps its explicit shutdown. Signed-off-by: sampan <[email protected]>
|
Hi @MengjinYan @sampan-s-nayak, Edited: |


Description
this pr migrates submission job events to go through the events recorder framework (proto changes have already been merged). Uses the python event recorder bindings 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:
SUBMISSION_JOB_DEFINITION_EVENT_TYPEandSUBMISSION_JOB_LIFECYCLE_EVENT_TYPEnote: when the ray event recorder path is enabled the old event export path is disabled