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

Merge branch 'master' into niko/clustercost-fix

Niko Kovacevic 6 лет назад
Родитель
Сommit
15904eb1ae
4 измененных файлов с 17 добавлено и 9 удалено
  1. 3 1
      pkg/cloud/azureprovider.go
  2. 1 0
      pkg/cloud/provider.go
  3. 3 0
      pkg/costmodel/costmodel.go
  4. 10 8
      pkg/costmodel/router.go

+ 3 - 1
pkg/cloud/azureprovider.go

@@ -408,7 +408,9 @@ func (az *Azure) DownloadPricingData() error {
 						for _, rate := range v.MeterRates {
 							priceInUsd += *rate
 						}
-						priceStr := fmt.Sprintf("%f", priceInUsd)
+						// rate is in GB per month, resolve to GB per hour
+						pricePerHour := priceInUsd / 730.0
+						priceStr := fmt.Sprintf("%f", pricePerHour)
 
 						key := region + "," + storageClass
 						klog.V(4).Infof("Adding PV.Key: %s, Cost: %s", key, priceStr)

+ 1 - 0
pkg/cloud/provider.go

@@ -59,6 +59,7 @@ type Node struct {
 	GPUName          string                `json:"gpuName"`
 	GPUCost          string                `json:"gpuCost"`
 	InstanceType     string                `json:"instanceType,omitempty"`
+	Region           string                `json:"region,omitempty"`
 	Reserved         *ReservedInstanceData `json:"reserved,omitempty"`
 }
 

+ 3 - 0
pkg/costmodel/costmodel.go

@@ -1144,6 +1144,9 @@ func (cm *CostModel) GetNodeCost(cp costAnalyzerCloud.Provider) (map[string]*cos
 		if newCnode.InstanceType == "" {
 			newCnode.InstanceType = n.Labels[v1.LabelInstanceType]
 		}
+		if newCnode.Region == "" {
+			newCnode.Region = n.Labels[v1.LabelZoneRegion]
+		}
 
 		var cpu float64
 		if newCnode.VCPU == "" {

+ 10 - 8
pkg/costmodel/router.go

@@ -709,13 +709,15 @@ func (a *Accesses) recordPrices() {
 					}
 				}
 				nodeType := node.InstanceType
+				nodeRegion := node.Region
+				nodeUsageType := node.UsageType
 
 				totalCost := cpu*cpuCost + ramCost*(ram/1024/1024/1024) + gpu*gpuCost
 
-				a.CPUPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(cpuCost)
-				a.RAMPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(ramCost)
-				a.GPUPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(gpuCost)
-				a.NodeTotalPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType).Set(totalCost)
+				a.CPUPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType, nodeRegion, nodeUsageType).Set(cpuCost)
+				a.RAMPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType, nodeRegion, nodeUsageType).Set(ramCost)
+				a.GPUPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType, nodeRegion, nodeUsageType).Set(gpuCost)
+				a.NodeTotalPriceRecorder.WithLabelValues(nodeName, nodeName, nodeType, nodeRegion, nodeUsageType).Set(totalCost)
 				labelKey := getKeyFromLabelStrings(nodeName, nodeName)
 				nodeSeen[labelKey] = true
 			}
@@ -968,22 +970,22 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) {
 	cpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_cpu_hourly_cost",
 		Help: "node_cpu_hourly_cost hourly cost for each cpu on this node",
-	}, []string{"instance", "node", "instance_type"})
+	}, []string{"instance", "node", "instance_type", "region", "usage_type"})
 
 	ramGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_ram_hourly_cost",
 		Help: "node_ram_hourly_cost hourly cost for each gb of ram on this node",
-	}, []string{"instance", "node", "instance_type"})
+	}, []string{"instance", "node", "instance_type", "region", "usage_type"})
 
 	gpuGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_gpu_hourly_cost",
 		Help: "node_gpu_hourly_cost hourly cost for each gpu on this node",
-	}, []string{"instance", "node", "instance_type"})
+	}, []string{"instance", "node", "instance_type", "region", "usage_type"})
 
 	totalGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "node_total_hourly_cost",
 		Help: "node_total_hourly_cost Total node cost per hour",
-	}, []string{"instance", "node", "instance_type"})
+	}, []string{"instance", "node", "instance_type", "region", "usage_type"})
 
 	pvGv := prometheus.NewGaugeVec(prometheus.GaugeOpts{
 		Name: "pv_hourly_cost",