Alejandro 4 лет назад
Родитель
Сommit
f4c0cdb019
2 измененных файлов с 10 добавлено и 2 удалено
  1. 1 2
      pkg/kubecost/allocation.go
  2. 9 0
      pkg/kubecost/allocation_test.go

+ 1 - 2
pkg/kubecost/allocation.go

@@ -2272,7 +2272,6 @@ func (asr *AllocationSetRange) AccumulateBy(resolution time.Duration) (*Allocati
 	asr.Lock()
 	defer asr.Unlock()
 
-	// check as.window and accumulate sets until sum of window durations == time.duration wanted -> add accumulated set to allocSetRange
 	for i, as := range asr.allocations {
 		allocSet, err = allocSet.accumulate(as)
 		if err != nil {
@@ -2283,7 +2282,7 @@ func (asr *AllocationSetRange) AccumulateBy(resolution time.Duration) (*Allocati
 			currAccumulatedSum += allocSet.Window.Duration()
 
 			// check if end of asr to sum the final set
-			// If accumulated sum never reaches the desired resolution then all sets are returned as 1 accumulated set
+			// If accumulated sum !>= resolution return 1 accumulated set
 			if currAccumulatedSum >= resolution || i == len(asr.allocations)-1 {
 				allocSetRange.allocations = append(allocSetRange.allocations, allocSet)
 				allocSet = &AllocationSet{allocations: map[string]*Allocation{}}

+ 9 - 0
pkg/kubecost/allocation_test.go

@@ -2285,6 +2285,15 @@ func TestAllocationSetRange_AccumulateBy(t *testing.T) {
 
 			testId: "AccumulateBy Test 8",
 		},
+		{
+			asr:        NewAllocationSetRange(ago2dAS, yesterdayAS, todayAS),
+			resolution: time.Hour * 24 * 2,
+
+			expectedCost: 18.0,
+			expectedSets: 2,
+
+			testId: "AccumulateBy Test 9",
+		},
 	}
 
 	for _, c := range cases {