Pārlūkot izejas kodu

Updates to semver version and incubating allocation

Matt Bolt 1 gadu atpakaļ
vecāks
revīzija
a4a46fff1c

+ 1 - 1
modules/prometheus-source/go.mod

@@ -8,7 +8,7 @@ replace (
 )
 
 require (
-	github.com/Masterminds/semver v1.5.0
+	github.com/Masterminds/semver/v3 v3.3.1
 	github.com/julienschmidt/httprouter v1.3.0
 	github.com/opencost/opencost/core v0.0.0-20241211165149-ee44b80e2fd0
 	github.com/prometheus/client_golang v1.20.5

+ 2 - 2
modules/prometheus-source/go.sum

@@ -39,8 +39,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
-github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
-github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
+github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
+github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
 github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
 github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
 github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=

+ 1 - 1
modules/prometheus-source/pkg/prom/datasource.go

@@ -7,7 +7,7 @@ import (
 	"strconv"
 	"time"
 
-	"github.com/Masterminds/semver"
+	"github.com/Masterminds/semver/v3"
 	"github.com/julienschmidt/httprouter"
 	"github.com/opencost/opencost/modules/prometheus-source/pkg/env"
 

+ 30 - 30
pkg/costmodel/allocation_incubating.go

@@ -31,7 +31,7 @@ func (cm *CostModel) ComputeAllocationWithNodeTotals(start, end time.Time, resol
 	nodeMap := make(map[string]*NodeTotals)
 
 	// If the duration is short enough, compute the AllocationSet directly
-	if end.Sub(start) <= cm.MaxPrometheusQueryDuration {
+	if end.Sub(start) <= cm.BatchDuration {
 		as, nodeData, err := cm.computeAllocation(start, end, resolution)
 		appendNodeData(nodeMap, start, end, nodeData)
 
@@ -54,8 +54,8 @@ func (cm *CostModel) ComputeAllocationWithNodeTotals(start, end time.Time, resol
 		// any individual query duration exceed the configured max Prometheus
 		// query duration.
 		duration := end.Sub(e)
-		if duration > cm.MaxPrometheusQueryDuration {
-			duration = cm.MaxPrometheusQueryDuration
+		if duration > cm.BatchDuration {
+			duration = cm.BatchDuration
 		}
 
 		// Set start and end parameters (s, e) for next individual computation.
@@ -237,17 +237,17 @@ func appendNodeData(nodeMap map[string]*NodeTotals, s, e time.Time, nodeData map
 // feature for extending the node details that can be returned with allocation
 // data
 type extendedNodeQueryResults struct {
-	nodeCPUCoreResults  []*source.QueryResult
-	nodeRAMByteResults  []*source.QueryResult
-	nodeGPUCountResults []*source.QueryResult
+	nodeCPUCoreResults  []*source.NodeCPUCoresCapacityResult
+	nodeRAMByteResults  []*source.NodeRAMBytesCapacityResult
+	nodeGPUCountResults []*source.NodeGPUCountResult
 }
 
 // queryExtendedNodeData makes additional prometheus queries for node data to append on
 // the AllocationNodePricing struct.
 func queryExtendedNodeData(grp *source.QueryGroup, ds source.MetricsQuerier, start, end time.Time) (*extendedNodeQueryResults, error) {
-	resChQueryNodeCPUCores := grp.With(ds.QueryNodeCPUCoresCapacity(start, end))
-	resChQueryNodeRAMBytes := grp.With(ds.QueryNodeRAMBytesCapacity(start, end))
-	resChQueryNodeGPUCount := grp.With(ds.QueryNodeGPUCount(start, end))
+	resChQueryNodeCPUCores := source.WithGroup(grp, ds.QueryNodeCPUCoresCapacity(start, end))
+	resChQueryNodeRAMBytes := source.WithGroup(grp, ds.QueryNodeRAMBytesCapacity(start, end))
+	resChQueryNodeGPUCount := source.WithGroup(grp, ds.QueryNodeGPUCount(start, end))
 
 	nodeCPUCoreResults, _ := resChQueryNodeCPUCores.Await()
 	nodeRAMByteResults, _ := resChQueryNodeRAMBytes.Await()
@@ -273,16 +273,16 @@ func applyExtendedNodeData(nodeMap map[nodeKey]*nodePricing, results *extendedNo
 	applyNodeGPUCount(nodeMap, results.nodeGPUCountResults)
 }
 
-func applyNodeCPUCores(nodeMap map[nodeKey]*nodePricing, nodeCPUCoreResults []*source.QueryResult) {
+func applyNodeCPUCores(nodeMap map[nodeKey]*nodePricing, nodeCPUCoreResults []*source.NodeCPUCoresCapacityResult) {
 	for _, res := range nodeCPUCoreResults {
-		cluster, err := res.GetCluster()
-		if err != nil {
+		cluster := res.Cluster
+		if cluster == "" {
 			cluster = env.GetClusterID()
 		}
 
-		node, err := res.GetNode()
-		if err != nil {
-			log.Warnf("CostModel.ComputeAllocation: Node CPU Cores query result missing field: %s", err)
+		node := res.Node
+		if node == "" {
+			log.Warnf("CostModel.ComputeAllocation: Node CPU Cores query result missing node field")
 			continue
 		}
 
@@ -294,20 +294,20 @@ func applyNodeCPUCores(nodeMap map[nodeKey]*nodePricing, nodeCPUCoreResults []*s
 			}
 		}
 
-		nodeMap[key].CPUCores = res.Values[0].Value
+		nodeMap[key].CPUCores = res.Data[0].Value
 	}
 }
 
-func applyNodeRAMBytes(nodeMap map[nodeKey]*nodePricing, nodeRAMByteResults []*source.QueryResult) {
+func applyNodeRAMBytes(nodeMap map[nodeKey]*nodePricing, nodeRAMByteResults []*source.NodeRAMBytesCapacityResult) {
 	for _, res := range nodeRAMByteResults {
-		cluster, err := res.GetCluster()
-		if err != nil {
+		cluster := res.Cluster
+		if cluster == "" {
 			cluster = env.GetClusterID()
 		}
 
-		node, err := res.GetNode()
-		if err != nil {
-			log.Warnf("CostModel.ComputeAllocation: Node CPU Cores query result missing field: %s", err)
+		node := res.Node
+		if node == "" {
+			log.Warnf("CostModel.ComputeAllocation: Node CPU Cores query result missing node field")
 			continue
 		}
 
@@ -319,20 +319,20 @@ func applyNodeRAMBytes(nodeMap map[nodeKey]*nodePricing, nodeRAMByteResults []*s
 			}
 		}
 
-		nodeMap[key].RAMGiB = res.Values[0].Value / 1024.0 / 1024.0 / 1024.0
+		nodeMap[key].RAMGiB = res.Data[0].Value / 1024.0 / 1024.0 / 1024.0
 	}
 }
 
-func applyNodeGPUCount(nodeMap map[nodeKey]*nodePricing, nodeGPUCountResults []*source.QueryResult) {
+func applyNodeGPUCount(nodeMap map[nodeKey]*nodePricing, nodeGPUCountResults []*source.NodeGPUCountResult) {
 	for _, res := range nodeGPUCountResults {
-		cluster, err := res.GetCluster()
-		if err != nil {
+		cluster := res.Cluster
+		if cluster == "" {
 			cluster = env.GetClusterID()
 		}
 
-		node, err := res.GetNode()
-		if err != nil {
-			log.Warnf("CostModel.ComputeAllocation: Node CPU Cores query result missing field: %s", err)
+		node := res.Node
+		if node == "" {
+			log.Warnf("CostModel.ComputeAllocation: Node CPU Cores query result missing node field")
 			continue
 		}
 
@@ -344,7 +344,7 @@ func applyNodeGPUCount(nodeMap map[nodeKey]*nodePricing, nodeGPUCountResults []*
 			}
 		}
 
-		nodeMap[key].GPUCount = res.Values[0].Value
+		nodeMap[key].GPUCount = res.Data[0].Value
 	}
 }