|
|
@@ -605,8 +605,8 @@ func (cm *CostModel) ComputeCostData(cli prometheusClient.Client, clientset kube
|
|
|
NamespaceLabels: nsLabels,
|
|
|
ClusterID: clusterID,
|
|
|
}
|
|
|
- costs.CPUAllocation = getContainerAllocation(costs.CPUReq, costs.CPUUsed)
|
|
|
- costs.RAMAllocation = getContainerAllocation(costs.RAMReq, costs.RAMUsed)
|
|
|
+ costs.CPUAllocation = getContainerAllocation(costs.CPUReq, costs.CPUUsed, "CPU")
|
|
|
+ costs.RAMAllocation = getContainerAllocation(costs.RAMReq, costs.RAMUsed, "RAM")
|
|
|
if filterNamespace == "" {
|
|
|
containerNameCost[newKey] = costs
|
|
|
} else if costs.Namespace == filterNamespace {
|
|
|
@@ -675,8 +675,8 @@ func (cm *CostModel) ComputeCostData(cli prometheusClient.Client, clientset kube
|
|
|
NamespaceLabels: namespacelabels,
|
|
|
ClusterID: c.ClusterID,
|
|
|
}
|
|
|
- costs.CPUAllocation = getContainerAllocation(costs.CPUReq, costs.CPUUsed)
|
|
|
- costs.RAMAllocation = getContainerAllocation(costs.RAMReq, costs.RAMUsed)
|
|
|
+ costs.CPUAllocation = getContainerAllocation(costs.CPUReq, costs.CPUUsed, "CPU")
|
|
|
+ costs.RAMAllocation = getContainerAllocation(costs.RAMReq, costs.RAMUsed, "RAM")
|
|
|
if filterNamespace == "" {
|
|
|
containerNameCost[key] = costs
|
|
|
missingContainers[key] = costs
|
|
|
@@ -843,11 +843,22 @@ func findDeletedNodeInfo(cli prometheusClient.Client, missingNodes map[string]*c
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func getContainerAllocation(req []*Vector, used []*Vector) []*Vector {
|
|
|
+func getContainerAllocation(req []*Vector, used []*Vector, allocationType string) []*Vector {
|
|
|
// The result of the normalize operation will be a new []*Vector to replace the requests
|
|
|
allocationOp := func(r *Vector, x *float64, y *float64) bool {
|
|
|
if x != nil && y != nil {
|
|
|
- r.Value = math.Max(*x, *y)
|
|
|
+ x1 := *x
|
|
|
+ if math.IsNaN(x1) {
|
|
|
+ klog.V(1).Infof("Warning: NaN value found during %s allocation calculation for requests.", allocationType)
|
|
|
+ x1 = 0.0
|
|
|
+ }
|
|
|
+ y1 := *y
|
|
|
+ if math.IsNaN(y1) {
|
|
|
+ klog.V(1).Infof("Warning: NaN value found during %s allocation calculation for used.", allocationType)
|
|
|
+ y1 = 0.0
|
|
|
+ }
|
|
|
+
|
|
|
+ r.Value = math.Max(x1, y1)
|
|
|
} else if x != nil {
|
|
|
r.Value = *x
|
|
|
} else if y != nil {
|