|
|
@@ -304,13 +304,14 @@ func (cm *CostModel) ComputeAllocation(start, end time.Time, resolution time.Dur
|
|
|
|
|
|
// TODO breakdown network costs?
|
|
|
|
|
|
+
|
|
|
// Build out a map of Nodes with resource costs, discounts, and node types
|
|
|
// for converting resource allocation data to cumulative costs.
|
|
|
nodeMap := map[nodeKey]*NodePricing{}
|
|
|
|
|
|
- applyNodeCostPerCPUHr(nodeMap, resNodeCostPerCPUHr)
|
|
|
- applyNodeCostPerRAMGiBHr(nodeMap, resNodeCostPerRAMGiBHr)
|
|
|
- applyNodeCostPerGPUHr(nodeMap, resNodeCostPerGPUHr)
|
|
|
+ applyNodeCostPerCPUHr(nodeMap, resNodeCostPerCPUHr, cm.Provider.ParseID)
|
|
|
+ applyNodeCostPerRAMGiBHr(nodeMap, resNodeCostPerRAMGiBHr, cm.Provider.ParseID)
|
|
|
+ applyNodeCostPerGPUHr(nodeMap, resNodeCostPerGPUHr, cm.Provider.ParseID)
|
|
|
applyNodeSpot(nodeMap, resNodeIsSpot)
|
|
|
applyNodeDiscount(nodeMap, cm)
|
|
|
|
|
|
@@ -1283,7 +1284,8 @@ func applyControllersToPods(podMap map[podKey]*Pod, podControllerMap map[podKey]
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func applyNodeCostPerCPUHr(nodeMap map[nodeKey]*NodePricing, resNodeCostPerCPUHr []*prom.QueryResult) {
|
|
|
+func applyNodeCostPerCPUHr(nodeMap map[nodeKey]*NodePricing, resNodeCostPerCPUHr []*prom.QueryResult,
|
|
|
+ providerIDParser func(string) string,) {
|
|
|
for _, res := range resNodeCostPerCPUHr {
|
|
|
cluster, err := res.GetString("cluster_id")
|
|
|
if err != nil {
|
|
|
@@ -1313,7 +1315,7 @@ func applyNodeCostPerCPUHr(nodeMap map[nodeKey]*NodePricing, resNodeCostPerCPUHr
|
|
|
nodeMap[key] = &NodePricing{
|
|
|
Name: node,
|
|
|
NodeType: instanceType,
|
|
|
- ProviderID: providerID,
|
|
|
+ ProviderID: providerIDParser(providerID),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1321,7 +1323,8 @@ func applyNodeCostPerCPUHr(nodeMap map[nodeKey]*NodePricing, resNodeCostPerCPUHr
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func applyNodeCostPerRAMGiBHr(nodeMap map[nodeKey]*NodePricing, resNodeCostPerRAMGiBHr []*prom.QueryResult) {
|
|
|
+func applyNodeCostPerRAMGiBHr(nodeMap map[nodeKey]*NodePricing, resNodeCostPerRAMGiBHr []*prom.QueryResult,
|
|
|
+ providerIDParser func(string) string,) {
|
|
|
for _, res := range resNodeCostPerRAMGiBHr {
|
|
|
cluster, err := res.GetString("cluster_id")
|
|
|
if err != nil {
|
|
|
@@ -1351,7 +1354,7 @@ func applyNodeCostPerRAMGiBHr(nodeMap map[nodeKey]*NodePricing, resNodeCostPerRA
|
|
|
nodeMap[key] = &NodePricing{
|
|
|
Name: node,
|
|
|
NodeType: instanceType,
|
|
|
- ProviderID: providerID,
|
|
|
+ ProviderID: providerIDParser(providerID),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1359,7 +1362,8 @@ func applyNodeCostPerRAMGiBHr(nodeMap map[nodeKey]*NodePricing, resNodeCostPerRA
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func applyNodeCostPerGPUHr(nodeMap map[nodeKey]*NodePricing, resNodeCostPerGPUHr []*prom.QueryResult) {
|
|
|
+func applyNodeCostPerGPUHr(nodeMap map[nodeKey]*NodePricing, resNodeCostPerGPUHr []*prom.QueryResult,
|
|
|
+ providerIDParser func(string) string,) {
|
|
|
for _, res := range resNodeCostPerGPUHr {
|
|
|
cluster, err := res.GetString("cluster_id")
|
|
|
if err != nil {
|
|
|
@@ -1389,7 +1393,7 @@ func applyNodeCostPerGPUHr(nodeMap map[nodeKey]*NodePricing, resNodeCostPerGPUHr
|
|
|
nodeMap[key] = &NodePricing{
|
|
|
Name: node,
|
|
|
NodeType: instanceType,
|
|
|
- ProviderID: providerID,
|
|
|
+ ProviderID: providerIDParser(providerID),
|
|
|
}
|
|
|
}
|
|
|
|