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

Added metric labels to NaN warning. Updated Warning log convention to use [] brackets

Matt Bolt 6 лет назад
Родитель
Сommit
1cffff711c
5 измененных файлов с 26 добавлено и 15 удалено
  1. 1 1
      cloud/azureprovider.go
  2. 1 1
      cloud/gcpprovider.go
  3. 6 6
      costmodel/costmodel.go
  4. 17 6
      costmodel/promparsers.go
  5. 1 1
      costmodel/router.go

+ 1 - 1
cloud/azureprovider.go

@@ -416,7 +416,7 @@ func (az *Azure) NodePricing(key Key) (*Node, error) {
 		klog.V(4).Infof("Returning pricing for node %s: %+v from key %s", key, n, key.Features())
 		klog.V(4).Infof("Returning pricing for node %s: %+v from key %s", key, n, key.Features())
 		return n, nil
 		return n, nil
 	}
 	}
-	klog.V(1).Infof("Warning: no pricing data found for %s: %s", key.Features(), key)
+	klog.V(1).Infof("[Warning] no pricing data found for %s: %s", key.Features(), key)
 	c, err := az.GetConfig()
 	c, err := az.GetConfig()
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("No default pricing data available")
 		return nil, fmt.Errorf("No default pricing data available")

+ 1 - 1
cloud/gcpprovider.go

@@ -1106,6 +1106,6 @@ func (gcp *GCP) NodePricing(key Key) (*Node, error) {
 		n.Node.BaseCPUPrice = gcp.BaseCPUPrice
 		n.Node.BaseCPUPrice = gcp.BaseCPUPrice
 		return n.Node, nil
 		return n.Node, nil
 	}
 	}
-	klog.V(1).Infof("Warning: no pricing data found for %s: %s", key.Features(), key)
+	klog.V(1).Infof("[Warning] no pricing data found for %s: %s", key.Features(), key)
 	return nil, fmt.Errorf("Warning: no pricing data found for %s", key)
 	return nil, fmt.Errorf("Warning: no pricing data found for %s", key)
 }
 }

+ 6 - 6
costmodel/costmodel.go

