Skip to content

Commit 7ddb657

Browse files
committed
convert timestamp
1 parent b00e39d commit 7ddb657

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

historyserver/pkg/eventserver/eventserver.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,13 @@ func transformToEvent(eventMap map[string]any) *types.Event {
204204
if v, ok := eventMap["sourceType"].(string); ok {
205205
event.SourceType = v
206206
}
207+
// Convert ISO 8601 timestamp to Unix milliseconds to match Ray Dashboard format
207208
if v, ok := eventMap["timestamp"].(string); ok {
208-
event.Timestamp = v
209+
if t, err := time.Parse(time.RFC3339Nano, v); err == nil {
210+
event.Timestamp = fmt.Sprintf("%d", t.UnixMilli())
211+
} else {
212+
event.Timestamp = v // Keep original if parsing fails
213+
}
209214
}
210215
if v, ok := eventMap["severity"].(string); ok {
211216
event.Severity = v

historyserver/pkg/eventserver/eventserver_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,3 +928,34 @@ func TestMultipleReprocessingCycles(t *testing.T) {
928928
}
929929
}
930930
}
931+
932+
func TestTransformToEventTimestamp(t *testing.T) {
933+
// Test that transformToEvent correctly converts timestamp format
934+
eventMap := map[string]any{
935+
"eventId": "test-event-id",
936+
"eventType": "TASK_DEFINITION_EVENT",
937+
"sourceType": "CORE_WORKER",
938+
"timestamp": "2026-01-16T19:22:49.414579427Z",
939+
"severity": "INFO",
940+
"taskDefinitionEvent": map[string]any{
941+
"taskId": "task-123",
942+
"jobId": "AQAAAA==",
943+
},
944+
}
945+
946+
event := transformToEvent(eventMap)
947+
948+
// Verify timestamp is converted to Unix milliseconds
949+
expectedTimestamp := "1768591369414"
950+
if event.Timestamp != expectedTimestamp {
951+
t.Errorf("transformToEvent timestamp = %q, want %q", event.Timestamp, expectedTimestamp)
952+
}
953+
954+
// Verify other fields are preserved
955+
if event.EventID != "test-event-id" {
956+
t.Errorf("EventID = %q, want %q", event.EventID, "test-event-id")
957+
}
958+
if event.SourceType != "CORE_WORKER" {
959+
t.Errorf("SourceType = %q, want %q", event.SourceType, "CORE_WORKER")
960+
}
961+
}

0 commit comments

Comments
 (0)