-
Notifications
You must be signed in to change notification settings - Fork 698
[Feature][history server] support endpoint /events #4479
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ type EventHandler struct { | |
| ClusterTaskMap *types.ClusterTaskMap | ||
| ClusterActorMap *types.ClusterActorMap | ||
| ClusterJobMap *types.ClusterJobMap | ||
| ClusterEventMap *types.ClusterEventMap // For /events API | ||
| } | ||
|
|
||
| var eventFilePattern = regexp.MustCompile(`-\d{4}-\d{2}-\d{2}-\d{2}$`) | ||
|
|
@@ -48,6 +49,7 @@ func NewEventHandler(reader storage.StorageReader) *EventHandler { | |
| ClusterJobMap: &types.ClusterJobMap{ | ||
| ClusterJobMap: make(map[string]*types.JobMap), | ||
| }, | ||
| ClusterEventMap: types.NewClusterEventMap(), | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -186,6 +188,133 @@ func (h *EventHandler) Run(stop chan struct{}, numOfEventProcessors int) error { | |
| return nil | ||
| } | ||
|
|
||
| // transformToEvent converts a RayEvent map to the API response Event format. | ||
| // This extracts common fields and puts event-type-specific data into customFields. | ||
| // It also extracts sourceHostname and sourcePid from nested events where available. | ||
| func transformToEvent(eventMap map[string]any) *types.Event { | ||
| event := &types.Event{ | ||
| Severity: "INFO", | ||
| CustomFields: make(map[string]any), | ||
| } | ||
|
|
||
| // Extract common fields (already camelCase) | ||
| if v, ok := eventMap["eventId"].(string); ok { | ||
| event.EventID = v | ||
| } | ||
| if v, ok := eventMap["sourceType"].(string); ok { | ||
| event.SourceType = v | ||
| } | ||
| // Convert ISO 8601 timestamp to Unix milliseconds to match Ray Dashboard format | ||
| if v, ok := eventMap["timestamp"].(string); ok { | ||
| if t, err := time.Parse(time.RFC3339Nano, v); err == nil { | ||
| event.Timestamp = fmt.Sprintf("%d", t.UnixMilli()) | ||
| } else { | ||
| logrus.Warnf("failed to parse timestamp %q: %v", v, err) | ||
| } | ||
| } | ||
| if v, ok := eventMap["severity"].(string); ok { | ||
| event.Severity = v | ||
| } | ||
| if v, ok := eventMap["message"].(string); ok { | ||
| event.Message = v | ||
| } | ||
| if v, ok := eventMap["sessionName"].(string); ok { | ||
| event.CustomFields["sessionName"] = v | ||
| } | ||
| // Extract nodeId from base RayEvent (field #18) | ||
| if v, ok := eventMap["nodeId"].(string); ok { | ||
| event.NodeID = v | ||
| } | ||
|
|
||
| // Extract eventType and set as Label for filtering | ||
| eventType, _ := eventMap["eventType"].(string) | ||
| event.EventType = eventType | ||
| event.Label = eventType // Use eventType as label for Dashboard compatibility | ||
|
|
||
| // Map eventType to its corresponding nested data field | ||
| eventDataFields := map[string]string{ | ||
| string(types.TASK_DEFINITION_EVENT): "taskDefinitionEvent", | ||
| string(types.TASK_LIFECYCLE_EVENT): "taskLifecycleEvent", | ||
| string(types.TASK_PROFILE_EVENT): "taskProfileEvents", | ||
| string(types.ACTOR_DEFINITION_EVENT): "actorDefinitionEvent", | ||
| string(types.ACTOR_LIFECYCLE_EVENT): "actorLifecycleEvent", | ||
| string(types.ACTOR_TASK_DEFINITION_EVENT): "actorTaskDefinitionEvent", | ||
| string(types.NODE_DEFINITION_EVENT): "nodeDefinitionEvent", | ||
| string(types.NODE_LIFECYCLE_EVENT): "nodeLifecycleEvent", | ||
| string(types.DRIVER_JOB_DEFINITION_EVENT): "driverJobDefinitionEvent", | ||
| string(types.DRIVER_JOB_LIFECYCLE_EVENT): "driverJobLifecycleEvent", | ||
| } | ||
|
|
||
| if dataField, ok := eventDataFields[eventType]; ok { | ||
| if data, ok := eventMap[dataField].(map[string]any); ok { | ||
| event.CustomFields[dataField] = data | ||
|
|
||
| // Extract sourceHostname and sourcePid from nested events where available | ||
| extractHostnameAndPid(event, eventType, data) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Task profile event data may be silently lostMedium Severity The field Additional Locations (1)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The concern is not valid. The
|
||
| } | ||
|
|
||
| return event | ||
| } | ||
|
|
||
| // extractHostnameAndPid extracts sourceHostname and sourcePid from nested event data. | ||
| // These fields are available in specific event types as discovered from Ray protos. | ||
| func extractHostnameAndPid(event *types.Event, eventType string, data map[string]any) { | ||
| switch eventType { | ||
| case string(types.NODE_DEFINITION_EVENT): | ||
| // NodeDefinitionEvent has: hostname, node_name, node_ip_address | ||
| if hostname, ok := data["hostname"].(string); ok && hostname != "" { | ||
| event.SourceHostname = hostname | ||
| } | ||
| case string(types.TASK_LIFECYCLE_EVENT): | ||
| // TaskLifecycleEvent has: worker_pid, worker_id, node_id | ||
| if pid, ok := data["workerPid"].(float64); ok { | ||
| event.SourcePid = int(pid) | ||
| } | ||
| case string(types.ACTOR_LIFECYCLE_EVENT): | ||
| // ActorLifecycleEvent has pid in StateTransition when ALIVE | ||
| if transitions, ok := data["stateTransitions"].([]any); ok && len(transitions) > 0 { | ||
| // Get the latest transition | ||
| if lastTransition, ok := transitions[len(transitions)-1].(map[string]any); ok { | ||
| if pid, ok := lastTransition["pid"].(float64); ok { | ||
| event.SourcePid = int(pid) | ||
| } | ||
| } | ||
| } | ||
| case string(types.DRIVER_JOB_DEFINITION_EVENT): | ||
| // DriverJobDefinitionEvent has: driver_pid, driver_node_id | ||
| if pid, ok := data["driverPid"].(float64); ok { | ||
| event.SourcePid = int(pid) | ||
| } else if pidStr, ok := data["driverPid"].(string); ok && pidStr != "" { | ||
| // Sometimes stored as string | ||
| var pidInt int | ||
| if _, err := fmt.Sscanf(pidStr, "%d", &pidInt); err == nil { | ||
| event.SourcePid = pidInt | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // extractJobIDFromEvent extracts jobId from various event type payloads | ||
| func extractJobIDFromEvent(eventMap map[string]any) string { | ||
| // Check common nested structures for jobId | ||
| nestedFields := []string{ | ||
| "taskDefinitionEvent", "taskLifecycleEvent", | ||
| "actorDefinitionEvent", "actorLifecycleEvent", | ||
| "driverJobDefinitionEvent", "driverJobLifecycleEvent", | ||
| "taskProfileEvents", "actorTaskDefinitionEvent", | ||
| } | ||
|
|
||
| for _, field := range nestedFields { | ||
| if nested, ok := eventMap[field].(map[string]any); ok { | ||
| if jobID, ok := nested["jobId"].(string); ok && jobID != "" { | ||
| return jobID | ||
| } | ||
| } | ||
| } | ||
| return "" // Will be grouped under "global" | ||
| } | ||
|
|
||
| // storeEvent unmarshals the event map into the correct actor/task struct and then stores it into the corresonding list | ||
| func (h *EventHandler) storeEvent(eventMap map[string]any) error { | ||
| eventTypeVal, ok := eventMap["eventType"] | ||
|
|
@@ -207,6 +336,14 @@ func (h *EventHandler) storeEvent(eventMap map[string]any) error { | |
| return fmt.Errorf("clusterName is not a string, got %T", clusterNameVal) | ||
| } | ||
|
|
||
| // ========== Store RayEvent for /events API ========== | ||
| if event := transformToEvent(eventMap); event != nil && event.EventID != "" { | ||
| jobID := extractJobIDFromEvent(eventMap) | ||
| clusterEventMap := h.ClusterEventMap.GetOrCreateEventMap(currentClusterName) | ||
| clusterEventMap.AddEvent(jobID, *event) | ||
| } | ||
| // ==================================================== | ||
|
|
||
| logrus.Infof("current eventType: %v", eventType) | ||
| switch eventType { | ||
| case types.TASK_DEFINITION_EVENT: | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.