Skip to content

fix: record init and sidecar GPU allocations as HAMi counts them - #307

Draft
Nimbus318 wants to merge 1 commit into
Project-HAMi:mainfrom
Nimbus318:fix/init-sidecar-allocations
Draft

Nimbus318 wants to merge 1 commit into
Project-HAMi:mainfrom
Nimbus318:fix/init-sidecar-allocations

Conversation

@Nimbus318

@Nimbus318 Nimbus318 commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Draft until a HAMi release includes native sidecar accounting (Project-HAMi/HAMi#2723) and init container monitoring (Project-HAMi/HAMi#2716); v2.10.0 has neither.

HAMi allocates GPUs to init containers and native sidecars. WebUI only recorded app containers, so such a container appeared in the workload list as a bare request, its scheduling diagnosis said no allocation record was found, and device totals left it out.

Allocation records. Init and sidecar containers with a HAMi record are now allocation rows, read from HAMi's annotation slots (init containers first). Each row shows the container's own memory and cores, its init-container status, and a kind label in the list and on the detail page. The diagnosis links to them like any other allocated container.

Totals. Device, node and cluster totals follow HAMi's Pod accounting (CollapseInitContainerUsage and SteadyStateDeviceUsage in pkg/device/initContainer.go) instead of adding up containers. Per Pod and device, memory, cores and slots are each:

Phase Counted
Init containers still running larger of the init peak (each ordinary init container plus the sidecars declared before it) and sidecars plus app containers
Every ordinary init container succeeded sidecars plus app containers; the init containers leave the list

So the rows of one Pod need not add up to its device total. The API totals and the new exporter gauges hami_vgpu_allocated, hami_vcore_allocated and hami_vmemory_allocated use the same function. The overview, node and card allocation charts read those gauges and fall back to the per-container sums for samples scraped before the upgrade. Per-container series and workload rankings are unchanged apart from now including these containers.

The workload detail also reads CPU and memory limits from kube-state-metrics' kube_pod_init_container_* series, where init and sidecar containers are reported. Their GPU usage charts need HAMi's device monitor to report them, which HAMi master does (#2716) and releases up to v2.10.0 do not.

Matching HAMi. The accounting tests include the two orderings from HAMi's Test_calcScore_SidecarInitOrdering. The same seven cases were also run through HAMi's own CollapseInitContainerUsage at 8ca23d0, with identical results. This follows HAMi master; HAMi v2.9 added up every container and v2.10.0 counts sidecars like init containers, so their scheduler figures can be higher or lower for such Pods.

make verify and make -C server verify (plus -race on the changed packages) pass.

On a single-A10 test cluster, a Pod with a GPU native sidecar (128 MiB) and a GPU app container (384 MiB) now shows the sidecar as an allocation row with its label, the diagnosis lists both allocated containers, and the device counts 9 of 10 slots and 3328 MiB where it previously omitted the sidecar. Ordinary GPU init containers are covered by the unit tests.

@hami-robot
hami-robot Bot requested a review from archlitchi September 13, 2026 10:52
@hami-robot

hami-robot Bot commented Sep 13, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Nimbus318

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hami-robot hami-robot Bot added the approved Approved by an OWNERS approver label Sep 13, 2026
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: d6592755-ebcc-47a8-b5fa-1cf0574d2197

📥 Commits

Reviewing files that changed from the base of the PR and between 5fd62d4 and f0c3608.

📒 Files selected for processing (18)
  • docs/operations/scheduling-diagnostics.md
  • packages/web/projects/vgpu/metrics/query-contract.mjs
  • packages/web/projects/vgpu/metrics/query-contract.test.mjs
  • packages/web/projects/vgpu/views/monitor/overview/metric-config.mjs
  • packages/web/projects/vgpu/views/monitor/overview/metric-config.test.mjs
  • packages/web/projects/vgpu/views/task/admin/Detail.vue
  • server/internal/biz/pod.go
  • server/internal/biz/pod_test.go
  • server/internal/data/pod.go
  • server/internal/data/pod_test.go
  • server/internal/data/scheduling_pod.go
  • server/internal/data/scheduling_test.go
  • server/internal/exporter/exporter.go
  • server/internal/exporter/exporter_test.go
  • server/internal/exporter/metrics.go
  • server/internal/service/container.go
  • server/internal/service/workload.go
  • server/internal/service/workload_test.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

HAMi allocates GPUs to init and sidecar containers, but WebUI only recorded
app containers. Such a container showed up as a bare request, and its
diagnosis reported that no allocation record was found.

Init and sidecar containers with a HAMi record are now allocation rows with
their own status. Device, node and cluster totals follow HAMi's Pod
accounting (CollapseInitContainerUsage): init containers count at their
peak and sidecars add to the app containers, until every ordinary init
container has succeeded and HAMi releases the init allocations. The
exporter publishes these totals as hami_vgpu_allocated, hami_vcore_allocated
and hami_vmemory_allocated. Allocation charts read them and fall back to the
per-container sums for older samples. The workload detail labels the
container kind and also reads kube-state-metrics' init container limits.

Signed-off-by: Nimbus318 <136771156+Nimbus318@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Approved by an OWNERS approver do-not-merge/work-in-progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant