Explorar o código

change value names

Signed-off-by: Sean Holcomb <seanholcomb@gmail.com>
Sean Holcomb hai 23 horas
pai
achega
04454a0062

+ 2 - 2
core/pkg/compute/kubemodel/container.go

@@ -92,7 +92,7 @@ func (km *KubeModel) computeContainers(kms *kubemodel.KubeModelSet, start, end t
 			continue
 		}
 		if len(res.Data) > 0 {
-			container.CPUCoresAllocated = res.Data[0].Value
+			container.CPUCoreAllocationAvg = res.Data[0].Value
 		}
 	}
 
@@ -105,7 +105,7 @@ func (km *KubeModel) computeContainers(kms *kubemodel.KubeModelSet, start, end t
 			continue
 		}
 		if len(res.Data) > 0 {
-			container.RAMBytesAllocated = res.Data[0].Value
+			container.RAMBytesAllocationAvg = res.Data[0].Value
 		}
 	}
 

+ 13 - 13
core/pkg/compute/kubemodel/container_test.go

@@ -146,18 +146,18 @@ func TestComputeContainers(t *testing.T) {
 			},
 			want: map[string]*kubemodel.Container{
 				"pod-1/main": {
-					PodUID:            "pod-1",
-					Name:              "main",
-					Start:             start,
-					End:               end,
-					ResourceRequests:  kubemodel.ResourceQuantities{},
-					ResourceLimits:    kubemodel.ResourceQuantities{},
-					CPUCoresAllocated: 0.25,
-					RAMBytesAllocated: 256 * 1024 * 1024,
-					CPUCoreUsageAvg:   0.1,
-					CPUCoreUsageMax:   0.2,
-					RAMBytesUsageAvg:  128 * 1024 * 1024,
-					RAMBytesUsageMax:  200 * 1024 * 1024,
+					PodUID:                "pod-1",
+					Name:                  "main",
+					Start:                 start,
+					End:                   end,
+					ResourceRequests:      kubemodel.ResourceQuantities{},
+					ResourceLimits:        kubemodel.ResourceQuantities{},
+					CPUCoreAllocationAvg:  0.25,
+					RAMBytesAllocationAvg: 256 * 1024 * 1024,
+					CPUCoreUsageAvg:       0.1,
+					CPUCoreUsageMax:       0.2,
+					RAMBytesUsageAvg:      128 * 1024 * 1024,
+					RAMBytesUsageMax:      200 * 1024 * 1024,
 				},
 			},
 		},
@@ -202,4 +202,4 @@ func TestComputeContainers(t *testing.T) {
 			assert.Equal(t, tt.want, kms.Containers)
 		})
 	}
-}
+}

+ 4 - 4
core/pkg/model/kubemodel/kubemodel_codecs.go

@@ -1207,13 +1207,13 @@ func (target *Container) MarshalBinaryWithContext(ctx *EncodingContext) (err err
 	}
 	// --- [end][write][alias](ResourceQuantities) ---
 
-	buff.WriteFloat64(target.CPUCoresAllocated) // write float64
+	buff.WriteFloat64(target.CPUCoreAllocationAvg) // write float64
 
 	buff.WriteFloat64(target.CPUCoreUsageAvg) // write float64
 
 	buff.WriteFloat64(target.CPUCoreUsageMax) // write float64
 
-	buff.WriteFloat64(target.RAMBytesAllocated) // write float64
+	buff.WriteFloat64(target.RAMBytesAllocationAvg) // write float64
 
 	buff.WriteFloat64(target.RAMBytesUsageAvg) // write float64
 
