Bläddra i källkod

Move `gpuRequestAverage` and `gpuUsageAverage` to bottom of struct in
accordance with documentation here
https://github.com/opencost/opencost/blob/develop/core/pkg/opencost/bingen.go.
Rerun `go generate`.

Signed-off-by: thomasvn <thomasnguyen96@gmail.com>

thomasvn 2 år sedan
förälder
incheckning
2c658ddefb
2 ändrade filer med 23 tillägg och 11 borttagningar
  1. 3 3
      core/pkg/opencost/allocation.go
  2. 20 8
      core/pkg/opencost/opencost_codecs.go

+ 3 - 3
core/pkg/opencost/allocation.go

@@ -64,8 +64,6 @@ type Allocation struct {
 	CPUCost                    float64               `json:"cpuCost"`
 	CPUCostAdjustment          float64               `json:"cpuCostAdjustment"`
 	GPUHours                   float64               `json:"gpuHours"`
-	GPURequestAverage          float64               `json:"gpuRequestAverage"`
-	GPUUsageAverage            float64               `json:"gpuUsageAverage"`
 	GPUCost                    float64               `json:"gpuCost"`
 	GPUCostAdjustment          float64               `json:"gpuCostAdjustment"`
 	NetworkTransferBytes       float64               `json:"networkTransferBytes"`
@@ -99,7 +97,9 @@ type Allocation struct {
 	// UnmountedPVCost is used to track how much of the cost in PVs is for an
 	// unmounted PV. It is not additive of PVCost() and need not be sent in API
 	// responses.
-	UnmountedPVCost float64 `json:"-"` //@bingen:field[ignore]
+	UnmountedPVCost   float64 `json:"-"`                 //@bingen:field[ignore]
+	GPURequestAverage float64 `json:"gpuRequestAverage"` //@bingen:field[version=22]
+	GPUUsageAverage   float64 `json:"gpuUsageAverage"`   //@bingen:field[version=22]
 }
 
 type LbAllocations map[string]*LbAllocation

+ 20 - 8
core/pkg/opencost/opencost_codecs.go

@@ -352,8 +352,6 @@ func (target *Allocation) MarshalBinaryWithContext(ctx *EncodingContext) (err er
 	buff.WriteFloat64(target.CPUCost)                    // write float64
 	buff.WriteFloat64(target.CPUCostAdjustment)          // write float64
 	buff.WriteFloat64(target.GPUHours)                   // write float64
-	buff.WriteFloat64(target.GPURequestAverage)          // write float64
-	buff.WriteFloat64(target.GPUUsageAverage)            // write float64
 	buff.WriteFloat64(target.GPUCost)                    // write float64
 	buff.WriteFloat64(target.GPUCostAdjustment)          // write float64
 	buff.WriteFloat64(target.NetworkTransferBytes)       // write float64
@@ -459,6 +457,8 @@ func (target *Allocation) MarshalBinaryWithContext(ctx *EncodingContext) (err er
 	}
 	// --- [end][write][alias](LbAllocations) ---
 
+	buff.WriteFloat64(target.GPURequestAverage) // write float64
+	buff.WriteFloat64(target.GPUUsageAverage)   // write float64
 	return nil
 }
 
@@ -590,12 +590,6 @@ func (target *Allocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err
 	s := buff.ReadFloat64() // read float64
 	target.GPUHours = s
 
-	s1 := buff.ReadFloat64() // read float64
-	target.GPURequestAverage = s1
-
-	s2 := buff.ReadFloat64() // read float64
-	target.GPUUsageAverage = s2
-
 	t := buff.ReadFloat64() // read float64
 	target.GPUCost = t
 
@@ -777,6 +771,24 @@ func (target *Allocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err
 	} else {
 	}
 
+	// field version check
+	if uint8(22) <= version {
+		fff := buff.ReadFloat64() // read float64
+		target.GPURequestAverage = fff
+
+	} else {
+		target.GPURequestAverage = float64(0) // default
+	}
+
+	// field version check
+	if uint8(22) <= version {
+		ggg := buff.ReadFloat64() // read float64
+		target.GPUUsageAverage = ggg
+
+	} else {
+		target.GPUUsageAverage = float64(0) // default
+	}
+
 	return nil
 }