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

WIP debugging aggregation deployment data

Niko Kovacevic 6 лет назад
Родитель
Сommit
4e894fe848
3 измененных файлов с 27 добавлено и 3 удалено
  1. 14 2
      costmodel/aggregations.go
  2. 7 0
      costmodel/costmodel.go
  3. 6 1
      costmodel/router.go

+ 14 - 2
costmodel/aggregations.go

@@ -220,7 +220,12 @@ func AggregateCostData(costData map[string]*CostData, field string, subfields []
 			// It is possible to score > 100% efficiency, which is meant to be interpreted as a red flag.
 			// It is not possible to score < 0% efficiency.
 
-			agg.CPUEfficiency = 100.0
+			klog.V(1).Infof("\n\tlen(CPU allocation): %d\n\tlen(CPU requested): %d\n\tlen(CPU used): %d",
+				len(agg.CPUAllocationVectors),
+				len(agg.CPURequestedVectors),
+				len(agg.CPUUsedVectors))
+
+			agg.CPUEfficiency = 1.0
 			CPUIdle := 0.0
 			avgCPUAllocation := totalVectors(agg.CPUAllocationVectors) / float64(len(agg.CPUAllocationVectors))
 			if avgCPUAllocation > 0.0 {
@@ -230,7 +235,12 @@ func AggregateCostData(costData map[string]*CostData, field string, subfields []
 				agg.CPUEfficiency = 1.0 - CPUIdle
 			}
 
-			agg.RAMEfficiency = 100.0
+			klog.V(1).Infof("\n\tlen(RAM allocation): %d\n\tlen(RAM requested): %d\n\tlen(RAM used): %d",
+				len(agg.RAMAllocationVectors),
+				len(agg.RAMRequestedVectors),
+				len(agg.RAMUsedVectors))
+
+			agg.RAMEfficiency = 1.0
 			RAMIdle := 0.0
 			avgRAMAllocation := totalVectors(agg.RAMAllocationVectors) / float64(len(agg.RAMAllocationVectors))
 			if avgRAMAllocation > 0.0 {
@@ -273,6 +283,8 @@ func aggregateDatum(cp cloud.Provider, aggregations map[string]*Aggregation, cos
 		aggregations[key] = agg
 	}
 
+	klog.V(1).Infoln(costDatum)
+
 	mergeVectors(cp, costDatum, aggregations[key], rate, discount, idleCoefficient)
 }
 

+ 7 - 0
costmodel/costmodel.go

@@ -86,6 +86,13 @@ type CostData struct {
 	ClusterID       string                       `json:"clusterId"`
 }
 
+func (cd *CostData) String() string {
+	return fmt.Sprintf("\n\tName: %s; PodName: %s, NodeName: %s\n\tNamespace: %s\n\tDeployments: %s\n\tServices: %s\n\tCPU (req, used, alloc): %d, %d, %d\n\tRAM (req, used, alloc): %d, %d, %d",
+		cd.Name, cd.PodName, cd.NodeName, cd.Namespace, strings.Join(cd.Deployments, ", "), strings.Join(cd.Services, ", "),
+		len(cd.CPUReq), len(cd.CPUUsed), len(cd.CPUAllocation),
+		len(cd.RAMReq), len(cd.RAMUsed), len(cd.RAMAllocation))
+}
+
 type Vector struct {
 	Timestamp float64 `json:"timestamp"`
 	Value     float64 `json:"value"`

+ 6 - 1
costmodel/router.go

@@ -265,7 +265,7 @@ func (a *Accesses) AggregateCostModel(w http.ResponseWriter, r *http.Request, ps
 	namespace := r.URL.Query().Get("namespace")
 	cluster := r.URL.Query().Get("cluster")
 	field := r.URL.Query().Get("aggregation")
-	subfields := strings.Split(r.URL.Query().Get("aggregationSubfield"), ",")
+	subfieldStr := r.URL.Query().Get("aggregationSubfield")
 	rate := r.URL.Query().Get("rate")
 	allocateIdle := r.URL.Query().Get("allocateIdle") == "true"
 	sharedNamespaces := r.URL.Query().Get("sharedNamespaces")
@@ -273,6 +273,11 @@ func (a *Accesses) AggregateCostModel(w http.ResponseWriter, r *http.Request, ps
 	sharedLabelValues := r.URL.Query().Get("sharedLabelValues")
 	remote := r.URL.Query().Get("remote")
 
+	subfields := []string{}
+	if len(subfieldStr) > 0 {
+		subfields = strings.Split(r.URL.Query().Get("aggregationSubfield"), ",")
+	}
+
 	// timeSeries == true maintains the time series dimension of the data,
 	// which by default gets summed over the entire interval
 	includeTimeSeries := r.URL.Query().Get("timeSeries") == "true"