|
|
@@ -609,7 +609,7 @@ func (cm *CostModel) ComputeCostData(cli prometheusClient.Client, clientset kube
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- err = findDeletedNodeInfo(cli, missingNodes, window)
|
|
|
+ err = findDeletedNodeInfo(cli, missingNodes, window, "")
|
|
|
if err != nil {
|
|
|
klog.V(1).Infof("Error fetching historical node data: %s", err.Error())
|
|
|
}
|
|
|
@@ -698,13 +698,13 @@ func findDeletedPodInfo(cli prometheusClient.Client, missingContainers map[strin
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func findDeletedNodeInfo(cli prometheusClient.Client, missingNodes map[string]*costAnalyzerCloud.Node, window string) error {
|
|
|
+func findDeletedNodeInfo(cli prometheusClient.Client, missingNodes map[string]*costAnalyzerCloud.Node, window, offset string) error {
|
|
|
if len(missingNodes) > 0 {
|
|
|
defer measureTime(time.Now(), profileThreshold, "Finding Deleted Node Info")
|
|
|
|
|
|
- queryHistoricalCPUCost := fmt.Sprintf(`avg_over_time(node_cpu_hourly_cost[%s])`, window)
|
|
|
- queryHistoricalRAMCost := fmt.Sprintf(`avg_over_time(node_ram_hourly_cost[%s])`, window)
|
|
|
- queryHistoricalGPUCost := fmt.Sprintf(`avg_over_time(node_gpu_hourly_cost[%s])`, window)
|
|
|
+ queryHistoricalCPUCost := fmt.Sprintf(`avg_over_time(node_cpu_hourly_cost[%s] offset %s)`, window, offset)
|
|
|
+ queryHistoricalRAMCost := fmt.Sprintf(`avg_over_time(node_ram_hourly_cost[%s] offset %s)`, window, offset)
|
|
|
+ queryHistoricalGPUCost := fmt.Sprintf(`avg_over_time(node_gpu_hourly_cost[%s] offset %s)`, window, offset)
|
|
|
|
|
|
ctx := prom.NewContext(cli)
|
|
|
cpuCostResCh := ctx.Query(queryHistoricalCPUCost)
|
|
|
@@ -738,6 +738,8 @@ func findDeletedNodeInfo(cli prometheusClient.Client, missingNodes map[string]*c
|
|
|
for node, costv := range cpuCosts {
|
|
|
if _, ok := missingNodes[node]; ok {
|
|
|
missingNodes[node].VCPUCost = fmt.Sprintf("%f", costv[0].Value)
|
|
|
+ } else {
|
|
|
+ klog.Infof("CANT FIND NODE %s", node)
|
|
|
}
|
|
|
}
|
|
|
for node, costv := range ramCosts {
|
|
|
@@ -1445,7 +1447,7 @@ func requestKeyFor(startString string, endString string, windowString string, fi
|
|
|
|
|
|
// Executes a range query for cost data
|
|
|
func (cm *CostModel) ComputeCostDataRange(cli prometheusClient.Client, clientset kubernetes.Interface, cp costAnalyzerCloud.Provider,
|
|
|
- startString, endString, windowString string, resolutionHours float64, filterNamespace string, filterCluster string, remoteEnabled bool) (map[string]*CostData, error) {
|
|
|
+ startString, endString, windowString string, resolutionHours float64, filterNamespace string, filterCluster string, remoteEnabled bool, offset string) (map[string]*CostData, error) {
|
|
|
// Create a request key for request grouping. This key will be used to represent the cost-model result
|
|
|
// for the specific inputs to prevent multiple queries for identical data.
|
|
|
key := requestKeyFor(startString, endString, windowString, filterNamespace, filterCluster, remoteEnabled)
|
|
|
@@ -1455,7 +1457,7 @@ func (cm *CostModel) ComputeCostDataRange(cli prometheusClient.Client, clientset
|
|
|
// If there is already a request out that uses the same data, wait for it to return to share the results.
|
|
|
// Otherwise, start executing.
|
|
|
result, err, _ := cm.RequestGroup.Do(key, func() (interface{}, error) {
|
|
|
- return cm.costDataRange(cli, clientset, cp, startString, endString, windowString, resolutionHours, filterNamespace, filterCluster, remoteEnabled)
|
|
|
+ return cm.costDataRange(cli, clientset, cp, startString, endString, windowString, resolutionHours, filterNamespace, filterCluster, remoteEnabled, offset)
|
|
|
})
|
|
|
|
|
|
data, ok := result.(map[string]*CostData)
|
|
|
@@ -1466,7 +1468,7 @@ func (cm *CostModel) ComputeCostDataRange(cli prometheusClient.Client, clientset
|
|
|
return data, err
|
|
|
}
|
|
|
|
|
|
-func (cm *CostModel) costDataRange(cli prometheusClient.Client, clientset kubernetes.Interface, cp costAnalyzerCloud.Provider, startString, endString, windowString string, resolutionHours float64, filterNamespace string, filterCluster string, remoteEnabled bool) (map[string]*CostData, error) {
|
|
|
+func (cm *CostModel) costDataRange(cli prometheusClient.Client, clientset kubernetes.Interface, cp costAnalyzerCloud.Provider, startString, endString, windowString string, resolutionHours float64, filterNamespace string, filterCluster string, remoteEnabled bool, offset string) (map[string]*CostData, error) {
|
|
|
layout := "2006-01-02T15:04:05.000Z"
|
|
|
|
|
|
start, err := time.Parse(layout, startString)
|
|
|
@@ -1848,7 +1850,7 @@ func (cm *CostModel) costDataRange(cli prometheusClient.Client, clientset kubern
|
|
|
|
|
|
namespaceLabels, ok := namespaceLabelsMapping[nsKey]
|
|
|
if !ok {
|
|
|
- klog.V(3).Infof("Missing data for namespace %s", c.Namespace)
|
|
|
+ klog.V(4).Infof("Missing data for namespace %s", c.Namespace)
|
|
|
}
|
|
|
|
|
|
pLabels := podLabels[podKey]
|
|
|
@@ -1982,7 +1984,7 @@ func (cm *CostModel) costDataRange(cli prometheusClient.Client, clientset kubern
|
|
|
w += window
|
|
|
if w.Minutes() > 0 {
|
|
|
wStr := fmt.Sprintf("%dm", int(w.Minutes()))
|
|
|
- err = findDeletedNodeInfo(cli, missingNodes, wStr)
|
|
|
+ err = findDeletedNodeInfo(cli, missingNodes, wStr, offset)
|
|
|
if err != nil {
|
|
|
klog.V(1).Infof("Error fetching historical node data: %s", err.Error())
|
|
|
}
|