Skip to content

Enhance unit test coverage for vGPUmonitor metrics collection and MIG info mapping #2818

Description

@Gurkaran18

What would you like to be added:
Comprehensive unit tests for the cmd/vGPUmonitor package to cover critical paths that are currently untested (0-25% coverage). Specifically:

  1. collectPodAndContainerMigInfo: Table-driven tests to verify the decoding and mapping of MIG allocations (hami.io/vgpu-mig-allocations annotations) to container indices.
  2. NVML Wrapper Functions (collectGPUInfo, getDeviceCount, collectGPUDeviceMetrics): Using nvmlmock (which is already imported) to simulate host GPU fetching and ensure NVML failures are handled gracefully.
  3. Edge cases in collectPodAndContainerInfo (e.g. handling of malformed/empty UUIDs and lister failures).

Why is this needed:
The cmd/vGPUmonitor is a core component for observability that tracks physical GPU usage and container/MIG instance mappings. While recent PRs improved the overall baseline test coverage to ~43%, the complex MIG mapping and hardware-fetching layers remain heavily untested.

Adding tests for these areas ensures that edge cases (like invalid annotations or NVML runtime errors) are handled smoothly without crashing the scrape or silently corrupting metrics in production environments.

Anything else we need to know?:
/kind test

AI assistance disclosure: I used an AI assistant to help identify these specific untested paths and format this issue, but I have verified the coverage gaps manually.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions