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

Ajay tripathy fix filters (#703)

* disable legacy api option for scale

* filter fixes

* also fix efficiency sums
Ajay Tripathy 5 лет назад
Родитель
Сommit
e48cad9845
1 измененных файлов с 15 добавлено и 6 удалено
  1. 15 6
      pkg/kubecost/allocation.go

+ 15 - 6
pkg/kubecost/allocation.go

@@ -316,7 +316,7 @@ func (a *Allocation) add(that *Allocation, isShared, isAccumulating bool) {
 
 		aggTotalCost := a.TotalCost + that.TotalCost
 		if aggTotalCost > 0 {
-			a.TotalEfficiency = (a.TotalEfficiency*a.TotalCost + that.TotalEfficiency*that.TotalCost) / aggTotalCost
+			a.TotalEfficiency = (a.TotalEfficiency*(a.TotalCost-a.ExternalCost) + that.TotalEfficiency*(that.TotalCost-that.ExternalCost)) / (aggTotalCost - a.ExternalCost - that.ExternalCost)
 		} else {
 			aggTotalCost = 0.0
 		}
@@ -733,13 +733,22 @@ func (as *AllocationSet) AggregateBy(properties Properties, options *AllocationA
 	// exact key match, given each external allocation's proerties, and
 	// aggregate if an exact match is found.
 	for _, alloc := range externalSet.allocations {
-		key, err := alloc.generateKey(properties)
-		if err != nil {
-			continue
+		skip := false
+		for _, ff := range options.FilterFuncs {
+			if !ff(alloc) {
+				skip = true
+				break
+			}
 		}
+		if !skip {
+			key, err := alloc.generateKey(properties)
+			if err != nil {
+				continue
+			}
 
-		alloc.Name = key
-		aggSet.Insert(alloc)
+			alloc.Name = key
+			aggSet.Insert(alloc)
+		}
 	}
 
 	// (9) Combine all idle allocations into a single "__idle__" allocation