ソースを参照

better normalization error logging, fix int->float issue

AjayTripathy 6 年 前
コミット
892e6b60d2
2 ファイル変更13 行追加11 行削除
  1. 12 10
      costmodel/costmodel.go
  2. 1 1
      costmodel/router.go

+ 12 - 10
costmodel/costmodel.go

@@ -340,7 +340,7 @@ func (cm *CostModel) ComputeCostData(cli prometheusClient.Client, clientset kube
 	queryRAMUsage := fmt.Sprintf(queryRAMUsageStr, window, offset, window, offset)
 	queryRAMUsage := fmt.Sprintf(queryRAMUsageStr, window, offset, window, offset)
 	queryCPURequests := fmt.Sprintf(queryCPURequestsStr, window, offset, window, offset)
 	queryCPURequests := fmt.Sprintf(queryCPURequestsStr, window, offset, window, offset)
 	queryCPUUsage := fmt.Sprintf(queryCPUUsageStr, window, offset)
 	queryCPUUsage := fmt.Sprintf(queryCPUUsageStr, window, offset)
-	queryGPURequests := fmt.Sprintf(queryGPURequestsStr, window, offset, window, offset, 1, window, offset)
+	queryGPURequests := fmt.Sprintf(queryGPURequestsStr, window, offset, window, offset, 1.0, window, offset)
 	queryPVRequests := fmt.Sprintf(queryPVRequestsStr)
 	queryPVRequests := fmt.Sprintf(queryPVRequestsStr)
 	queryNetZoneRequests := fmt.Sprintf(queryZoneNetworkUsage, window, "")
 	queryNetZoneRequests := fmt.Sprintf(queryZoneNetworkUsage, window, "")
 	queryNetRegionRequests := fmt.Sprintf(queryRegionNetworkUsage, window, "")
 	queryNetRegionRequests := fmt.Sprintf(queryRegionNetworkUsage, window, "")
@@ -487,7 +487,7 @@ func (cm *CostModel) ComputeCostData(cli prometheusClient.Client, clientset kube
 
 
 	normalizationValue, err := getNormalization(normalizationResult)
 	normalizationValue, err := getNormalization(normalizationResult)
 	if err != nil {
 	if err != nil {
-		return nil, fmt.Errorf("Error parsing normalization values: " + err.Error())
+		return nil, fmt.Errorf("Error parsing normalization values from %s: %s", normalization, err.Error())
 	}
 	}
 
 
 	nodes, err := cm.GetNodeCost(cp)
 	nodes, err := cm.GetNodeCost(cp)
@@ -735,14 +735,16 @@ func (cm *CostModel) ComputeCostData(cli prometheusClient.Client, clientset kube
 				CPUUsedV = []*Vector{&Vector{}}
 				CPUUsedV = []*Vector{&Vector{}}
 			}
 			}
 
 
-			var node *costAnalyzerCloud.Node
-			if n, ok := missingNodes[c.NodeName]; ok {
-				node = n
-			} else {
-				node = &costAnalyzerCloud.Node{}
-				missingNodes[c.NodeName] = node
+			node, ok := nodes[c.NodeName]
+			if !ok {
+				klog.V(4).Infof("Node \"%s\" has been deleted from Kubernetes. Query historical data to get it.", c.NodeName)
+				if n, ok := missingNodes[c.NodeName]; ok {
+					node = n
+				} else {
+					node = &costAnalyzerCloud.Node{}
+					missingNodes[c.NodeName] = node
+				}
 			}
 			}
-
 			namespacelabels, ok := namespaceLabelsMapping[c.Namespace+","+c.ClusterID]
 			namespacelabels, ok := namespaceLabelsMapping[c.Namespace+","+c.ClusterID]
 			if !ok {
 			if !ok {
 				klog.V(3).Infof("Missing data for namespace %s", c.Namespace)
 				klog.V(3).Infof("Missing data for namespace %s", c.Namespace)
@@ -1877,7 +1879,7 @@ func (cm *CostModel) costDataRange(cli prometheusClient.Client, clientset kubern
 
 
 	normalizationValue, err := getNormalizations(normalizationResults)
 	normalizationValue, err := getNormalizations(normalizationResults)
 	if err != nil {
 	if err != nil {
-		return nil, fmt.Errorf("error computing normalization for start=%s, end=%s, window=%s, res=%f: %s",
+		return nil, fmt.Errorf("error computing normalization %s for start=%s, end=%s, window=%s, res=%f: %s", normalization,
 			start, end, window, resolutionHours*60*60, err.Error())
 			start, end, window, resolutionHours*60*60, err.Error())
 	}
 	}
 
 

+ 1 - 1
costmodel/router.go

@@ -867,7 +867,7 @@ func Initialize() {
 	// We need an initial invocation because the init of the cache has happened before we had access to the provider.
 	// We need an initial invocation because the init of the cache has happened before we had access to the provider.
 	configs, err := kubeClientset.CoreV1().ConfigMaps(kubecostNamespace).Get("pricing-configs", metav1.GetOptions{})
 	configs, err := kubeClientset.CoreV1().ConfigMaps(kubecostNamespace).Get("pricing-configs", metav1.GetOptions{})
 	if err != nil {
 	if err != nil {
-		klog.Infof("ERROR FETCHING configmap: %s", err.Error())
+		klog.Infof("No configs found at installtime, using existing configs: %s", err.Error())
 	} else {
 	} else {
 		watchConfigFunc(configs)
 		watchConfigFunc(configs)
 	}
 	}