Browse Source

Detect, prevent, and log warning if a NaN sharing coefficient is detected

Niko Kovacevic 4 năm trước cách đây
mục cha
commit
4a54284ce1
1 tập tin đã thay đổi với 6 bổ sung1 xóa
  1. 6 1
      pkg/kubecost/summaryallocation.go

+ 6 - 1
pkg/kubecost/summaryallocation.go

@@ -889,7 +889,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 {