Browse Source

Merge pull request #201 from kubecost/AjayTripathy-safe-idle

safe idle coefficient if remotes go down
Ajay Tripathy 6 years ago
parent
commit
d325b0614d
2 changed files with 9 additions and 4 deletions
  1. 6 3
      costmodel/aggregations.go
  2. 3 1
      costmodel/cluster.go

+ 6 - 3
costmodel/aggregations.go

@@ -96,7 +96,12 @@ func ComputeIdleCoefficient(costData map[string]*CostData, cli prometheusClient.
 		return nil, err
 		return nil, err
 	}
 	}
 	for cid, totals := range allTotals {
 	for cid, totals := range allTotals {
-
+		klog.Infof("%+v", 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
+			continue
+		}
 		cpuCost, err := strconv.ParseFloat(totals.CPUCost[0][1], 64)
 		cpuCost, err := strconv.ParseFloat(totals.CPUCost[0][1], 64)
 		if err != nil {
 		if err != nil {
 			return nil, err
 			return nil, err
@@ -307,8 +312,6 @@ func aggregateDatum(cp cloud.Provider, aggregations map[string]*Aggregation, cos
 		aggregations[key] = agg
 		aggregations[key] = agg
 	}
 	}
 
 
-	klog.V(1).Infoln(costDatum)
-
 	mergeVectors(cp, costDatum, aggregations[key], rate, discount, idleCoefficient)
 	mergeVectors(cp, costDatum, aggregations[key], rate, discount, idleCoefficient)
 }
 }
 
 

+ 3 - 1
costmodel/cluster.go

@@ -150,15 +150,17 @@ func ClusterCostsForAllClusters(cli prometheusClient.Client, cloud costAnalyzerC
 	qRAM := fmt.Sprintf(queryClusterRAM, offset, offset)
 	qRAM := fmt.Sprintf(queryClusterRAM, offset, offset)
 	qStorage := fmt.Sprintf(queryStorage, windowString, offset, windowString, offset, "")
 	qStorage := fmt.Sprintf(queryStorage, windowString, offset, windowString, offset, "")
 
 
+	klog.V(4).Infof("Running query %s", qCores)
 	resultClusterCores, err := Query(cli, qCores)
 	resultClusterCores, err := Query(cli, qCores)
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("Error for query %s: %s", qCores, err.Error())
 		return nil, fmt.Errorf("Error for query %s: %s", qCores, err.Error())
 	}
 	}
+	klog.V(4).Infof("Running query %s", qRAM)
 	resultClusterRAM, err := Query(cli, qRAM)
 	resultClusterRAM, err := Query(cli, qRAM)
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("Error for query %s: %s", qRAM, err.Error())
 		return nil, fmt.Errorf("Error for query %s: %s", qRAM, err.Error())
 	}
 	}
-
+	klog.V(4).Infof("Running query %s", qRAM)
 	resultStorage, err := Query(cli, qStorage)
 	resultStorage, err := Query(cli, qStorage)
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("Error for query %s: %s", qStorage, err.Error())
 		return nil, fmt.Errorf("Error for query %s: %s", qStorage, err.Error())