Niko Kovacevic 5 лет назад
Родитель
Сommit
af4cfd8d48
2 измененных файлов с 6 добавлено и 15 удалено
  1. 5 14
      pkg/costmodel/allocation.go
  2. 1 1
      pkg/kubecost/allocation.go

+ 5 - 14
pkg/costmodel/allocation.go

@@ -85,10 +85,7 @@ func (cm *CostModel) ComputeAllocation(start, end time.Time, resolution time.Dur
 	clusterStart := map[string]time.Time{}
 	clusterStart := map[string]time.Time{}
 	clusterEnd := map[string]time.Time{}
 	clusterEnd := map[string]time.Time{}
 
 
-	// TODO niko/computeallocation make this configurable?
-	batchSize := 6 * time.Hour
-
-	cm.buildPodMap(window, resolution, batchSize, podMap, clusterStart, clusterEnd)
+	cm.buildPodMap(window, resolution, env.GetETLMaxBatchDuration(), podMap, clusterStart, clusterEnd)
 
 
 	// (2) Run and apply remaining queries
 	// (2) Run and apply remaining queries
 
 
@@ -424,12 +421,8 @@ func (cm *CostModel) buildPodMap(window kubecost.Window, resolution, maxBatchSiz
 			queryProfile := time.Now()
 			queryProfile := time.Now()
 			resPods, err = ctx.Query(queryPods).Await()
 			resPods, err = ctx.Query(queryPods).Await()
 			if err != nil {
 			if err != nil {
-				// TODO niko/computeallocation remove log
-				log.Profile(queryProfile, fmt.Sprintf("CostModel.ComputeAllocation: pod query batch %d try %d failed: %s", numQuery, numTries, queryPods))
+				log.Profile(queryProfile, fmt.Sprintf("CostModel.ComputeAllocation: pod query %d try %d failed: %s", numQuery, numTries, queryPods))
 				resPods = nil
 				resPods = nil
-			} else {
-				// TODO niko/computeallocation remove log
-				log.Profile(queryProfile, fmt.Sprintf("CostModel.ComputeAllocation: pod query batch %d try %d succeeded: %s", numQuery, numTries, queryPods))
 			}
 			}
 		}
 		}
 
 
@@ -788,9 +781,6 @@ func applyGPUsRequested(podMap map[podKey]*Pod, resGPUsRequested []*prom.QueryRe
 			pod.AppendContainer(container)
 			pod.AppendContainer(container)
 		}
 		}
 
 
-		// TODO niko/computeallocation remove log
-		log.Infof("CostModel.ComputeAllocation: GPU results: %s=%f", key, res.Values[0].Value)
-
 		hrs := pod.Allocations[container].Minutes() / 60.0
 		hrs := pod.Allocations[container].Minutes() / 60.0
 		pod.Allocations[container].GPUHours = res.Values[0].Value * hrs
 		pod.Allocations[container].GPUHours = res.Values[0].Value * hrs
 	}
 	}
@@ -1723,7 +1713,8 @@ type NodePricing struct {
 	Source          string
 	Source          string
 }
 }
 
 
-// TODO niko/computealloction comment
+// Pod describes a running pod's start and end time within a Window and
+// all the Allocations (i.e. containers) contained within it.
 type Pod struct {
 type Pod struct {
 	Window      kubecost.Window
 	Window      kubecost.Window
 	Start       time.Time
 	Start       time.Time
@@ -1732,7 +1723,7 @@ type Pod struct {
 	Allocations map[string]*kubecost.Allocation
 	Allocations map[string]*kubecost.Allocation
 }
 }
 
 
-// TODO niko/computealloction comment
+// AppendContainer adds an entry for the given container name to the Pod.
 func (p Pod) AppendContainer(container string) {
 func (p Pod) AppendContainer(container string) {
 	name := fmt.Sprintf("%s/%s/%s/%s", p.Key.Cluster, p.Key.Namespace, p.Key.Pod, container)
 	name := fmt.Sprintf("%s/%s/%s/%s", p.Key.Cluster, p.Key.Namespace, p.Key.Pod, container)
 
 

+ 1 - 1
pkg/kubecost/allocation.go

@@ -414,7 +414,7 @@ func (a *Allocation) add(that *Allocation) {
 	}
 	}
 
 
 	// Convert cumulatuve request and usage back into rates
 	// Convert cumulatuve request and usage back into rates
-	// TODO write a unit test that fails if this is done incorrectly
+	// TODO:CLEANUP write a unit test that fails if this is done incorrectly
 	a.CPUCoreRequestAverage = cpuReqCoreMins / a.Minutes()
 	a.CPUCoreRequestAverage = cpuReqCoreMins / a.Minutes()
 	a.CPUCoreUsageAverage = cpuUseCoreMins / a.Minutes()
 	a.CPUCoreUsageAverage = cpuUseCoreMins / a.Minutes()
 	a.RAMBytesRequestAverage = ramReqByteMins / a.Minutes()
 	a.RAMBytesRequestAverage = ramReqByteMins / a.Minutes()