Răsfoiți Sursa

Detect, prevent, and log warning if precomputed sharing coefficients generate a NaN

Niko Kovacevic 4 ani în urmă
părinte
comite
7bb9e6c5d2
1 a modificat fișierele cu 6 adăugiri și 1 ștergeri
  1. 6 1
      pkg/kubecost/summaryallocation.go

+ 6 - 1
pkg/kubecost/summaryallocation.go

@@ -875,7 +875,12 @@ func (sas *SummaryAllocationSet) AggregateBy(aggregateBy []string, options *Allo
 			// Compute sharing coeffs by dividing the thus-far accumulated
 			// Compute sharing coeffs by dividing the thus-far accumulated
 			// numerators by the now-finalized denominator.
 			// numerators by the now-finalized denominator.
 			for key := range sharingCoeffs {
 			for key := range sharingCoeffs {
-				sharingCoeffs[key] /= sharingCoeffDenominator
+				if sharingCoeffs[key] > 0.0 {
+					sharingCoeffs[key] /= sharingCoeffDenominator
+				} else {
+					log.Warningf("SummaryAllocation: detected illegal sharing coefficient for %s: %v (setting to zero)", key, sharingCoeffs[key])
+					sharingCoeffs[key] = 0.0
+				}
 			}
 			}
 
 
 			for key, sa := range resultSet.SummaryAllocations {
 			for key, sa := range resultSet.SummaryAllocations {