Jelajahi Sumber

fix missing bracket + add INGEST_POD_UID env logic

Kaelan Patel 4 tahun lalu
induk
melakukan
5f9f215a09
2 mengubah file dengan 14 tambahan dan 2 penghapusan
  1. 6 2
      pkg/costmodel/allocation.go
  2. 8 0
      pkg/env/costmodelenv.go

+ 6 - 2
pkg/costmodel/allocation.go

@@ -111,9 +111,13 @@ func (cm *CostModel) ComputeAllocation(start, end time.Time, resolution time.Dur
 	clusterStart := map[string]time.Time{}
 	clusterEnd := map[string]time.Time{}
 
-	ingestPodUID := true
+	ingestPodUID := env.IsIngestingPodUID()
 	podUIDKeyMap := make(map[podKey][]podKey)
 
+	if ingestPodUID {
+		log.Infof("CostModel.ComputeAllocation: ingesting UID data from KSM metrics...")
+	}
+
 	cm.buildPodMap(window, resolution, env.GetETLMaxBatchDuration(), podMap, clusterStart, clusterEnd, ingestPodUID, podUIDKeyMap)
 
 	// (2) Run and apply remaining queries
@@ -866,7 +870,7 @@ func applyCPUCoresRequested(podMap map[podKey]*Pod, resCPUCoresRequested []*prom
 			if pod.Allocations[container].CPUCores() > MAX_CPU_CAP {
 				log.Infof("[WARNING] Very large cpu allocation, clamping! to %f", res.Values[0].Value*(pod.Allocations[container].Minutes()/60.0))
 				pod.Allocations[container].CPUCoreHours = res.Values[0].Value * (pod.Allocations[container].Minutes() / 60.0)
-
+			}
 			node, err := res.GetString("node")
 			if err != nil {
 				log.Warningf("CostModel.ComputeAllocation: CPU request query result missing 'node': %s", key)

+ 8 - 0
pkg/env/costmodelenv.go

@@ -82,6 +82,8 @@ const (
 	PrometheusRetryOnRateLimitResponseEnvVar    = "PROMETHEUS_RETRY_ON_RATE_LIMIT"
 	PrometheusRetryOnRateLimitMaxRetriesEnvVar  = "PROMETHEUS_RETRY_ON_RATE_LIMIT_MAX_RETRIES"
 	PrometheusRetryOnRateLimitDefaultWaitEnvVar = "PROMETHEUS_RETRY_ON_RATE_LIMIT_DEFAULT_WAIT"
+
+	IngestPodUIDEnvVar = "INGEST_POD_UID"
 )
 
 // GetKubecostConfigBucket returns a file location for a mounted bucket configuration which is used to store
@@ -463,3 +465,9 @@ func LegacyExternalCostsAPIDisabled() bool {
 func GetPromClusterLabel() string {
 	return Get(PromClusterIDLabelEnvVar, "cluster_id")
 }
+
+// IsIngestingPodUID returns the env variable from ingestPodUID, which alters the
+// contents of podKeys in Allocation
+func IsIngestingPodUID() bool {
+	return GetBool(IngestPodUIDEnvVar, false)
+}