Просмотр исходного кода

Logs

Signed-off-by: Alan Rodrigues <alanr5691@yahoo.com>
Niko Kovacevic 2 лет назад
Родитель
Сommit
1a76cb8d85
1 измененных файлов с 23 добавлено и 0 удалено
  1. 23 0
      pkg/kubecost/summaryallocation.go

+ 23 - 0
pkg/kubecost/summaryallocation.go

@@ -982,35 +982,58 @@ func (sas *SummaryAllocationSet) AggregateBy(aggregateBy []string, options *Allo
 	// 11. Distribute shared resources according to sharing coefficients.
 	// 11. Distribute shared resources according to sharing coefficients.
 	// NOTE: ShareEven is not supported
 	// NOTE: ShareEven is not supported
 	if len(shareSet.SummaryAllocations) > 0 {
 	if len(shareSet.SummaryAllocations) > 0 {
+		totalTotalCost := 0.0
+		sharedTotalCost := 0.0
+
 		sharingCoeffDenominator := 0.0
 		sharingCoeffDenominator := 0.0
 		for _, rt := range allocTotals {
 		for _, rt := range allocTotals {
 			sharingCoeffDenominator += rt.TotalCost()
 			sharingCoeffDenominator += rt.TotalCost()
+			totalTotalCost += rt.TotalCost()
 		}
 		}
 
 
 		// Do not include the shared costs, themselves, when determining
 		// Do not include the shared costs, themselves, when determining
 		// sharing coefficients.
 		// sharing coefficients.
 		for _, rt := range sharedResourceTotals {
 		for _, rt := range sharedResourceTotals {
 			sharingCoeffDenominator -= rt.TotalCost()
 			sharingCoeffDenominator -= rt.TotalCost()
+			sharedTotalCost += rt.TotalCost()
 		}
 		}
 
 
 		// Do not include the unmounted costs when determining sharing
 		// Do not include the unmounted costs when determining sharing
 		// coefficients because they do not receive shared costs.
 		// coefficients because they do not receive shared costs.
 		sharingCoeffDenominator -= totalUnmountedCost
 		sharingCoeffDenominator -= totalUnmountedCost
 
 
+		log.Infof("BD-152: sharingCoeffDenom=%f (total cost: %f; shared cost: %f; unmounted cost: %f)", sharingCoeffDenominator, totalTotalCost, sharedTotalCost, totalUnmountedCost)
+
 		if sharingCoeffDenominator <= 0.0 {
 		if sharingCoeffDenominator <= 0.0 {
 			log.Warnf("SummaryAllocation: sharing coefficient denominator is %f", sharingCoeffDenominator)
 			log.Warnf("SummaryAllocation: sharing coefficient denominator is %f", sharingCoeffDenominator)
 		} else {
 		} else {
+			// Needs to be 1.00000
+			sumSharingCoeffs := 0.0
+
 			// 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 {
 				if sharingCoeffs[key] > 0.0 {
 				if sharingCoeffs[key] > 0.0 {
+					before := sharingCoeffs[key]
 					sharingCoeffs[key] /= sharingCoeffDenominator
 					sharingCoeffs[key] /= sharingCoeffDenominator
+
+					log.Infof("BD152: sharingCoeff[%s]=%f ; numerator before=%f", key, sharingCoeffs[key], before)
+
+					sumSharingCoeffs += sharingCoeffs[key]
 				} else {
 				} else {
 					log.Warnf("SummaryAllocation: detected illegal sharing coefficient for %s: %v (setting to zero)", key, sharingCoeffs[key])
 					log.Warnf("SummaryAllocation: detected illegal sharing coefficient for %s: %v (setting to zero)", key, sharingCoeffs[key])
 					sharingCoeffs[key] = 0.0
 					sharingCoeffs[key] = 0.0
 				}
 				}
 			}
 			}
 
 
+			// HERE if you add all the sharingCoeffs, you should get 1.00000 exactly
+			//  "integration": 0.27
+			//  "ally": 0.13
+			//  ...
+			//  TOTAL : 1.000000
+
+			log.Infof("BD152: sum of sharingCoeffs = %f", sumSharingCoeffs)
+
 			for key, sa := range resultSet.SummaryAllocations {
 			for key, sa := range resultSet.SummaryAllocations {
 				// Idle and unmounted allocations, by definition, do not
 				// Idle and unmounted allocations, by definition, do not
 				// receive shared cost
 				// receive shared cost