Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 11 additions & 9 deletions cmd/vGPUmonitor/feedback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ func (s *stubInfo) DeviceMemoryOffset(int) uint64 { return 0 }
func (s *stubInfo) DeviceMemoryTotal(i int) uint64 { return slot(s.total, i) }
func (s *stubInfo) DeviceSmUtil(i int) uint64 { return slot(s.smUtil, i) }
func (s *stubInfo) SetDeviceSmLimit(uint64) {}
func (s *stubInfo) IsValidUUID(i int) bool { return i < len(s.uuids) }
func (s *stubInfo) DeviceMemoryLimit(i int) uint64 { return slot(s.limit, i) }
func (s *stubInfo) SetDeviceMemoryLimit(uint64) {}
func (s *stubInfo) LastKernelTime() int64 { return s.lastKernel }
func (s *stubInfo) GetPriority() int { return s.priority }
func (s *stubInfo) GetRecentKernel() int32 { return 1 }
func (s *stubInfo) SetRecentKernel(int32) {}
func (s *stubInfo) GetUtilizationSwitch() int32 { return 0 }
func (s *stubInfo) SetUtilizationSwitch(int32) {}
func (s *stubInfo) IsValidUUID(i int) bool {
return i >= 0 && i < len(s.uuids) && len(s.uuids[i]) > 0 && s.uuids[i][0] != 0
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
func (s *stubInfo) DeviceMemoryLimit(i int) uint64 { return slot(s.limit, i) }
func (s *stubInfo) SetDeviceMemoryLimit(uint64) {}
func (s *stubInfo) LastKernelTime() int64 { return s.lastKernel }
func (s *stubInfo) GetPriority() int { return s.priority }
func (s *stubInfo) GetRecentKernel() int32 { return 1 }
func (s *stubInfo) SetRecentKernel(int32) {}
func (s *stubInfo) GetUtilizationSwitch() int32 { return 0 }
func (s *stubInfo) SetUtilizationSwitch(int32) {}

func TestCheckFunctionsHighPriority(t *testing.T) {
sw := map[string]UtilizationPerDevice{"gpu-0": {0, 1}}
Expand Down
9 changes: 4 additions & 5 deletions cmd/vGPUmonitor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,13 @@ func (cc ClusterManagerCollector) collectContainerMetrics(ch chan<- prometheus.M

// Iterate through each device
for i := range c.Info.DeviceNum() {
uuid := c.Info.DeviceUUID(i)
if len(uuid) < 40 {
klog.Warningf("Device %d in Pod %s/%s, Container %s has invalid UUID length %d (shared memory not yet initialised); skipping until next scrape", i, pod.Namespace, pod.Name, ctr.Name, len(uuid))
if !c.Info.IsValidUUID(i) {
klog.Warningf("Device %d in Pod %s/%s, Container %s UUID not yet initialised; skipping until next scrape", i, pod.Namespace, pod.Name, ctr.Name)
continue
}
uuid = uuid[0:40] // Ensure UUID is truncated to 40 characters
uuid := c.Info.DeviceUUID(i)[0:40]
if !utf8.ValidString(uuid) {
klog.Warningf("Device %d in Pod %s/%s, Container %s has invalid UTF-8 UUID (shared memory not yet initialised); skipping until next scrape", i, pod.Namespace, pod.Name, ctr.Name)
klog.Warningf("Device %d in Pod %s/%s, Container %s has invalid UTF-8 UUID; skipping until next scrape", i, pod.Namespace, pod.Name, ctr.Name)
continue
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/vGPUmonitor/metrics_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ func TestCollectContainerMetricsBadInput(t *testing.T) {
if _, err := collectContainer(t, &nvidia.ContainerUsage{}, 0); err == nil {
t.Error("nil ContainerUsage.Info should return an error")
}
short := &nvidia.ContainerUsage{Info: &stubInfo{uuids: []string{"gpu-short"}}}
metrics, err := collectContainer(t, short, 0)
uninit := &nvidia.ContainerUsage{Info: &stubInfo{uuids: []string{"\x00" + strings.Repeat("\x00", 39)}}}
metrics, err := collectContainer(t, uninit, 0)
if err != nil {
t.Fatalf("a UUID shorter than 40 chars should be skipped, not error: %v", err)
t.Fatalf("uninitialized UUID should be skipped, not error: %v", err)
}
if len(metrics) != 0 {
t.Errorf("got %d metrics for a short UUID, want 0", len(metrics))
t.Errorf("got %d metrics for an uninitialized UUID, want 0", len(metrics))
}
}

Expand Down
Loading