8000 feat(rod): extract requested resources from work units using domain resources adapter by janzak-dev · Pull Request #407 · google/xmc · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b698a13
refactor(rod): populate requested_resources, shorten functions, add c…
janzak-dev Aug 10, 2026
33cf9a5
refactor(rod): extractRequestedResourcesFromSpec directly operates on…
janzak-dev Aug 10, 2026
09980bc
refactor(rod): simplify extractRequestedResources to read directly fr…
janzak-dev Aug 10, 2026
0ac7f58
refactor(rod): use type switch on ResourceSet.resources in extractReq…
janzak-dev Aug 10, 2026
61710a6
refactor(rod): use GPU and TPU as default resource type strings
janzak-dev Aug 10, 2026
99c1143
refactor(rod): aggregate resources across all jobs in jobset without …
janzak-dev Aug 10, 2026
27c5d9c
refactor(rod): extract resourceAccumulator struct with dedicated help…
janzak-dev Aug 10, 2026
e3bf04c
refactor(rod): refactor jobs_test.go to use proto.Modify and baseline…
janzak-dev Aug 10, 2026
0a320c1
feat(rod): extract resourceAccumulator to separate file and test suite
janzak-dev Aug 10, 2026
09d601e
refactor(rod): replace custom resourceAccumulator with domain workuni…
janzak-dev Aug 10, 2026
ef4891c
fix(rod): parse TPU topology dimensions to calculate total TPU chips …
janzak-dev Aug 10, 2026
77d70ef
test(rod): add unit tests for TPU resource extraction and topology ch…
janzak-dev Aug 10, 2026
43fe65d
refactor(rod): decompose extractRequestedResources under 15 lines and…
janzak-dev Aug 10, 2026
78a5d48
feat(rod): render Resources column in Angular UI for ROD jobs table
janzak-dev Aug 10, 2026
042556a
refactor(ui): simplify resource formatting logic in queue jobs table
janzak-dev Aug 10, 2026
bf42b43
refactor(ui): restrict QueueJobResourcesPipe input strictly to Resour…
janzak-dev Aug 10, 2026
5c0f73d
refactor(rod): sync jobs.go and jobs_test.go with domain workunit.Get…
janzak-dev Aug 10, 2026
f223180
refactor(rod): format accelerators as ${count} x ${type}, normalize T…
janzak-dev Aug 10, 2026
e8f4a86
refactor(rod): extract resource type string literals into constants
janzak-dev Aug 10, 2026
231cb45
refactor(rod): address PR 407 review comments
janzak-dev Aug 10, 2026
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
3 changes: 3 additions & 0 deletions cmd/rod_data_provider/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ compat_go_library(
"main.go",
"queue_converters.go",
"queue_matcher.go",
"resource_accumulator.go",
"server.go",
],
importpath = "xmanager_cloud/cmd/rod_data_provider/main",
Expand All @@ -38,6 +39,7 @@ compat_go_library(
"//cmd/rod_data_provider/reconciler",
"//internal/compat/google",
"//internal/configutil",
"//internal/domain/workunit",
"//internal/logging",
"//internal/storage/spanner/workunit",
"//internal/validator",
Expand Down Expand Up @@ -79,6 +81,7 @@ compat_go_test(
"config_test.go",
"jobs_test.go",
"queue_matcher_test.go",
"resource_accumulator_test.go",
"server_test.go",
],
embed = [":rod_data_provider_lib"],
Expand Down
11 changes: 5 additions & 6 deletions cmd/rod_data_provider/jobs.go
8000
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (s *server) GetRunningAndPendingJobs(ctx context.Context, req *spb.GetRunni
workUnits, nextPageToken := extractWorkUnitsResult(result)
jobs := mapWorkUnitsToDashboardJobs(ctx, workUnits, time.Now())

// TODO: Set TotalQueueSize to the total count across all pages once pagination is implemented.
return &spb.GetRunningAndPendingJobsResponse{
Jobs: jobs,
NextPageToken: nextPageToken,
Expand All @@ -69,7 +68,7 @@ func validateJobsRequest(ctx context.Context, req *spb.GetRunningAndPendingJobsR
return nil
}

func extractWorkUnitsResult(result *workunit.ActiveWorkUnitsResult) ([]*essmsgpb.WorkUnit, string) {
func extractWorkUnitsResult(result *workunit.ActiveWorkUnitsResult) (workUnits []*essmsgpb.WorkUnit, nextPageToken string) {
if result == nil {
return nil, ""
}
Expand Down Expand Up @@ -103,10 +102,10 @@ func mapWorkUnitToDashboardJob(ctx context.Context, wu *essmsgpb.WorkUnit, now t
Priority: int64(wu.GetPriority()),
Status: extractWorkUnitState(wu),
TimeInQueueSeconds: calculateQueueDuration(wu, now),
// TODO: Populate RequestedResources field using extractRequestedResources once resource accumulator PR is merged.
PositionInQueue: extractQueuePosition(wu),
CreateTime: wu.GetCreateTime(),
Tags: wu.GetTags(),
RequestedResources: extractRequestedResources(wu),
Comment thread
VLukiantsev marked this conversation as resolved.
Resolved
PositionInQueue: extractQueuePosition(wu),
CreateTime: wu.GetCreateTime(),
Tags: wu.GetTags(),
}
}

Expand Down
76 changes: 76 additions & 0 deletions cmd/rod_data_provider/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ var (
},
},
},
Executable: &essmsgpb.Executable{
Type: &essmsgpb.Executable_Jobset{
Jobset: &essmsgpb.JobSetExecutable{
Jobs: []*essmsgpb.KubernetesJob{
{
Spec: &essmsgpb.ExecutableSpec{
Resources: &essmsgpb.ResourceSet{
Resources: &essmsgpb.ResourceSet_CpuResources{
CpuResources: &essmsgpb.CpuResources{
CpuMillicores: 4000,
MemoryBytes: 8192,
},
},
},
},
},
},
},
},
},
}
)

Expand Down Expand Up @@ -174,6 +194,10 @@ func TestGetRunningAndPendingJobs(t *testing.T) {
Priority: 100,
Status: essmsgpb.WorkUnitStatus_SCHEDULING,
PositionInQueue: 1,
RequestedResources: []*spb.Resource{
{ResourceType: "cpu", Count: 4.0},
{ResourceType: "memory", Count: 8192.0},
},
}
if diff := cmp.Diff(wantJob, gotJob, protocmp.Transform(), protocmp.IgnoreFields(&spb.DashboardJob{}, "time_in_queue_seconds", "create_time")); diff != "" {
t.Errorf("DashboardJob mismatch (-want +got):\n%s", diff)
Expand All @@ -195,3 +219,55 @@ func TestGetRunningAndPendingJobs_ContextCancelled(t *testing.T) {
t.Errorf("GetRunningAndPendingJobs status code = %v, want %v", status.Code(err), codes.Canceled)
}
}

func TestMapWorkUnitToDashboardJob_RequestedResources(t *testing.T) {
Comment thread
VLukiantsev marked this conversation as resolved.
Resolved
Comment thread
VLukiantsev marked this conversation as resolved.
Resolved
now := time.Now()
wu := proto.Modify(baseWorkUnit, func(w *essmsgpb.WorkUnit) {
w.Executable = &essmsgpb.Executable{
Type: &essmsgpb.Executable_Jobset{
Jobset: &essmsgpb.JobSetExecutable{
Jobs: []*essmsgpb.KubernetesJob{
{
Replicas: 2,
Spec: &essmsgpb.ExecutableSpec{
Resources: &essmsgpb.ResourceSet{
Resources: &essmsgpb.ResourceSet_GpuResources{
GpuResources: &essmsgpb.GpuResources{
Type: "nvidia-tesla-h100",
Count: 4,
},
},
},
},
},
{
Replicas: 1,
Spec: &essmsgpb.ExecutableSpec{
Resources: &essmsgpb.ResourceSet{
Resources: &essmsgpb.ResourceSet_GpuResources{
GpuResources: &essmsgpb.GpuResources{
Type: "nvidia-tesla-h100",
Count: 2,
},
},
},
},
},
},
},
},
}
})

job := mapWorkUnitToDashboardJob(context.Background(), wu, now)
if job == nil {
t.Fatalf("mapWorkUnitToDashboardJob returned nil")
}
if len(job.GetRequestedResources()) != 1 {
t.Fatalf("RequestedResources len = %d, want 1", len(job.GetRequestedResources()))
}
res := job.GetRequestedResources()[0]
if res.GetResourceType() != "nvidia-tesla-h100" || res.GetCount() != 10.0 {
t.Errorf("RequestedResource = %v %v, want nvidia-tesla-h100 10.0", res.GetResourceType(), res.GetCount())
}
}
132 changes: 132 additions & 0 deletions cmd/rod_data_provider/resource_accumulator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"strconv"
"strings"

spb "xmanager_cloud/api/protos/rod"
essmsgpb "xmanager_cloud/experiment_state_server/proto/messages_go_proto"
"xmanager_cloud/internal/domain/workunit"
)

const (
resourceTypeCPU = "cpu"
resourceTypeMemory = "memory"
resourceTypeGPU = "GPU"
resourceTypeTPU = "TPU"
)

type resourceAccumulator struct {
totals map[string]float64
order []string
}

func (a *resourceAccumulator) add(resType string, count float64) {
if count <= 0 {
return
}
if _, exists := a.totals[resType]; !exists {
a.order = append(a.order, resType)
}
a.totals[resType] += count
}

// extractRequestedResources converts domain ResourceSets from workunit.GetWorkUnitResources
// into presentation DTOs ([]*spb.Resource) required by the ROD API, aggregating identical resource types.
func extractRequestedResources(wu *essmsgpb.WorkUnit) []*spb.Resource {
resourceSets := workunit.GetWorkUnitResources(wu)
if len(resourceSets) == 0 {
return nil
}
totals, order := accumulateResourceTotals(resourceSets)
return buildResourceDTOs(totals, order)
}

func accumulateResourceTotals(resourceSets []*essmsgpb.ResourceSet) (totals map[string]float64, order []string) {
acc := &resourceAccumulator{totals: make(map[string]float64, len(resourceSets))}
for _, rs := range resourceSets {
Comment thread
VLukiantsev marked this conversation as resolved.
Resolved
Comment thread
VLukiantsev marked this conversation as resolved.
Resolved
accumulateResource(rs, acc)
}
return acc.totals, acc.order
}

func buildResourceDTOs(totals map[string]float64, order []string) []*spb.Resource {
resources := make([]*spb.Resource, 0, len(order))
for _, resType := range order {
resources = append(resources, &spb.Resource{
ResourceType: resType,
Count: totals[resType],
})
}
return resources
}

func accumulateResource(rs *essmsgpb.ResourceSet, acc *resourceAccumulator) {
if rs == nil || acc == nil {
return
}
if cpu := rs.GetCpuResources(); cpu != nil {
accumulateCpuResource(cpu, acc)
} else if gpu := rs.GetGpuResources(); gpu != nil {
accumulateGpuResource(gpu, acc)
} else if tpu := rs.GetTpuResources(); tpu != nil {
accumulateTpuResource(tpu, acc)
}
}

func accumulateCpuResource(cpu *essmsgpb.CpuResources, acc *resourceAccumulator) {
if millicores := cpu.GetCpuMillicores(); millicores > 0 {
acc.add(resourceTypeCPU, float64(millicores)/1000.0)
}
if memoryBytes := cpu.GetMemoryBytes(); memoryBytes > 0 {
acc.add(resourceTypeMemory, float64(memoryBytes))
}
}

func accumulateGpuResource(gpu *essmsgpb.GpuResources, acc *resourceAccumulator) {
resType := gpu.GetType()
if resType == "" {
resType = resourceTypeGPU
}
acc.add(resType, float64(gpu.GetCount()))
}

func accumulateTpuResource(tpu *essmsgpb.TpuResources, acc *resourceAccumulator) {
resType := tpu.GetType()
if resType == "" {
resType = resourceTypeTPU
}
chips := parseTotalChips(tpu.GetTopology())
acc.add(resType, float64(chips))
}

func parseTotalChips(topology string) int64 {
if topology == "" {
return 1
}
cleaned := strings.TrimSpace(strings.ToLower(topology))
dims := strings.Split(cleaned, "x")
totalChips := int64(1)
for _, d := range dims {
v, err := strconv.ParseInt(d, 10, 64)
if err != nil || v <= 0 {
return 1
}
totalChips *= v
}
return totalChips
}
Loading
Loading
0