@@ -1400,7 +1400,7 @@ func (target *Container) UnmarshalBinaryWithContext(ctx *DecodingContext) (err e
 	// --- [end][read][alias](ResourceQuantities) ---
 
 	bb := buff.ReadFloat64() // read float64
-	target.CPUCoresAllocated = bb
+	target.CPUCoreAllocationAvg = bb
 
 	cc := buff.ReadFloat64() // read float64
 	target.CPUCoreUsageAvg = cc
@@ -1409,7 +1409,7 @@ func (target *Container) UnmarshalBinaryWithContext(ctx *DecodingContext) (err e
 	target.CPUCoreUsageMax = dd
 
 	ee := buff.ReadFloat64() // read float64
-	target.RAMBytesAllocated = ee
+	target.RAMBytesAllocationAvg = ee
 
 	ff := buff.ReadFloat64() // read float64
 	target.RAMBytesUsageAvg = ff

+ 8 - 8
core/pkg/model/kubemodel/mock.go

@@ -121,14 +121,14 @@ func NewMockKubeModelSet(start, end time.Time) *KubeModelSet {
 			ResourceCPU:    {Resource: ResourceCPU, Unit: UnitMillicore, Values: Stats{StatAvg: 500, StatMax: 500}},
 			ResourceMemory: {Resource: ResourceMemory, Unit: UnitByte, Values: Stats{StatAvg: 1e9, StatMax: 1e9}},
 		},
-		CPUCoresAllocated: 0.25,
-		CPUCoreUsageAvg:   0.18,
-		CPUCoreUsageMax:   0.42,
-		RAMBytesAllocated: 512e6,
-		RAMBytesUsageAvg:  300e6,
-		RAMBytesUsageMax:  480e6,
-		Start:             start,
-		End:               end,
+		CPUCoreAllocationAvg:  0.25,
+		CPUCoreUsageAvg:       0.18,
+		CPUCoreUsageMax:       0.42,
+		RAMBytesAllocationAvg: 512e6,
+		RAMBytesUsageAvg:      300e6,
+		RAMBytesUsageMax:      480e6,
+		Start:                 start,
+		End:                   end,
 	})
 
 	// --- Deployment ---

+ 1 - 1
modules/collector-source/pkg/metric/collector.go

@@ -64,7 +64,7 @@ const (
 	RAMLimitsID                                MetricCollectorID = "RAMLimits"
 	RAMUsageAverageID                          MetricCollectorID = "RAMUsageAverage"
 	RAMUsageMaxID                              MetricCollectorID = "RAMBytesUsageMax"
-	CPUCoresAllocatedID                        MetricCollectorID = "CPUCoresAllocated"
+	CPUCoresAllocatedID                        MetricCollectorID = "CPUCoreAllocationAvg"
 	CPURequestsID                              MetricCollectorID = "CPURequestsID"
 	CPULimitsID                                MetricCollectorID = "CPULimitsID"
 	CPUUsageAverageID                          MetricCollectorID = "CPUUsageAverage"

+ 11 - 7
pkg/costmodel/router.go

@@ -531,15 +531,19 @@ func Initialize(router *httprouter.Router, additionalConfigWatchers ...*watcher.
 	costModel := NewCostModel(clusterUID, dataSource, cloudProvider, k8sCache, clusterMap, dataSource.BatchDuration())
 	metricsEmitter := NewCostModelMetricsEmitter(k8sCache, cloudProvider, clusterInfoProvider, costModel)
 
-	appName := sysenv.GetAppName()
 	var kubeModelPipeline *km.Pipeline
-	if p, err := km.NewPipeline(appName, clusterUID, store, costModel); err != nil {
-		log.Errorf("Failed to initialize KubeModel pipeline: %v", err)
-	} else {
-		p.Start()
-		kubeModelPipeline = p
+	var kubeModelQuerier km.Querier
+	if sysenv.GetExportKubeModel() {
+		appName := sysenv.GetAppName()
+
+		if p, err := km.NewPipeline(appName, clusterUID, store, costModel); err != nil {
+			log.Errorf("Failed to initialize KubeModel pipeline: %v", err)
+		} else {
+			p.Start()
+			kubeModelPipeline = p
+		}
+		kubeModelQuerier = km.NewQuerier(appName, clusterUID, store)
 	}
-	kubeModelQuerier := km.NewQuerier(appName, clusterUID, store)
 
 	a := &Accesses{
 		DataSource:          dataSource,