mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
+10









Andrew Sy Kim
GitHub
Ping
Han-Ju Chen
Ryan O'Leary
Kai-Hsun Chen
Kavish
Neo Chien
cchung100m
JustinYeh
Jun-Hao Wan
Divyam Raj
Nary Yeh
Alima Azamat
Spencer Peterson
dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Rueian
Cheng-Yeh Chung
fscnick
Copilot
f68857e9ff
* [Bug] Sidecar mode shouldn't restart head pod when head pod is deleted (#4141) * [Bug] Sidecar mode shouldn't restart head pod when head pod is deleted Signed-off-by: 400Ping <[email protected]> * [Fix] Fix e2e error Signed-off-by: 400Ping <[email protected]> * [Fix] fix according to rueian's comment Signed-off-by: 400Ping <[email protected]> * [Chore] fix ci error Signed-off-by: 400Ping <[email protected]> * Update ray-operator/controllers/ray/raycluster_controller.go Co-authored-by: Han-Ju Chen (Future-Outlier) <[email protected]> Signed-off-by: Ping <[email protected]> * Update ray-operator/controllers/ray/rayjob_controller.go Co-authored-by: Han-Ju Chen (Future-Outlier) <[email protected]> Signed-off-by: Ping <[email protected]> * update Signed-off-by: Future-Outlier <[email protected]> * update Signed-off-by: Future-Outlier <[email protected]> * Trigger CI Signed-off-by: Future-Outlier <[email protected]> --------- Signed-off-by: 400Ping <[email protected]> Signed-off-by: Ping <[email protected]> Signed-off-by: Future-Outlier <[email protected]> Co-authored-by: Han-Ju Chen (Future-Outlier) <[email protected]> * fix: dashboard build for kuberay 1.5.0 (#4161) Signed-off-by: Future-Outlier <[email protected]> * [Feature Enhancement] Set ordered replica index label to support multi-slice (#4163) * [Feature Enhancement] Set ordered replica index label to support multi-slice Signed-off-by: Ryan O'Leary <[email protected]> * rename replica-id -> replica-name Signed-off-by: Ryan O'Leary <[email protected]> * Separate replica index feature gate logic Signed-off-by: Ryan O'Leary <[email protected]> * remove index arg in createWorkerPod Signed-off-by: Ryan O'Leary <[email protected]> --------- Signed-off-by: Ryan O'Leary <[email protected]> * update stale feature gate comments (#4174) Signed-off-by: Andrew Sy Kim <[email protected]> * [RayCluster] Add more context why we don't recreate head Pod for RayJob (#4175) Signed-off-by: Kai-Hsun Chen <[email protected]> * feature: Remove empty resource list initialization. (#4168) Fixes #4142. * [Dockerfile] [KubeRay Dashboard]: Fix Dockerfile warnings (ENV format, CMD JSON args) (#4167) * [#4166] improvement: Fix Dockerfile warnings (ENV format, CMD JSON args) * extract the hostname from CMD Signed-off-by: Neo Chien <[email protected]> --------- Signed-off-by: Neo Chien <[email protected]> Co-authored-by: cchung100m <[email protected]> * [Fix] Resolve int32 overflow by having the calculation in int64 and c… (#4158) * [Fix] Resolve int32 overflow by having the calculation in int64 and cap it if the count is over math.MaxInt32 Signed-off-by: justinyeh1995 <[email protected]> * [Test] Add unit tests for CalculateReadyReplicas Signed-off-by: justinyeh1995 <[email protected]> * [Fix] Add a nosec comment to pass the Lint (pre-commit) test Signed-off-by: justinyeh1995 <[email protected]> * [Refactor] Add CapInt64ToInt32 to replace #nosec directives Signed-off-by: justinyeh1995 <[email protected]> * [Refactor] Rename function to SafeInt64ToInt32 and add a underflowing prevention (it also help pass the lint test) Signed-off-by: justinyeh1995 <[email protected]> * [Refactor] Remove the early return as SafeInt64ToInt32 handles the int32 overflow and underflow checking. Signed-off-by: justinyeh1995 <[email protected]> --------- Signed-off-by: justinyeh1995 <[email protected]> * Add RayService incremental upgrade sample for guide (#4164) Signed-off-by: Ryan O'Leary <[email protected]> * Edit RayCluster example config for label selectors (#4151) Signed-off-by: Ryan O'Leary <[email protected]> * [RayJob] update light weight submitter image from quay.io (#4181) Signed-off-by: Future-Outlier <[email protected]> * [flaky] RayJob fails when head Pod is deleted when job is running (#4182) Signed-off-by: Future-Outlier <[email protected]> * [CI] Pin Docker api version to avoid API version mismatch (#4188) Signed-off-by: win5923 <[email protected]> * Make replicas configurable for kuberay-operator #4180 (#4195) * Make replicas configurable for kuberay-operator #4180 * Make replicas configurable for kuberay-operator #4180 * [Fix] rayjob update raycluster status (#4192) * feat: check if raycluster status update in rayjob * test: e2e test to check the rayjob raycluster status update * fix: dashboard http client tests discovered and passing (#4173) Signed-off-by: alimaazamat <[email protected]> * [RayJob] Lift cluster status while initializing (#4191) Signed-off-by: Spencer Peterson <[email protected]> * [RayJob] Remove updateJobStatus call (#4198) Fast follow to #4191 Signed-off-by: Spencer Peterson <[email protected]> * Add support for Ray token auth (#4179) * Add support for Ray token auth Signed-off-by: Andrew Sy Kim <[email protected]> * add e2e test for Ray cluster auth Signed-off-by: Andrew Sy Kim <[email protected]> * address nits from Ruiean Signed-off-by: Andrew Sy Kim <[email protected]> * update RAY_auth_mode -> RAY_AUTH_MODE Signed-off-by: Andrew Sy Kim <[email protected]> * configure auth for Ray autoscaler Signed-off-by: Andrew Sy Kim <[email protected]> --------- Signed-off-by: Andrew Sy Kim <[email protected]> * Bump js-yaml from 4.1.0 to 4.1.1 in /dashboard (#4194) Bumps [js-yaml](https://github.com/nodeca/js-yaml) from 4.1.0 to 4.1.1. - [Changelog](https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md) - [Commits](https://github.com/nodeca/js-yaml/compare/4.1.0...4.1.1) --- updated-dependencies: - dependency-name: js-yaml dependency-version: 4.1.1 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * update minimum Ray version required for token authentication to 2.52.0 (#4201) * update minimum Ray version required for token authentication to 2.52.0 Signed-off-by: Andrew Sy Kim <[email protected]> * update RayCluster auth e2e test to use Ray v2.52 Signed-off-by: Andrew Sy Kim <[email protected]> --------- Signed-off-by: Andrew Sy Kim <[email protected]> * add samples for RayCluster token auth (#4200) Signed-off-by: Andrew Sy Kim <[email protected]> * update (#4208) Signed-off-by: Future-Outlier <[email protected]> * [RayJob] Add token authentication support for All mode (#4210) * dashboard client authentication support Signed-off-by: Future-Outlier <[email protected]> * support rayjob Signed-off-by: Future-Outlier <[email protected]> * update to fix api serverr err Signed-off-by: Future-Outlier <[email protected]> * update Signed-off-by: Future-Outlier <[email protected]> * updarte Signed-off-by: Future-Outlier <[email protected]> * Rayjob sidecar mode auth token mode support Signed-off-by: Future-Outlier <[email protected]> * RayJob support k8s job mode Signed-off-by: Future-Outlier <[email protected]> * update Signed-off-by: Future-Outlier <[email protected]> * update Signed-off-by: Future-Outlier <[email protected]> * update Signed-off-by: Future-Outlier <[email protected]> * Address Andrew's advice Signed-off-by: Future-Outlier <[email protected]> * add todo x-ray-authorization comments Signed-off-by: Future-Outlier <[email protected]> --------- Signed-off-by: Future-Outlier <[email protected]> * [RayCluster] Enable Secret informer watch/list and remove unused RBAC verbs (#4202) * Add authentication secret reconciliation support Signed-off-by: Future-Outlier <[email protected]> * update Signed-off-by: Future-Outlier <[email protected]> * update Signed-off-by: Future-Outlier <[email protected]> * fix flaky test Signed-off-by: Future-Outlier <[email protected]> * remove test fix Signed-off-by: Rueian <[email protected]> --------- Signed-off-by: Future-Outlier <[email protected]> Signed-off-by: Rueian <[email protected]> Co-authored-by: Rueian <[email protected]> * [APIServer][Docs] Add user guide for retry behavior & configuration (#4144) * [Docs] Add the draft description about feature intro, configurations, and usecases Signed-off-by: justinyeh1995 <[email protected]> * [Fix] Update the retry walk-through Signed-off-by: justinyeh1995 <[email protected]> * [Doc] rewrite the first 2 sections Signed-off-by: justinyeh1995 <[email protected]> * [Doc] Revise documentation wording and add Observing Retry Behavior section Signed-off-by: justinyeh1995 <[email protected]> * [Fix] fix linting issue by running pre-commit run berfore commiting Signed-off-by: justinyeh1995 <[email protected]> * [Fix] fix linting errors in the Markdown linting Signed-off-by: justinyeh1995 <[email protected]> * [Fix] Clean up the math equation Signed-off-by: justinyeh1995 <[email protected]> * Update the math formula of Backoff calculation. Co-authored-by: Nary Yeh <[email protected]> Signed-off-by: JustinYeh <[email protected]> * [Fix] Explicitly mentioned exponential backoff and removed the customization parts Signed-off-by: justinyeh1995 <[email protected]> * [Docs] Clarify naming by replacing “APIServer” with “KubeRay APIServer” Co-authored-by: Cheng-Yeh Chung <[email protected]> Signed-off-by: JustinYeh <[email protected]> * [Docs] Rename retry-configuration.md to retry-behavior.md for accuracy Signed-off-by: justinyeh1995 <[email protected]> * Update Title to KubeRay APIServer Retry Behavior Co-authored-by: Cheng-Yeh Chung <[email protected]> Signed-off-by: JustinYeh <[email protected]> * [Docs] Add a note about the limitation of retry configuration Signed-off-by: justinyeh1995 <[email protected]> --------- Signed-off-by: justinyeh1995 <[email protected]> Signed-off-by: JustinYeh <[email protected]> Co-authored-by: Nary Yeh <[email protected]> Co-authored-by: Cheng-Yeh Chung <[email protected]> * Support X-Ray-Authorization fallback header for accepting auth token via proxy (#4213) * Support X-Ray-Authorization fallback header for accepting auth token in dashboard Signed-off-by: Future-Outlier <[email protected]> * remove todo comment Signed-off-by: Future-Outlier <[email protected]> --------- Signed-off-by: Future-Outlier <[email protected]> * [RayCluster] make auth token secret name consistency (#4216) Signed-off-by: fscnick <[email protected]> * [RayCluster] Status includes head containter status message (#4196) * [RayCluster] Status includes head containter status message Signed-off-by: Spencer Peterson <[email protected]> * lint Signed-off-by: Spencer Peterson <[email protected]> * [RayCluster] Containers not ready status reflects structured reason Signed-off-by: Spencer Peterson <[email protected]> * nit Signed-off-by: Spencer Peterson <[email protected]> --------- Signed-off-by: Spencer Peterson <[email protected]> * Remove erroneous call in applyServeTargetCapacity (#4212) Signed-off-by: Ryan O'Leary <[email protected]> * [RayJob] Add token authentication support for light weight job submitter (#4215) * [RayJob] light weight job submitter auth token support Signed-off-by: Future-Outlier <[email protected]> * X-Ray-Authorization Signed-off-by: Rueian <[email protected]> --------- Signed-off-by: Future-Outlier <[email protected]> Signed-off-by: Rueian <[email protected]> Co-authored-by: Rueian <[email protected]> * feat: kubectl ray get token command (#4218) * feat: kubectl ray get token command Signed-off-by: Rueian <[email protected]> * Update kubectl-plugin/pkg/cmd/get/get_token_test.go Co-authored-by: Copilot <[email protected]> Signed-off-by: Rueian <[email protected]> * Update kubectl-plugin/pkg/cmd/get/get_token.go Co-authored-by: Copilot <[email protected]> Signed-off-by: Rueian <[email protected]> * make sure the raycluster exists before getting the secret Signed-off-by: Rueian <[email protected]> * better ux Signed-off-by: Rueian <[email protected]> * Update kubectl-plugin/pkg/cmd/get/get_token.go Co-authored-by: Han-Ju Chen (Future-Outlier) <[email protected]> Signed-off-by: Rueian <[email protected]> --------- Signed-off-by: Rueian <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Han-Ju Chen (Future-Outlier) <[email protected]> --------- Signed-off-by: 400Ping <[email protected]> Signed-off-by: Ping <[email protected]> Signed-off-by: Future-Outlier <[email protected]> Signed-off-by: Ryan O'Leary <[email protected]> Signed-off-by: Andrew Sy Kim <[email protected]> Signed-off-by: Kai-Hsun Chen <[email protected]> Signed-off-by: Neo Chien <[email protected]> Signed-off-by: justinyeh1995 <[email protected]> Signed-off-by: win5923 <[email protected]> Signed-off-by: alimaazamat <[email protected]> Signed-off-by: Spencer Peterson <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Rueian <[email protected]> Signed-off-by: JustinYeh <[email protected]> Signed-off-by: fscnick <[email protected]> Co-authored-by: Ping <[email protected]> Co-authored-by: Han-Ju Chen (Future-Outlier) <[email protected]> Co-authored-by: Ryan O'Leary <[email protected]> Co-authored-by: Kai-Hsun Chen <[email protected]> Co-authored-by: Kavish <[email protected]> Co-authored-by: Neo Chien <[email protected]> Co-authored-by: cchung100m <[email protected]> Co-authored-by: JustinYeh <[email protected]> Co-authored-by: Jun-Hao Wan <[email protected]> Co-authored-by: Divyam Raj <[email protected]> Co-authored-by: Nary Yeh <[email protected]> Co-authored-by: Alima Azamat <[email protected]> Co-authored-by: Spencer Peterson <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rueian <[email protected]> Co-authored-by: Cheng-Yeh Chung <[email protected]> Co-authored-by: fscnick <[email protected]> Co-authored-by: Copilot <[email protected]>
302 lines
10 KiB
Go
302 lines
10 KiB
Go
package dashboardclient
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/jarcoal/httpmock"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
|
|
utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types"
|
|
)
|
|
|
|
const (
|
|
runtimeEnvStr = `working_dir: "./"
|
|
pip:
|
|
- requests==2.26.0
|
|
- pendulum==2.1.2
|
|
conda:
|
|
dependencies:
|
|
- pytorch
|
|
- torchvision
|
|
- pip
|
|
- pip:
|
|
- pendulum
|
|
eager_install: false`
|
|
)
|
|
|
|
var _ = Describe("RayFrameworkGenerator", func() {
|
|
var (
|
|
rayJob *rayv1.RayJob
|
|
expectJobId string
|
|
errorJobId string
|
|
rayDashboardClient *RayDashboardClient
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
expectJobId = "raysubmit_test001"
|
|
rayJob = &rayv1.RayJob{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "rayjob-sample",
|
|
Namespace: "default",
|
|
},
|
|
Spec: rayv1.RayJobSpec{
|
|
Entrypoint: "python samply.py",
|
|
Metadata: map[string]string{
|
|
"owner": "test1",
|
|
},
|
|
RuntimeEnvYAML: runtimeEnvStr,
|
|
},
|
|
}
|
|
|
|
rayDashboardClient = &RayDashboardClient{}
|
|
rayDashboardClient.dashboardURL = "http://127.0.0.1:8090"
|
|
rayDashboardClient.client = &http.Client{}
|
|
})
|
|
|
|
It("Test ConvertRayJobToReq", func() {
|
|
rayJobRequest, err := ConvertRayJobToReq(rayJob)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(rayJobRequest.RuntimeEnv).To(HaveLen(4))
|
|
Expect(rayJobRequest.RuntimeEnv["working_dir"]).To(Equal("./"))
|
|
})
|
|
|
|
It("Test ConvertRayJobToReq with EntrypointResources", func() {
|
|
rayJobRequest, err := ConvertRayJobToReq(&rayv1.RayJob{
|
|
Spec: rayv1.RayJobSpec{
|
|
EntrypointResources: `{"r1": 0.1, "r2": 0.2}`,
|
|
EntrypointNumCpus: 1.1,
|
|
EntrypointNumGpus: 2.2,
|
|
},
|
|
})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(rayJobRequest.NumCpus).To(Equal(float32(1.1)))
|
|
Expect(rayJobRequest.NumGpus).To(Equal(float32(2.2)))
|
|
Expect(rayJobRequest.Resources).To(Equal(map[string]float32{"r1": 0.1, "r2": 0.2}))
|
|
})
|
|
|
|
It("Test ConvertRayJobToReq with invalid EntrypointResources", func() {
|
|
_, err := ConvertRayJobToReq(&rayv1.RayJob{
|
|
Spec: rayv1.RayJobSpec{
|
|
EntrypointResources: `{"r1": "string"}`,
|
|
},
|
|
})
|
|
Expect(err).Should(MatchError(ContainSubstring("json: cannot unmarshal")))
|
|
})
|
|
|
|
It("Test submitting/getting rayJob", func() {
|
|
httpmock.Activate()
|
|
defer httpmock.DeactivateAndReset()
|
|
httpmock.RegisterResponder(http.MethodPost, rayDashboardClient.dashboardURL+JobPath,
|
|
func(_ *http.Request) (*http.Response, error) {
|
|
body := &utiltypes.RayJobResponse{
|
|
JobId: expectJobId,
|
|
}
|
|
bodyBytes, _ := json.Marshal(body)
|
|
return httpmock.NewBytesResponse(200, bodyBytes), nil
|
|
})
|
|
httpmock.RegisterResponder(http.MethodGet, rayDashboardClient.dashboardURL+JobPath+expectJobId,
|
|
func(_ *http.Request) (*http.Response, error) {
|
|
body := &utiltypes.RayJobInfo{
|
|
JobStatus: rayv1.JobStatusRunning,
|
|
Entrypoint: rayJob.Spec.Entrypoint,
|
|
Metadata: rayJob.Spec.Metadata,
|
|
}
|
|
bodyBytes, _ := json.Marshal(body)
|
|
return httpmock.NewBytesResponse(200, bodyBytes), nil
|
|
})
|
|
httpmock.RegisterResponder(http.MethodGet, rayDashboardClient.dashboardURL+JobPath+errorJobId,
|
|
func(_ *http.Request) (*http.Response, error) {
|
|
// return a string in the body
|
|
return httpmock.NewStringResponse(200, "Ray misbehaved and sent string, not JSON"), nil
|
|
})
|
|
|
|
jobId, err := rayDashboardClient.SubmitJob(context.TODO(), rayJob)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(jobId).To(Equal(expectJobId))
|
|
|
|
rayJobInfo, err := rayDashboardClient.GetJobInfo(context.TODO(), jobId)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(rayJobInfo.Entrypoint).To(Equal(rayJob.Spec.Entrypoint))
|
|
Expect(rayJobInfo.JobStatus).To(Equal(rayv1.JobStatusRunning))
|
|
|
|
_, err = rayDashboardClient.GetJobInfo(context.TODO(), errorJobId)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("GetJobInfo fail"))
|
|
Expect(err.Error()).To(ContainSubstring("Ray misbehaved"))
|
|
})
|
|
|
|
It("Test stop job", func() {
|
|
httpmock.Activate()
|
|
defer httpmock.DeactivateAndReset()
|
|
httpmock.RegisterResponder(http.MethodPost, rayDashboardClient.dashboardURL+JobPath+"stop-job-1/stop",
|
|
func(_ *http.Request) (*http.Response, error) {
|
|
body := &utiltypes.RayJobStopResponse{
|
|
Stopped: true,
|
|
}
|
|
bodyBytes, _ := json.Marshal(body)
|
|
return httpmock.NewBytesResponse(200, bodyBytes), nil
|
|
})
|
|
|
|
err := rayDashboardClient.StopJob(context.TODO(), "stop-job-1")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("Test stop succeeded job", func() {
|
|
// StopJob only returns an error when JobStatus is not in terminated states (STOPPED / SUCCEEDED / FAILED)
|
|
httpmock.Activate()
|
|
defer httpmock.DeactivateAndReset()
|
|
httpmock.RegisterResponder(http.MethodPost, rayDashboardClient.dashboardURL+JobPath+"stop-job-1/stop",
|
|
func(_ *http.Request) (*http.Response, error) {
|
|
body := &utiltypes.RayJobStopResponse{
|
|
Stopped: false,
|
|
}
|
|
bodyBytes, _ := json.Marshal(body)
|
|
return httpmock.NewBytesResponse(200, bodyBytes), nil
|
|
})
|
|
httpmock.RegisterResponder(http.MethodGet, rayDashboardClient.dashboardURL+JobPath+"stop-job-1",
|
|
func(_ *http.Request) (*http.Response, error) {
|
|
body := &utiltypes.RayJobInfo{
|
|
JobStatus: rayv1.JobStatusSucceeded,
|
|
Entrypoint: rayJob.Spec.Entrypoint,
|
|
Metadata: rayJob.Spec.Metadata,
|
|
}
|
|
bodyBytes, _ := json.Marshal(body)
|
|
return httpmock.NewBytesResponse(200, bodyBytes), nil
|
|
})
|
|
|
|
err := rayDashboardClient.StopJob(context.TODO(), "stop-job-1")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("Test GetServeDetails URL construction with query parameters", func() {
|
|
httpmock.Activate()
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
// Mock the response
|
|
expectedResponse := &utiltypes.ServeDetails{
|
|
Applications: map[string]utiltypes.ServeApplicationDetails{
|
|
"app1": {
|
|
ServeApplicationStatus: utiltypes.ServeApplicationStatus{
|
|
Name: "app1",
|
|
Status: "RUNNING",
|
|
},
|
|
Deployments: map[string]utiltypes.ServeDeploymentDetails{},
|
|
},
|
|
},
|
|
DeployMode: "MULTI_APP",
|
|
}
|
|
responseBytes, _ := json.Marshal(expectedResponse)
|
|
|
|
// Register responder that checks the URL includes the query parameter
|
|
httpmock.RegisterResponder(http.MethodGet, rayDashboardClient.dashboardURL+ServeDetailsPath,
|
|
func(req *http.Request) (*http.Response, error) {
|
|
// Verify the query parameter is present
|
|
Expect(req.URL.Query().Get("api_type")).To(Equal("declarative"))
|
|
return httpmock.NewBytesResponse(200, responseBytes), nil
|
|
})
|
|
|
|
details, err := rayDashboardClient.GetServeDetails(context.TODO())
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(details.Applications).To(HaveKey("app1"))
|
|
Expect(details.DeployMode).To(Equal("MULTI_APP"))
|
|
})
|
|
|
|
It("Test GetServeDetails with invalid dashboard URL", func() {
|
|
invalidClient := &RayDashboardClient{
|
|
dashboardURL: "://invalid-url",
|
|
client: &http.Client{},
|
|
}
|
|
|
|
_, err := invalidClient.GetServeDetails(context.TODO())
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("failed to parse dashboard URL"))
|
|
})
|
|
|
|
It("Test GetServeDetails with HTTP 400 Bad Request", func() {
|
|
httpmock.Activate()
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
// Test 400 Bad Request (might happen with older Ray versions)
|
|
httpmock.RegisterResponder(http.MethodGet, rayDashboardClient.dashboardURL+ServeDetailsPath,
|
|
func(_ *http.Request) (*http.Response, error) {
|
|
return httpmock.NewStringResponse(400, "Bad Request: unknown parameter api_type"), nil
|
|
})
|
|
|
|
_, err := rayDashboardClient.GetServeDetails(context.TODO())
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("GetServeDetails fail: 400"))
|
|
Expect(err.Error()).To(ContainSubstring("Bad Request: unknown parameter api_type"))
|
|
})
|
|
|
|
It("Test GetServeDetails with HTTP 500 Internal Server Error", func() {
|
|
httpmock.Activate()
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
httpmock.RegisterResponder(http.MethodGet, rayDashboardClient.dashboardURL+ServeDetailsPath,
|
|
func(_ *http.Request) (*http.Response, error) {
|
|
return httpmock.NewStringResponse(500, "Internal Server Error"), nil
|
|
})
|
|
|
|
_, err := rayDashboardClient.GetServeDetails(context.TODO())
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("GetServeDetails fail: 500"))
|
|
})
|
|
|
|
It("Test GetServeDetails with invalid JSON response", func() {
|
|
httpmock.Activate()
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
httpmock.RegisterResponder(http.MethodGet, rayDashboardClient.dashboardURL+ServeDetailsPath,
|
|
func(_ *http.Request) (*http.Response, error) {
|
|
return httpmock.NewStringResponse(200, "invalid json response"), nil
|
|
})
|
|
|
|
_, err := rayDashboardClient.GetServeDetails(context.TODO())
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("GetServeDetails failed. Failed to unmarshal bytes"))
|
|
Expect(err.Error()).To(ContainSubstring("invalid json response"))
|
|
})
|
|
|
|
It("Test GetServeDetails with empty response", func() {
|
|
httpmock.Activate()
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
// Test with empty but valid JSON
|
|
emptyResponse := &utiltypes.ServeDetails{
|
|
Applications: map[string]utiltypes.ServeApplicationDetails{},
|
|
DeployMode: "",
|
|
}
|
|
responseBytes, _ := json.Marshal(emptyResponse)
|
|
|
|
httpmock.RegisterResponder(http.MethodGet, rayDashboardClient.dashboardURL+ServeDetailsPath,
|
|
func(req *http.Request) (*http.Response, error) {
|
|
// Verify the query parameter is present
|
|
Expect(req.URL.Query().Get("api_type")).To(Equal("declarative"))
|
|
return httpmock.NewBytesResponse(200, responseBytes), nil
|
|
})
|
|
|
|
details, err := rayDashboardClient.GetServeDetails(context.TODO())
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(details.Applications).To(BeEmpty())
|
|
Expect(details.DeployMode).To(Equal(""))
|
|
})
|
|
|
|
It("Test GetServeDetails with network error", func() {
|
|
httpmock.Activate()
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
httpmock.RegisterResponder(http.MethodGet, rayDashboardClient.dashboardURL+ServeDetailsPath,
|
|
httpmock.NewErrorResponder(context.DeadlineExceeded))
|
|
|
|
_, err := rayDashboardClient.GetServeDetails(context.TODO())
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(errors.Is(err, context.DeadlineExceeded)).To(BeTrue())
|
|
})
|
|
})
|