Skip to content

feat(device-plugin): add the OpenTelemetry allocate span - #3544

Merged
moezdil merged 3 commits into
Project-HAMi:masterfrom
loiht2:feat/tracing-device-plugin
Nov 26, 2026
Merged

moezdil merged 3 commits into
Project-HAMi:masterfrom
loiht2:feat/tracing-device-plugin

Conversation

@loiht2

@loiht2 loiht2 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

/kind feature

What this PR does / why we need it:

  • an allocate span in the NVIDIA device plugin, a child of the Filter span whose context is on the pod (hami.io/traceparent), so one trace covers Filter, Bind and Allocate
  • attributes: the pod, node, device type and the device UUIDs the container gets. A failed Allocate sets status Error with the error returned to kubelet
  • the device plugin sets up tracing from the same OTEL_* variables as the scheduler, with service name hami-device-plugin, and flushes on exit
  • the log line that ends Allocate carries traceID

Part of #3473

Special notes for your reviewer:

  • Allocate now has named results, so one deferred check marks every failure branch with the returned error
  • no span when no pending pod is found, since there is no pod to attach it to
  • "Allocate Response" moves from Infoln to InfoS to carry the traceID key

Does this PR introduce a user-facing change?:

Yes, when OTEL_EXPORTER_OTLP_ENDPOINT is set on the device plugin: an allocate span per container and traceID in the "Allocate Response" log line. That line is now a structured log line, with tracing on or off.

AI Assistance Disclosure:

I used Claude Code to help me investigate the code, make the changes (I reviewed and approved each one), and refine the content of this PR.

Summary by CodeRabbit

  • Improvements
    • GPU allocation activity now includes tracing details such as pod and device information, making allocation behavior easier to monitor.
    • Allocation failures are recorded in traces with their error status, while tracing setup or shutdown issues are logged without preventing the device plugin from continuing or exiting.

Signed-off-by: Thanh-Loi Hoang <loi.hoangthanh.24@gmail.com>
Signed-off-by: Thanh-Loi Hoang <loi.hoangthanh.24@gmail.com>
Signed-off-by: Thanh-Loi Hoang <loi.hoangthanh.24@gmail.com>
@hami-robot hami-robot Bot added the kind/feature new function label Nov 26, 2026
@hami-robot
hami-robot Bot requested review from FouoF and wawa0210 November 26, 2026 16:26
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The NVIDIA device plugin now initializes tracing at startup and records spans for allocation requests. The spans include pod and device attributes, allocation errors, and device UUIDs. Tests cover parent context, allocation failures, and MIG device identifiers.

Changes: GPU allocation tracing

Layer / File(s) Summary
Tracing startup
cmd/device-plugin/nvidia/main.go
The device plugin initializes tracing during startup. It uses a no-op shutdown if setup fails and attempts to flush tracing with a five-second timeout on exit.
Allocation spans and validation
pkg/device-plugin/nvidiadevice/nvinternal/plugin/tracing.go, pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go, pkg/device-plugin/nvidiadevice/nvinternal/plugin/allocate_tracing_test.go
Allocate creates a span using the pending pod’s annotation context, records allocation errors and device UUIDs, and includes the trace ID in the response log. Tests cover parent context, failure cases, and MIG replica UUIDs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant DevicePluginStart
  participant Tracing
  participant Allocate
  participant startAllocateSpan
  participant AllocateSpan
  DevicePluginStart->>Tracing: Initialize with process context
  Allocate->>startAllocateSpan: Start span for pending Pod
  startAllocateSpan-->>Allocate: Return context and span
  Allocate->>AllocateSpan: Record result and device UUIDs, then end span
Loading

Possibly related issues

Suggested labels: enhancement

Suggested reviewers: archlitchi, fouof

Merge Risk: Minimal · up to 5097e

This change adds optional tracing to GPU allocation, and the logging change is low risk. No concrete merge-blocking problem was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(device-plugin): add the OpenTelemetry allocate span" matches the main change. The PR adds an allocate span to the NVIDIA device plugin's Allocate path, which the summary and objectives…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(device-plugin): add the OpenTelemetry allocate span" matches the main change. The PR adds an allocate span to the NVIDIA device plugin's Allocate path, which the summary and objectives both describe. The title is concise, specific, and follows a conventional-commit style. It does not cover the log change, the tracing startup, or the flush on exit, which is acceptable because the title need not list every detail.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit traces paths through the night
Each pod leaves a span in the light
Device UUIDs join the trail
Errors too are in the tale
MIG names lose the replica’s tail
At shutdown, flushes set sail

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 370a5aeb-0d72-42a9-a557-18567fb9cb55
Commits

Reviewing files that changed from the base of the PR and between 3d600ea and 5097e2e.

Files selected for processing: 4

  • cmd/device-plugin/nvidia/main.go
  • pkg/device-plugin/nvidiadevice/nvinternal/plugin/allocate_tracing_test.go
  • pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go
  • pkg/device-plugin/nvidiadevice/nvinternal/plugin/tracing.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.85714% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/device-plugin/nvidia/main.go 0.00% 9 Missing ⚠️
Flag Coverage Δ
unittests 81.54% <67.85%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ce-plugin/nvidiadevice/nvinternal/plugin/server.go 82.23% <100.00%> (+0.16%) ⬆️
...e-plugin/nvidiadevice/nvinternal/plugin/tracing.go 100.00% <100.00%> (ø)
cmd/device-plugin/nvidia/main.go 27.77% <0.00%> (-0.57%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@moezdil

moezdil commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@hami-robot hami-robot Bot added the lgtm label Nov 26, 2026
@hami-robot

hami-robot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: loiht2, moezdil

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

1 similar comment
@hami-robot

hami-robot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: loiht2, moezdil

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 label Nov 26, 2026
@moezdil
moezdil merged commit 1f4a591 into Project-HAMi:master Nov 26, 2026
18 of 20 checks passed

This branch was previously deployed

1 inactive deployment
nvidia — 5097e2eb Deployed Nov 26, 2026 by loiht2 via e2e_test / e2e-test (nvidia, tesla-p4) #7935
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants