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

Fix bug in both Allocation and Summary Allocation where shared tenancy cost would slightly skew sharing coefficients for shared resources.

Niko Kovacevic 4 лет назад
Родитель
Сommit
63c65ab57f
2 измененных файлов с 3 добавлено и 3 удалено
  1. 2 2
      pkg/kubecost/allocation.go
  2. 1 1
      pkg/kubecost/summaryallocation.go

+ 2 - 2
pkg/kubecost/allocation.go

@@ -1499,8 +1499,8 @@ func computeShareCoeffs(aggregateBy []string, options *AllocationAggregationOpti
 		} else {
 			// Both are additive for weighted distribution, where each
 			// cumulative coefficient will be divided by the total.
-			coeffs[name] += alloc.TotalCost()
-			total += alloc.TotalCost()
+			coeffs[name] += alloc.TotalCost() - alloc.SharedCost
+			total += alloc.TotalCost() - alloc.SharedCost
 		}
 	}
 

+ 1 - 1
pkg/kubecost/summaryallocation.go

@@ -716,7 +716,7 @@ func (sas *SummaryAllocationSet) AggregateBy(aggregateBy []string, options *Allo
 		// NOTE: SummaryAllocation does not support ShareEven, so only record
 		// by cost for cost-weighted distribution.
 		if sharingCoeffs != nil {
-			sharingCoeffs[key] += sa.TotalCost()
+			sharingCoeffs[key] += sa.TotalCost() - sa.SharedCost
 		}
 
 		// 6. Distribute idle allocations according to the idle coefficients.