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

fix allocation of shared overhead

Ajay Tripathy 5 лет назад
Родитель
Сommit
d3050edba0
2 измененных файлов с 15 добавлено и 0 удалено
  1. 1 0
      pkg/kubecost/allocation.go
  2. 14 0
      pkg/kubecost/allocation_test.go

+ 1 - 0
pkg/kubecost/allocation.go

@@ -684,6 +684,7 @@ func (as *AllocationSet) AggregateBy(properties Properties, options *AllocationA
 				Start:      as.Start(),
 				End:        as.End(),
 				SharedCost: totalSharedCost,
+				Properties: Properties{ClusterProp: SharedSuffix}, // The allocation needs to belong to a cluster,but it really doesn't matter which one, so just make it clear.
 			})
 		}
 	}

+ 14 - 0
pkg/kubecost/allocation_test.go

@@ -1327,6 +1327,20 @@ func TestAllocationSet_AggregateBy(t *testing.T) {
 	})
 	assertAllocationWindow(t, as, "6g", startYesterday, endYesterday, 1440.0)
 
+	// 6g Share idle, share resources, shareoverhead
+	as = generateAllocationSet(start)
+	err = as.AggregateBy(Properties{NamespaceProp: ""}, &AllocationAggregationOptions{
+		FilterFuncs:       []AllocationMatchFunc{isNamespace("namespace2")},
+		ShareSplit:        ShareWeighted,
+		ShareIdle:         ShareWeighted,
+		SharedHourlyCosts: map[string]float64{"total": sharedOverheadHourlyCost},
+	})
+	assertAllocationSetTotals(t, as, "6g", err, 1, 112.31)
+	assertAllocationTotals(t, as, "6g", map[string]float64{
+		"namespace2": 112.31,
+	})
+	assertAllocationWindow(t, as, "6g", startYesterday, endYesterday, 1440.0)
+
 	// 7  Edge cases and errors
 
 	// 7a Empty AggregationProperties