Parcourir la source

clearer price setting

AjayTripathy il y a 6 ans
Parent
commit
43f6fcc810
1 fichiers modifiés avec 10 ajouts et 6 suppressions
  1. 10 6
      costmodel/costmodel.go

+ 10 - 6
costmodel/costmodel.go

@@ -902,7 +902,7 @@ func findDeletedNodeInfo(cli prometheusClient.Client, missingNodes map[string]*c
 		}
 		}
 
 
 		if len(cpuCosts) == 0 {
 		if len(cpuCosts) == 0 {
-			klog.V(1).Infof("Historical data for node prices not available. Ingest this server's /metrics endpoint to get that data.")
+			klog.V(1).Infof("Kubecost prometheus metrics not currently available. Ingest this server's /metrics endpoint to get that data.")
 		}
 		}
 
 
 		for node, costv := range cpuCosts {
 		for node, costv := range cpuCosts {
@@ -1106,13 +1106,13 @@ func (cm *CostModel) GetNodeCost(cp costAnalyzerCloud.Provider) (map[string]*cos
 			cpuToRAMRatio := defaultCPU / defaultRAM
 			cpuToRAMRatio := defaultCPU / defaultRAM
 			if math.IsNaN(cpuToRAMRatio) {
 			if math.IsNaN(cpuToRAMRatio) {
 				klog.V(1).Infof("[Warning] cpuToRAMRatio[defaultCPU: %f / defaultRam: %f] is NaN. Setting to 0.", defaultCPU, defaultRAM)
 				klog.V(1).Infof("[Warning] cpuToRAMRatio[defaultCPU: %f / defaultRam: %f] is NaN. Setting to 0.", defaultCPU, defaultRAM)
-				cpuToRAMRatio = 1
+				cpuToRAMRatio = 0
 			}
 			}
 
 
 			gpuToRAMRatio := defaultGPU / defaultRAM
 			gpuToRAMRatio := defaultGPU / defaultRAM
 			if math.IsNaN(gpuToRAMRatio) {
 			if math.IsNaN(gpuToRAMRatio) {
 				klog.V(1).Infof("[Warning] gpuToRAMRatio is NaN. Setting to 0.")
 				klog.V(1).Infof("[Warning] gpuToRAMRatio is NaN. Setting to 0.")
-				gpuToRAMRatio = 1
+				gpuToRAMRatio = 0
 			}
 			}
 
 
 			ramGB := ram / 1024 / 1024 / 1024
 			ramGB := ram / 1024 / 1024 / 1024
@@ -1186,7 +1186,7 @@ func (cm *CostModel) GetNodeCost(cp costAnalyzerCloud.Provider) (map[string]*cos
 			cpuToRAMRatio := defaultCPU / defaultRAM
 			cpuToRAMRatio := defaultCPU / defaultRAM
 			if math.IsNaN(cpuToRAMRatio) {
 			if math.IsNaN(cpuToRAMRatio) {
 				klog.V(1).Infof("[Warning] cpuToRAMRatio[defaultCPU: %f / defaultRam: %f] is NaN. Setting to 0.", defaultCPU, defaultRAM)
 				klog.V(1).Infof("[Warning] cpuToRAMRatio[defaultCPU: %f / defaultRam: %f] is NaN. Setting to 0.", defaultCPU, defaultRAM)
-				cpuToRAMRatio = 1
+				cpuToRAMRatio = 0
 			}
 			}
 
 
 			ramGB := ram / 1024 / 1024 / 1024
 			ramGB := ram / 1024 / 1024 / 1024
@@ -1228,8 +1228,12 @@ func (cm *CostModel) GetNodeCost(cp costAnalyzerCloud.Provider) (map[string]*cos
 
 
 			cpuPrice := ramPrice * cpuToRAMRatio
 			cpuPrice := ramPrice * cpuToRAMRatio
 
 
-			newCnode.VCPUCost = fmt.Sprintf("%f", cpuPrice)
-			newCnode.RAMCost = fmt.Sprintf("%f", ramPrice)
+			if defaultRAM != 0 {
+				newCnode.VCPUCost = fmt.Sprintf("%f", cpuPrice)
+				newCnode.RAMCost = fmt.Sprintf("%f", ramPrice)
+			} else { // just assign the full price to CPU
+				newCnode.VCPUCost = fmt.Sprintf("%f", nodePrice)
+			}
 			newCnode.RAMBytes = fmt.Sprintf("%f", ram)
 			newCnode.RAMBytes = fmt.Sprintf("%f", ram)
 
 
 			klog.V(4).Infof("Computed \"%s\" RAM Cost := %v", name, newCnode.RAMCost)
 			klog.V(4).Infof("Computed \"%s\" RAM Cost := %v", name, newCnode.RAMCost)