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

Implement TotalCost for AssetSetRange

Niko Kovacevic 4 лет назад
Родитель
Сommit
d4d20898f8
1 измененных файлов с 17 добавлено и 0 удалено
  1. 17 0
      pkg/kubecost/asset.go

+ 17 - 0
pkg/kubecost/asset.go

@@ -3054,6 +3054,23 @@ func (asr *AssetSetRange) Minutes() float64 {
 	return duration.Minutes()
 }
 
+// TotalCost returns the AssetSetRange's total cost
+func (asr *AssetSetRange) TotalCost() float64 {
+	if asr == nil {
+		return 0.0
+	}
+
+	asr.RLock()
+	defer asr.RUnlock()
+
+	tc := 0.0
+	for _, as := range asr.assets {
+		tc += as.TotalCost()
+	}
+
+	return tc
+}
+
 // This is a helper type. The Asset API returns a json which cannot be natively
 // unmarshaled into any Asset struct. Therefore, this struct IN COMBINATION WITH
 // DESERIALIZATION LOGIC DEFINED IN asset_unmarshal.go can unmarshal a json directly