AjayTripathy 6 лет назад
Родитель
Сommit
c5c3cb7d49
2 измененных файлов с 16 добавлено и 10 удалено
  1. 11 9
      costmodel/aggregations.go
  2. 5 1
      costmodel/router.go

+ 11 - 9
costmodel/aggregations.go

@@ -90,13 +90,12 @@ func ComputeIdleCoefficient(costData map[string]*CostData, cli prometheusClient.
 		return nil, err
 	}
 
-	aggregateContainerCosts := AggregateCostData(costData, "cluster", []string{}, cp, &AggregationOptions{Discount: discount})
 	allTotals, err := ClusterCostsForAllClusters(cli, cp, windowString, offset)
 	if err != nil {
 		return nil, err
 	}
 	for cid, totals := range allTotals {
-		klog.Infof("%+v", totals)
+		klog.Infof("%s: %+v", cid, totals)
 		if !(len(totals.CPUCost) > 0 && len(totals.MemCost) > 0 && len(totals.StorageCost) > 0) {
 			klog.V(1).Infof("WARNING: NO DATA FOR CLUSTER %s. Is it emitting data?", cid)
 			coefficients[cid] = 1.0
@@ -121,16 +120,19 @@ func ComputeIdleCoefficient(costData map[string]*CostData, cli prometheusClient.
 		totalClusterCostOverWindow := (totalClusterCost / 730) * windowDuration.Hours()
 		totalContainerCost := 0.0
 		for _, costDatum := range costData {
-			cpuv, ramv, gpuv, pvvs, _ := getPriceVectors(cp, costDatum, "", discount, 1)
-			totalContainerCost += totalVectors(cpuv)
-			totalContainerCost += totalVectors(ramv)
-			totalContainerCost += totalVectors(gpuv)
-			for _, pv := range pvvs {
-				totalContainerCost += totalVectors(pv)
+			if costDatum.ClusterID == cid {
+				cpuv, ramv, gpuv, pvvs, _ := getPriceVectors(cp, costDatum, "", discount, 1)
+				totalContainerCost += totalVectors(cpuv)
+				totalContainerCost += totalVectors(ramv)
+				totalContainerCost += totalVectors(gpuv)
+				for _, pv := range pvvs {
+					totalContainerCost += totalVectors(pv)
+				}
 			}
+
 		}
 
-		coefficients[cid] = aggregateContainerCosts[cid].TotalCost / totalClusterCostOverWindow
+		coefficients[cid] = totalContainerCost / totalClusterCostOverWindow
 	}
 
 	return coefficients, nil

+ 5 - 1
costmodel/router.go

@@ -287,7 +287,7 @@ func (a *Accesses) AggregateCostModel(w http.ResponseWriter, r *http.Request, ps
 
 	// disableCache, if set to "true", tells this function to recompute and
 	// cache the requested data
-	disableCache := r.URL.Query().Get("disableCache") == "true"
+	disableCache := r.URL.Query().Get("disableCache") == "true" || allocateIdle
 
 	// clearCache, if set to "true", tells this function to flush the cache,
 	// then recompute and cache the requested data
@@ -463,6 +463,10 @@ func (a *Accesses) AggregateCostModel(w http.ResponseWriter, r *http.Request, ps
 		sr = NewSharedResourceInfo(true, sn, sln, slv)
 	}
 
+	for cid, idleCoefficient := range idleCoefficients {
+		klog.Infof("Idle Coeff: %s: %f", cid, idleCoefficient)
+	}
+
 	// aggregate cost model data by given fields and cache the result for the default expiration
 	opts := &AggregationOptions{
 		DataCount:          dataCount,