Răsfoiți Sursa

Add nil check and comment.

Signed-off-by: thomasvn <thomasnguyen96@gmail.com>
thomasvn 1 an în urmă
părinte
comite
841c303773
2 a modificat fișierele cu 10 adăugiri și 0 ștergeri
  1. 4 0
      core/pkg/opencost/allocation.go
  2. 6 0
      pkg/costmodel/allocation_helpers.go

+ 4 - 0
core/pkg/opencost/allocation.go

@@ -950,6 +950,10 @@ func (a *Allocation) RAMEfficiency() float64 {
 // DCGM exporter providing Prometheus with usage metrics, this will always be
 // zero, as GPUUsageAverage will be zero (the default value).
 func (a *Allocation) GPUEfficiency() float64 {
+	if a == nil {
+		return 0.0
+	}
+
 	if a.GPURequestAverage > 0 && a.GPUUsageAverage > 0 {
 		return a.GPUUsageAverage / a.GPURequestAverage
 	}

+ 6 - 0
pkg/costmodel/allocation_helpers.go

@@ -697,6 +697,12 @@ func applyGPUsAllocated(podMap map[podKey]*pod, resGPUsRequested []*prom.QueryRe
 
 			hrs := thisPod.Allocations[container].Minutes() / 60.0
 			thisPod.Allocations[container].GPUHours = res.Values[0].Value * hrs
+
+			// For now, it will always be the case that Request==Allocation. If
+			// you would like to use a GPU you need to request the full GPU.
+			// Therefore max(usage,request) will always equal request. In the
+			// future this may need to be refactored when building support for
+			// GPU Time Slicing.
 			thisPod.Allocations[container].GPURequestAverage = res.Values[0].Value
 		}
 	}