Skip to content
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

[API Server] Add Ray Job output - start/end time and ray cluster name #2533

Merged
merged 8 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 46 additions & 19 deletions apiserver/pkg/model/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ func FromCrdToApiClusters(clusters []*rayv1api.RayCluster, clusterEventsMap map[

func FromCrdToApiCluster(cluster *rayv1api.RayCluster, events []corev1.Event) *api.Cluster {
pbCluster := &api.Cluster{
Name: cluster.Name,
Namespace: cluster.Namespace,
Version: cluster.Labels[util.RayClusterVersionLabelKey],
User: cluster.Labels[util.RayClusterUserLabelKey],
Environment: api.Cluster_Environment(api.Cluster_Environment_value[cluster.Labels[util.RayClusterEnvironmentLabelKey]]),
Name: cluster.Name,
Namespace: cluster.Namespace,
Version: cluster.Labels[util.RayClusterVersionLabelKey],
User: cluster.Labels[util.RayClusterUserLabelKey],
Environment: api.Cluster_Environment(
api.Cluster_Environment_value[cluster.Labels[util.RayClusterEnvironmentLabelKey]],
),
CreatedAt: &timestamppb.Timestamp{Seconds: cluster.CreationTimestamp.Unix()},
ClusterState: string(cluster.Status.State),
}
Expand Down Expand Up @@ -507,10 +509,23 @@ func FromCrdToApiJob(job *rayv1api.RayJob) (pbJob *api.RayJob) {
pbJob.EntrypointResources = jres
}

if jstarttime := job.Status.StartTime; jstarttime != nil {
pbJob.StartTime = timestamppb.New(job.Status.StartTime.Time)
}
if jendtime := job.Status.EndTime; jendtime != nil {
pbJob.EndTime = timestamppb.New(job.Status.EndTime.Time)
}
if jclustername := job.Status.RayClusterName; jclustername != "" {
pbJob.RayClusterName = jclustername
}

return pbJob
}

func FromCrdToApiServices(services []*rayv1api.RayService, serviceEventsMap map[string][]corev1.Event) []*api.RayService {
func FromCrdToApiServices(
services []*rayv1api.RayService,
serviceEventsMap map[string][]corev1.Event,
) []*api.RayService {
apiServices := make([]*api.RayService, 0)
for _, service := range services {
apiServices = append(apiServices, FromCrdToApiService(service, serviceEventsMap[service.Name]))
Expand All @@ -531,16 +546,20 @@ func FromCrdToApiService(service *rayv1api.RayService, events []corev1.Event) *a
deleteTime = service.DeletionTimestamp.Unix()
}
pbService := &api.RayService{
Name: service.Name,
Namespace: service.Namespace,
User: service.Labels[util.RayClusterUserLabelKey],
ServeConfig_V2: service.Spec.ServeConfigV2,
ClusterSpec: PopulateRayClusterSpec(service.Spec.RayClusterSpec),
ServiceUnhealthySecondThreshold: PoplulateUnhealthySecondThreshold(service.Spec.ServiceUnhealthySecondThreshold),
DeploymentUnhealthySecondThreshold: PoplulateUnhealthySecondThreshold(service.Spec.DeploymentUnhealthySecondThreshold),
RayServiceStatus: PoplulateRayServiceStatus(service.Name, service.Status, events),
CreatedAt: &timestamppb.Timestamp{Seconds: service.CreationTimestamp.Unix()},
DeleteAt: &timestamppb.Timestamp{Seconds: deleteTime},
Name: service.Name,
Namespace: service.Namespace,
User: service.Labels[util.RayClusterUserLabelKey],
ServeConfig_V2: service.Spec.ServeConfigV2,
ClusterSpec: PopulateRayClusterSpec(service.Spec.RayClusterSpec),
ServiceUnhealthySecondThreshold: PoplulateUnhealthySecondThreshold(
service.Spec.ServiceUnhealthySecondThreshold,
),
DeploymentUnhealthySecondThreshold: PoplulateUnhealthySecondThreshold(
service.Spec.DeploymentUnhealthySecondThreshold,
),
RayServiceStatus: PoplulateRayServiceStatus(service.Name, service.Status, events),
CreatedAt: &timestamppb.Timestamp{Seconds: service.CreationTimestamp.Unix()},
DeleteAt: &timestamppb.Timestamp{Seconds: deleteTime},
}
return pbService
}
Expand All @@ -552,7 +571,11 @@ func PoplulateUnhealthySecondThreshold(value *int32) int32 {
return *value
}

func PoplulateRayServiceStatus(serviceName string, serviceStatus rayv1api.RayServiceStatuses, events []corev1.Event) *api.RayServiceStatus {
func PoplulateRayServiceStatus(
serviceName string,
serviceStatus rayv1api.RayServiceStatuses,
events []corev1.Event,
) *api.RayServiceStatus {
status := &api.RayServiceStatus{
RayServiceEvents: PopulateRayServiceEvent(serviceName, events),
RayClusterName: serviceStatus.ActiveServiceStatus.RayClusterName,
Expand All @@ -566,7 +589,9 @@ func PoplulateRayServiceStatus(serviceName string, serviceStatus rayv1api.RaySer
return status
}

func PopulateServeApplicationStatus(serveApplicationStatuses map[string]rayv1api.AppStatus) []*api.ServeApplicationStatus {
func PopulateServeApplicationStatus(
serveApplicationStatuses map[string]rayv1api.AppStatus,
) []*api.ServeApplicationStatus {
appStatuses := make([]*api.ServeApplicationStatus, 0)
for appName, appStatus := range serveApplicationStatuses {
ds := &api.ServeApplicationStatus{
Expand All @@ -580,7 +605,9 @@ func PopulateServeApplicationStatus(serveApplicationStatuses map[string]rayv1api
return appStatuses
}

func PopulateServeDeploymentStatus(serveDeploymentStatuses map[string]rayv1api.ServeDeploymentStatus) []*api.ServeDeploymentStatus {
func PopulateServeDeploymentStatus(
serveDeploymentStatuses map[string]rayv1api.ServeDeploymentStatus,
) []*api.ServeDeploymentStatus {
deploymentStatuses := make([]*api.ServeDeploymentStatus, 0)
for deploymentName, deploymentStatus := range serveDeploymentStatuses {
ds := &api.ServeDeploymentStatus{
Expand Down
47 changes: 45 additions & 2 deletions apiserver/pkg/model/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"reflect"
"testing"
"time"

util "github.com/ray-project/kuberay/apiserver/pkg/util"
api "github.com/ray-project/kuberay/proto/go_client"
Expand Down Expand Up @@ -364,6 +365,30 @@ var JobExistingClusterSubmitterTest = rayv1api.RayJob{
},
}

var JobWithOutputTest = rayv1api.RayJob{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "test",
Labels: map[string]string{
"ray.io/user": "user",
},
},
Spec: rayv1api.RayJobSpec{
Entrypoint: "python /home/ray/samples/sample_code.py",
RuntimeEnvYAML: "mytest yaml",
TTLSecondsAfterFinished: secondsValue,
RayClusterSpec: &ClusterSpecTest.Spec,
},
Status: rayv1api.RayJobStatus{
JobStatus: "RUNNING",
JobDeploymentStatus: "Initializing",
Message: "Job is currently running",
RayClusterName: "raycluster-sample-xxxxx",
StartTime: &metav1.Time{Time: time.Date(2024, 0o7, 25, 0, 0, 0, 0, time.UTC)},
EndTime: nil,
},
}

var ServiceV2Test = rayv1api.RayService{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Expand Down Expand Up @@ -605,11 +630,20 @@ func TestPopulateTemplate(t *testing.T) {
assert.Equal(t, uint32(4), template.Cpu, "CPU mismatch")
assert.Equal(t, uint32(8), template.Memory, "Memory mismatch")
assert.Equal(t, uint32(0), template.Gpu, "GPU mismatch")
assert.Equal(t, map[string]uint32{"vpc.amazonaws.com/efa": 32}, template.ExtendedResources, "Extended resources mismatch")
assert.Equal(
t,
map[string]uint32{"vpc.amazonaws.com/efa": 32},
template.ExtendedResources,
"Extended resources mismatch",
)
}

func tolerationToString(toleration *api.PodToleration) string {
return "Key: " + toleration.Key + " Operator: " + string(toleration.Operator) + " Effect: " + string(toleration.Effect)
return "Key: " + toleration.Key + " Operator: " + string(
toleration.Operator,
) + " Effect: " + string(
toleration.Effect,
)
}

func TestPopulateJob(t *testing.T) {
Expand Down Expand Up @@ -641,4 +675,13 @@ func TestPopulateJob(t *testing.T) {
assert.Nil(t, job.ClusterSpec)
assert.Equal(t, "image", job.JobSubmitter.Image)
assert.Equal(t, "2", job.JobSubmitter.Cpu)

job = FromCrdToApiJob(&JobWithOutputTest)
fmt.Printf("jobWithOutput = %#v\n", job)
assert.Equal(t, time.Date(2024, 0o7, 25, 0, 0, 0, 0, time.UTC), job.StartTime.AsTime())
assert.Nil(t, job.EndTime)
assert.Equal(t, "RUNNING", job.JobStatus)
assert.Equal(t, "Initializing", job.JobDeploymentStatus)
assert.Equal(t, "Job is currently running", job.Message)
assert.Equal(t, "raycluster-sample-xxxxx", job.RayClusterName)
}
2 changes: 1 addition & 1 deletion apiserver/test/e2e/job_server_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func TestGetJobsInNamespace(t *testing.T) {
require.NoError(t, err, "No error expected")
require.Nil(t, actualRpcStatus, "No RPC status expected")
require.NotNil(t, response, "A response is expected")
require.NotEmpty(t, response.Jobs, "A list of compute templates is required")
require.NotEmpty(t, response.Jobs, "A list of jobs is required")
foundName := false
for _, job := range response.Jobs {
if testJobRequest.Job.Name == job.Name && tCtx.GetNamespaceName() == job.Namespace {
Expand Down
Loading
Loading