Przeglądaj źródła

Merge pull request #1037 from kubecost/niko/share-nan-fix

Detect, prevent, and log warning if a NaN sharing coefficient is detected
Niko Kovacevic 4 lat temu
rodzic
commit
814fdf6f44
1 zmienionych plików z 6 dodań i 1 usunięć
  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
 			// numerators by the now-finalized denominator.
 			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 {