@@ -403,13 +403,13 @@ func (cm *CostModel) ComputeCostData(cli prometheusClient.Client, clientset kube
 
 
 	nodes, err := cm.GetNodeCost(cp)
 	nodes, err := cm.GetNodeCost(cp)
 	if err != nil {
 	if err != nil {
-		klog.V(1).Infof("Warning, no Node cost model available: " + err.Error())
+		klog.V(1).Infof("[Warning] no Node cost model available: " + err.Error())
 		return nil, err
 		return nil, err
 	}
 	}
 
 
 	pvClaimMapping, err := GetPVInfo(resultPVRequests, clusterID)
 	pvClaimMapping, err := GetPVInfo(resultPVRequests, clusterID)
 	if err != nil {
 	if err != nil {
-		klog.Infof("Unable to get PV Data: %s", err.Error())
+		klog.Infof("[Warning] Unable to get PV Data: %s", err.Error())
 	}
 	}
 	if pvClaimMapping != nil {
 	if pvClaimMapping != nil {
 		err = addPVData(cm.Cache, pvClaimMapping, cp)
 		err = addPVData(cm.Cache, pvClaimMapping, cp)
@@ -420,7 +420,7 @@ func (cm *CostModel) ComputeCostData(cli prometheusClient.Client, clientset kube
 
 
 	networkUsageMap, err := GetNetworkUsageData(resultNetZoneRequests, resultNetRegionRequests, resultNetInternetRequests, clusterID)
 	networkUsageMap, err := GetNetworkUsageData(resultNetZoneRequests, resultNetRegionRequests, resultNetInternetRequests, clusterID)
 	if err != nil {
 	if err != nil {
-		klog.V(1).Infof("Unable to get Network Cost Data: %s", err.Error())
+		klog.V(1).Infof("[Warning] Unable to get Network Cost Data: %s", err.Error())
 		networkUsageMap = make(map[string]*NetworkUsageData)
 		networkUsageMap = make(map[string]*NetworkUsageData)
 	}
 	}
 
 
@@ -849,12 +849,12 @@ func getContainerAllocation(req []*Vector, used []*Vector, allocationType string
 		if x != nil && y != nil {
 		if x != nil && y != nil {
 			x1 := *x
 			x1 := *x
 			if math.IsNaN(x1) {
 			if math.IsNaN(x1) {
-				klog.V(1).Infof("Warning: NaN value found during %s allocation calculation for requests.", allocationType)
+				klog.V(1).Infof("[Warning] NaN value found during %s allocation calculation for requests.", allocationType)
 				x1 = 0.0
 				x1 = 0.0
 			}
 			}
 			y1 := *y
 			y1 := *y
 			if math.IsNaN(y1) {
 			if math.IsNaN(y1) {
-				klog.V(1).Infof("Warning: NaN value found during %s allocation calculation for used.", allocationType)
+				klog.V(1).Infof("[Warning] NaN value found during %s allocation calculation for used.", allocationType)
 				y1 = 0.0
 				y1 = 0.0
 			}
 			}
 
 
@@ -1565,7 +1565,7 @@ func (cm *CostModel) costDataRange(cli prometheusClient.Client, clientset kubern
 
 
 	nodes, err := cm.GetNodeCost(cp)
 	nodes, err := cm.GetNodeCost(cp)
 	if err != nil {
 	if err != nil {
-		klog.V(1).Infof("Warning, no cost model available: " + err.Error())
+		klog.V(1).Infof("[Warning] no cost model available: " + err.Error())
 		return nil, err
 		return nil, err
 	}
 	}
 
 

+ 17 - 6
costmodel/promparsers.go

@@ -96,6 +96,8 @@ func NewQueryResults(queryResult interface{}) ([]*PromQueryResult, error) {
 			return nil, fmt.Errorf("Metric field is improperly formatted")
 			return nil, fmt.Errorf("Metric field is improperly formatted")
 		}
 		}
 
 
+		labels := labelsForMetric(metricMap)
+
 		// Determine if the result is a ranged data set or single value
 		// Determine if the result is a ranged data set or single value
 		_, isRange := resultInterface["values"]
 		_, isRange := resultInterface["values"]
 
 
@@ -106,7 +108,7 @@ func NewQueryResults(queryResult interface{}) ([]*PromQueryResult, error) {
 				return nil, fmt.Errorf("Value field does not exist in data result vector")
 				return nil, fmt.Errorf("Value field does not exist in data result vector")
 			}
 			}
 
 
-			v, err := parseDataPoint(dataPoint)
+			v, err := parseDataPoint(dataPoint, labels)
 			if err != nil {
 			if err != nil {
 				return nil, err
 				return nil, err
 			}
 			}
@@ -118,7 +120,7 @@ func NewQueryResults(queryResult interface{}) ([]*PromQueryResult, error) {
 			}
 			}
 
 
 			for _, value := range values {
 			for _, value := range values {
-				v, err := parseDataPoint(value)
+				v, err := parseDataPoint(value, labels)
 				if err != nil {
 				if err != nil {
 					return nil, err
 					return nil, err
 				}
 				}
@@ -136,7 +138,7 @@ func NewQueryResults(queryResult interface{}) ([]*PromQueryResult, error) {
 	return result, nil
 	return result, nil
 }
 }
 
 
-func parseDataPoint(dataPoint interface{}) (*Vector, error) {
+func parseDataPoint(dataPoint interface{}, labels string) (*Vector, error) {
 	value, ok := dataPoint.([]interface{})
 	value, ok := dataPoint.([]interface{})
 	if !ok || len(value) != 2 {
 	if !ok || len(value) != 2 {
 		return nil, fmt.Errorf("Improperly formatted datapoint from Prometheus")
 		return nil, fmt.Errorf("Improperly formatted datapoint from Prometheus")
@@ -149,7 +151,7 @@ func parseDataPoint(dataPoint interface{}) (*Vector, error) {
 	}
 	}
 
 
 	if math.IsNaN(v) {
 	if math.IsNaN(v) {
-		klog.V(1).Infof("Warning: Found NaN value parsing vector data point.")
+		klog.V(1).Infof("[Warning] Found NaN value parsing vector data point for metric: %s", labels)
 		v = 0.0
 		v = 0.0
 	}
 	}
 
 
@@ -184,14 +186,14 @@ func GetPVInfo(qr interface{}, defaultClusterID string) (map[string]*PersistentV
 
 
 		volumeName, err := val.GetString("volumename")
 		volumeName, err := val.GetString("volumename")
 		if err != nil {
 		if err != nil {
-			klog.V(4).Infof("Warning: Unfulfilled claim %s: volumename field does not exist in data result vector", pvcName)
+			klog.V(4).Infof("[Warning] Unfulfilled claim %s: volumename field does not exist in data result vector", pvcName)
 			volumeName = ""
 			volumeName = ""
 		}
 		}
 
 
 		pvClass, err := val.GetString("storageclass")
 		pvClass, err := val.GetString("storageclass")
 		if err != nil {
 		if err != nil {
 			// TODO: We need to look up the actual PV and PV capacity. For now just proceed with "".
 			// TODO: We need to look up the actual PV and PV capacity. For now just proceed with "".
-			klog.V(2).Infof("Storage Class not found for claim \"%s/%s\".", ns, pvcName)
+			klog.V(2).Infof("[Warning] Storage Class not found for claim \"%s/%s\".", ns, pvcName)
 			pvClass = ""
 			pvClass = ""
 		}
 		}
 
 
@@ -434,3 +436,12 @@ func GetServiceSelectorLabelsMetrics(queryResult interface{}, defaultClusterID s
 
 
 	return toReturn, nil
 	return toReturn, nil
 }
 }
+
+func labelsForMetric(metricMap map[string]interface{}) string {
+	var pairs []string
+	for k, v := range metricMap {
+		pairs = append(pairs, fmt.Sprintf("%s:%+v", k, v))
+	}
+
+	return fmt.Sprintf("{%s}", strings.Join(pairs, ", "))
+}

+ 1 - 1
costmodel/router.go

@@ -982,7 +982,7 @@ func Initialize() {
 
 
 			_, err = ValidatePrometheus(thanosCli, true)
 			_, err = ValidatePrometheus(thanosCli, true)
 			if err != nil {
 			if err != nil {
-				klog.V(1).Infof("Warning: Failed to query Thanos at %s. Error: %s.", thanosUrl, err.Error())
+				klog.V(1).Infof("[Warning] Failed to query Thanos at %s. Error: %s.", thanosUrl, err.Error())
 				A.ThanosClient = thanosCli
 				A.ThanosClient = thanosCli
 			} else {
 			} else {
 				klog.V(1).Info("Success: retrieved the 'up' query against Thanos at: " + thanosUrl)
 				klog.V(1).Info("Success: retrieved the 'up' query against Thanos at: " + thanosUrl)