Przeglądaj źródła

Merge pull request #299 from kubecost/AjayTripathy-fix-azure-metertypes

Ajay tripathy fix azure metertypes
Ajay Tripathy 6 lat temu
rodzic
commit
7b8c81ef9e
3 zmienionych plików z 9 dodań i 4 usunięć
  1. 2 1
      cloud/azureprovider.go
  2. 6 2
      costmodel/costmodel.go
  3. 1 1
      costmodel/router.go

+ 2 - 1
cloud/azureprovider.go

@@ -325,6 +325,7 @@ func (az *Azure) DownloadPricingData() error {
 	containerServiceClient.Authorizer = authorizer
 	containerServiceClient.Authorizer = authorizer
 
 
 	rateCardFilter := fmt.Sprintf("OfferDurableId eq 'MS-AZR-0003p' and Currency eq '%s' and Locale eq 'en-US' and RegionInfo eq '%s'", config.CurrencyCode, config.AzureBillingRegion)
 	rateCardFilter := fmt.Sprintf("OfferDurableId eq 'MS-AZR-0003p' and Currency eq '%s' and Locale eq 'en-US' and RegionInfo eq '%s'", config.CurrencyCode, config.AzureBillingRegion)
+
 	klog.Infof("Using ratecard query %s", rateCardFilter)
 	klog.Infof("Using ratecard query %s", rateCardFilter)
 	result, err := rcClient.Get(context.TODO(), rateCardFilter)
 	result, err := rcClient.Get(context.TODO(), rateCardFilter)
 	if err != nil {
 	if err != nil {
@@ -343,7 +344,7 @@ func (az *Azure) DownloadPricingData() error {
 	baseCPUPrice := c.CPU
 	baseCPUPrice := c.CPU
 
 
 	for _, v := range *result.Meters {
 	for _, v := range *result.Meters {
-		if !strings.Contains(*v.MeterSubCategory, "Windows") && !strings.Contains(*v.MeterCategory, "Cloud Services") {
+		if !strings.Contains(*v.MeterSubCategory, "Windows") && strings.Contains(*v.MeterCategory, "Virtual Machines") {
 
 
 			region, err := toRegionID(*v.MeterRegion, regions)
 			region, err := toRegionID(*v.MeterRegion, regions)
 			if err != nil {
 			if err != nil {

+ 6 - 2
costmodel/costmodel.go

@@ -178,7 +178,7 @@ const (
 			), "pod_name","$1","pod","(.+)"
 			), "pod_name","$1","pod","(.+)"
 		) 
 		) 
 	) by (namespace,container_name,pod_name,node,cluster_id) 
 	) by (namespace,container_name,pod_name,node,cluster_id) 
-	* on (pod_name, namespace, node, cluster_id) group_right(container_name) label_replace(avg_over_time(kube_pod_status_phase{phase="Running"}[%s] %s), "pod_name","$1","pod","(.+)")`
+	* on (pod_name, namespace, cluster_id) group_left(container) label_replace(avg(avg_over_time(kube_pod_status_phase{phase="Running"}[%s] %s)) by (pod,namespace,cluster_id), "pod_name","$1","pod","(.+)")`
 	queryPVRequestsStr = `avg(kube_persistentvolumeclaim_info) by (persistentvolumeclaim, storageclass, namespace, volumename, cluster_id) 
 	queryPVRequestsStr = `avg(kube_persistentvolumeclaim_info) by (persistentvolumeclaim, storageclass, namespace, volumename, cluster_id) 
 						* 
 						* 
 						on (persistentvolumeclaim, namespace, cluster_id) group_right(storageclass, volumename) 
 						on (persistentvolumeclaim, namespace, cluster_id) group_right(storageclass, volumename) 
@@ -1238,7 +1238,11 @@ func (cm *CostModel) GetNodeCost(cp costAnalyzerCloud.Provider) (map[string]*cos
 				newCnode.VCPUCost = fmt.Sprintf("%f", cpuPrice)
 				newCnode.VCPUCost = fmt.Sprintf("%f", cpuPrice)
 				newCnode.RAMCost = fmt.Sprintf("%f", ramPrice)
 				newCnode.RAMCost = fmt.Sprintf("%f", ramPrice)
 			} else { // just assign the full price to CPU
 			} else { // just assign the full price to CPU
-				newCnode.VCPUCost = fmt.Sprintf("%f", nodePrice)
+				if cpu != 0 {
+					newCnode.VCPUCost = fmt.Sprintf("%f", nodePrice/cpu)
+				} else {
+					newCnode.VCPUCost = fmt.Sprintf("%f", nodePrice)
+				}
 			}
 			}
 			newCnode.RAMBytes = fmt.Sprintf("%f", ram)
 			newCnode.RAMBytes = fmt.Sprintf("%f", ram)
 
 

+ 1 - 1
costmodel/router.go

@@ -480,7 +480,7 @@ func (a *Accesses) OutOfClusterCostsWithCache(w http.ResponseWriter, r *http.Req
 	key := fmt.Sprintf(`%s:%s:%s:%s:%s`, start, end, aggregation, filterType, filterValue)
 	key := fmt.Sprintf(`%s:%s:%s:%s:%s`, start, end, aggregation, filterType, filterValue)
 	if value, found := a.OutOfClusterCache.Get(key); found && !disableCache {
 	if value, found := a.OutOfClusterCache.Get(key); found && !disableCache {
 		if data, ok := value.([]*costAnalyzerCloud.OutOfClusterAllocation); ok {
 		if data, ok := value.([]*costAnalyzerCloud.OutOfClusterAllocation); ok {
-			w.Write(WrapDataWithMessage(data, nil, fmt.Sprintf("out of cluser cache hit: %s", key)))
+			w.Write(WrapDataWithMessage(data, nil, fmt.Sprintf("out of cluster cache hit: %s", key)))
 			return
 			return
 		}
 		}
 		klog.Errorf("caching error: failed to type cast data: %s", key)
 		klog.Errorf("caching error: failed to type cast data: %s", key)