Ver código fonte

PR fixes

Signed-off-by: Alex Meijer <ameijer@kubecost.com>
Alex Meijer 2 anos atrás
pai
commit
d1480d3556

+ 4 - 2
pkg/costmodel/router.go

@@ -1846,8 +1846,10 @@ func Initialize(additionalConfigWatchers ...*watcher.ConfigMapWatcher) *Accesses
 	a.Router.GET("/cloud/config/disable", a.CloudConfigController.GetDisableConfigHandler())
 	a.Router.GET("/cloud/config/delete", a.CloudConfigController.GetDeleteConfigHandler())
 
-	a.Router.GET("/customCost/total", a.CustomCostQueryService.GetCustomCostTotalHandler())
-	a.Router.GET("/customCost/timeseries", a.CustomCostQueryService.GetCustomCostTimeseriesHandler())
+	if env.IsCustomCostEnabled() {
+		a.Router.GET("/customCost/total", a.CustomCostQueryService.GetCustomCostTotalHandler())
+		a.Router.GET("/customCost/timeseries", a.CustomCostQueryService.GetCustomCostTimeseriesHandler())
+	}
 
 	a.httpServices.RegisterAll(a.Router)
 

+ 7 - 9
pkg/customcost/ingestor.go

@@ -42,13 +42,12 @@ type CustomCostIngestorConfig struct {
 // DefaultIngestorConfiguration retrieves an CustomCostIngestorConfig from env variables
 func DefaultIngestorConfiguration() CustomCostIngestorConfig {
 	return CustomCostIngestorConfig{
-		DailyDuration:          timeutil.Day * time.Duration(env.GetDataRetentionDailyResolutionDays()),
-		HourlyDuration:         time.Hour * time.Duration(env.GetDataRetentionHourlyResolutionHours()),
-		MonthToDateRunInterval: env.GetCloudCostMonthToDateInterval(),
-		DailyQueryWindow:       timeutil.Day * time.Duration(env.GetCustomCostQueryWindowDays()),
-		HourlyQueryWindow:      time.Hour * time.Duration(env.GetCustomCostQueryWindowHours()),
-		PluginConfigDir:        env.GetPluginConfigDir(),
-		PluginExecutableDir:    env.GetPluginExecutableDir(),
+		DailyDuration:       timeutil.Day * time.Duration(env.GetDataRetentionDailyResolutionDays()),
+		HourlyDuration:      time.Hour * time.Duration(env.GetDataRetentionHourlyResolutionHours()),
+		DailyQueryWindow:    timeutil.Day * time.Duration(env.GetCustomCostQueryWindowDays()),
+		HourlyQueryWindow:   time.Hour * time.Duration(env.GetCustomCostQueryWindowHours()),
+		PluginConfigDir:     env.GetPluginConfigDir(),
+		PluginExecutableDir: env.GetPluginExecutableDir(),
 	}
 }
 
@@ -179,7 +178,6 @@ func (ing *CustomCostIngestor) buildSingleDomain(start, end time.Time, domain st
 		return
 	}
 
-	// TODO HAVE PLUG IN RETURN DATA AS PROTOBUF
 	// Request the plugin
 	raw, err := rpcClient.Dispense("CustomCostSource")
 	if err != nil {
@@ -236,7 +234,7 @@ func (ing *CustomCostIngestor) Start(rebuild bool) {
 func (ing *CustomCostIngestor) Stop() {
 	// If already stopping, log that and return.
 	if !ing.isStopping.CompareAndSwap(false, true) {
-		log.Infof("CloudCost: ingestor: is already stopping")
+		log.Infof("CustomCost: ingestor: is already stopping")
 		return
 	}
 

+ 2 - 2
pkg/customcost/memoryrepository.go

@@ -42,12 +42,12 @@ func (m *MemoryRepository) Get(startTime time.Time, domain string) (*pb.CustomCo
 
 	domainData, ok := m.data[domain]
 	if !ok {
-		return nil, nil
+		return &pb.CustomCostResponse{}, nil
 	}
 
 	b, ook := domainData[startTime.UTC()]
 	if !ook {
-		return nil, nil
+		return &pb.CustomCostResponse{}, nil
 	}
 
 	ccr := &pb.CustomCostResponse{}

+ 1 - 1
pkg/customcost/pipelineservice.go

@@ -22,7 +22,7 @@ var protocol = proto.HTTP()
 
 const execFmt = `%s/%s.ocplugin.%s.%s`
 
-// PipelineService exposes CloudCost pipeline controls and diagnostics endpoints
+// PipelineService exposes CustomCost pipeline controls and diagnostics endpoints
 type PipelineService struct {
 	hourlyIngestor, dailyIngestor *CustomCostIngestor
 	hourlyStore, dailyStore       Repository

+ 1 - 1
pkg/customcost/repository.go

@@ -6,7 +6,7 @@ import (
 	"github.com/opencost/opencost/core/pkg/model/pb"
 )
 
-// Repository is an interface for storing and retrieving CloudCost data
+// Repository is an interface for storing and retrieving CustomCost data
 type Repository interface {
 	Has(time.Time, string) (bool, error)
 	Get(time.Time, string) (*pb.CustomCostResponse, error)

+ 1 - 3
pkg/customcost/status.go

@@ -4,10 +4,9 @@ import (
 	"time"
 
 	"github.com/opencost/opencost/core/pkg/opencost"
-	cloudconfig "github.com/opencost/opencost/pkg/cloud"
 )
 
-// Status gives the details and metadata of a CloudCost integration
+// Status gives the details and metadata of a CustomCost integration
 type Status struct {
 	Key               string                     `json:"key"`
 	Source            string                     `json:"source"`
@@ -23,5 +22,4 @@ type Status struct {
 	CoverageHourly    map[string]opencost.Window `json:"coverageHourly"`
 	CoverageDaily     map[string]opencost.Window `json:"coverageDaily"`
 	ConnectionStatus  string                     `json:"connectionStatus"`
-	Config            cloudconfig.Config         `json:"config"`
 }