소스 검색

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 년 전
부모
커밋
814fdf6f44
1개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  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 {