Skip to content

Commit

Permalink
[CI] apply resource logger to ray cluster test (#3075)
Browse files Browse the repository at this point in the history
  • Loading branch information
simotw authored Feb 20, 2025
1 parent 349ab01 commit a9aa9a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions ray-operator/test/sampleyaml/raycluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestRayCluster(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
test := With(t)
g := NewWithT(t)
g.ConfigureWithT(WithRayClusterResourceLogger(test))

yamlFilePath := path.Join(GetSampleYAMLDir(test), tt.name)
namespace := test.NewTestNamespace()
Expand Down
24 changes: 24 additions & 0 deletions ray-operator/test/support/resource_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
JOBS_RESOURCE
SERVICES_RESOURCE
RAYJOBS_RESOURCE
RAYCLUSTERS_RESOURCE
)

type ResourceLoggerFunc = func(sb *strings.Builder)
Expand All @@ -23,6 +24,11 @@ func WithRayJobResourceLogger(t Test) types.GomegaTestingT {
return &RayResourceLogger{t: t, resources: resources}
}

func WithRayClusterResourceLogger(t Test) types.GomegaTestingT {
resources := []int{SERVICES_RESOURCE, RAYCLUSTERS_RESOURCE}
return &RayResourceLogger{t: t, resources: resources}
}

type RayResourceLogger struct {
t Test
resources []int
Expand Down Expand Up @@ -108,6 +114,22 @@ func (l *RayResourceLogger) FprintRayJobs(sb *strings.Builder) {
}
}

func (l *RayResourceLogger) FprintRayClusters(sb *strings.Builder) {
if rayClusters, err := l.t.Client().Ray().RayV1().RayClusters("").List(l.t.Ctx(), metav1.ListOptions{}); err == nil {
fmt.Fprintf(sb, "\n=== RayClusters across all namespaces ===\n")
for _, rayCluster := range rayClusters.Items {
rayClusterJSON, err := json.MarshalIndent(rayCluster, "", " ")
if err != nil {
fmt.Fprintf(sb, "Error marshaling rayCluster %s/%s: %v\n", rayCluster.Namespace, rayCluster.Name, err)
continue
}
fmt.Fprintf(sb, "---\n# rayCluster: %s/%s\n%s\n", rayCluster.Namespace, rayCluster.Name, string(rayClusterJSON))
}
} else {
fmt.Fprintf(sb, "Failed to get rayCluster: %v\n", err)
}
}

func (l *RayResourceLogger) MakeFprintUnsupportedResource(resource int) func(sb *strings.Builder) {
return func(sb *strings.Builder) {
fmt.Fprintf(sb, "Error: Unsupported resource: %d for RayResourceLogger\n", resource)
Expand All @@ -126,6 +148,8 @@ func (l *RayResourceLogger) GetLoggers() []ResourceLoggerFunc {
loggers = append(loggers, l.FprintServices)
case RAYJOBS_RESOURCE:
loggers = append(loggers, l.FprintRayJobs)
case RAYCLUSTERS_RESOURCE:
loggers = append(loggers, l.FprintRayClusters)
default:
loggers = append(loggers, l.MakeFprintUnsupportedResource(resource))
}
Expand Down

0 comments on commit a9aa9a3

Please sign in to comment.