Преглед изворни кода

Migrate Agg API: fix nil dereferences

Niko Kovacevic пре 5 година
родитељ
комит
3570830afb
2 измењених фајлова са 7 додато и 3 уклоњено
  1. 2 0
      pkg/costmodel/aggregation.go
  2. 5 3
      pkg/costmodel/router.go

+ 2 - 0
pkg/costmodel/aggregation.go

@@ -1246,6 +1246,8 @@ func (a *Accesses) ComputeAggregateCostModel(promClient prometheusClient.Client,
 	// report message about which of the two caches hit. by default report a miss
 	// report message about which of the two caches hit. by default report a miss
 	cacheMessage := fmt.Sprintf("L1 cache miss: %s L2 cache miss: %s", aggKey, key)
 	cacheMessage := fmt.Sprintf("L1 cache miss: %s L2 cache miss: %s", aggKey, key)
 
 
+	log.Infof("Open Source Accesses: AggregateCache=%v", a.AggregateCache)
+
 	// check the cache for aggregated response; if cache is hit and not disabled, return response
 	// check the cache for aggregated response; if cache is hit and not disabled, return response
 	if value, found := a.AggregateCache.Get(aggKey); found && !disableCache && !noCache {
 	if value, found := a.AggregateCache.Get(aggKey); found && !disableCache && !noCache {
 		result, ok := value.(map[string]*Aggregation)
 		result, ok := value.(map[string]*Aggregation)

+ 5 - 3
pkg/costmodel/router.go

@@ -970,6 +970,7 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) *Accesses {
 	aggregateCache := cache.New(time.Minute*10, time.Minute*20)
 	aggregateCache := cache.New(time.Minute*10, time.Minute*20)
 	costDataCache := cache.New(time.Minute*10, time.Minute*20)
 	costDataCache := cache.New(time.Minute*10, time.Minute*20)
 	clusterCostsCache := cache.New(cache.NoExpiration, cache.NoExpiration)
 	clusterCostsCache := cache.New(cache.NoExpiration, cache.NoExpiration)
+	outOfClusterCache := cache.New(time.Minute*5, time.Minute*10)
 	settingsCache := cache.New(cache.NoExpiration, cache.NoExpiration)
 	settingsCache := cache.New(cache.NoExpiration, cache.NoExpiration)
 
 
 	// query durations that should be cached longer should be registered here
 	// query durations that should be cached longer should be registered here
@@ -985,7 +986,7 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) *Accesses {
 	costModel := NewCostModel(k8sCache, clusterMap, scrapeInterval)
 	costModel := NewCostModel(k8sCache, clusterMap, scrapeInterval)
 	metricsEmitter := NewCostModelMetricsEmitter(promCli, k8sCache, cloudProvider, costModel)
 	metricsEmitter := NewCostModelMetricsEmitter(promCli, k8sCache, cloudProvider, costModel)
 
 
-	a := Accesses{
+	a := &Accesses{
 		Router:            httprouter.New(),
 		Router:            httprouter.New(),
 		PrometheusClient:  promCli,
 		PrometheusClient:  promCli,
 		ThanosClient:      thanosClient,
 		ThanosClient:      thanosClient,
@@ -998,6 +999,7 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) *Accesses {
 		AggregateCache:    aggregateCache,
 		AggregateCache:    aggregateCache,
 		CostDataCache:     costDataCache,
 		CostDataCache:     costDataCache,
 		ClusterCostsCache: clusterCostsCache,
 		ClusterCostsCache: clusterCostsCache,
+		OutOfClusterCache: outOfClusterCache,
 		SettingsCache:     settingsCache,
 		SettingsCache:     settingsCache,
 		CacheExpiration:   cacheExpiration,
 		CacheExpiration:   cacheExpiration,
 	}
 	}
@@ -1005,7 +1007,7 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) *Accesses {
 	// confusing and unconventional, but necessary so that we can swap it
 	// confusing and unconventional, but necessary so that we can swap it
 	// out for the ETL-adapted version elsewhere.
 	// out for the ETL-adapted version elsewhere.
 	// TODO clean this up once ETL is open-sourced.
 	// TODO clean this up once ETL is open-sourced.
-	a.AggAPI = &a
+	a.AggAPI = a
 
 
 	// Initialize mechanism for subscribing to settings changes
 	// Initialize mechanism for subscribing to settings changes
 	a.InitializeSettingsPubSub()
 	a.InitializeSettingsPubSub()
@@ -1048,5 +1050,5 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) *Accesses {
 	a.Router.PUT("/clusters", managerEndpoints.PutCluster)
 	a.Router.PUT("/clusters", managerEndpoints.PutCluster)
 	a.Router.DELETE("/clusters/:id", managerEndpoints.DeleteCluster)
 	a.Router.DELETE("/clusters/:id", managerEndpoints.DeleteCluster)
 
 
-	return &a
+	return a
 }
 }