Przeglądaj źródła

code review fixes

Signed-off-by: Alex Meijer <ameijer@kubecost.com>
Alex Meijer 2 lat temu
rodzic
commit
8ef0155ee9

+ 4 - 2
pkg/customcost/pipelineservice.go

@@ -21,6 +21,8 @@ import (
 
 var protocol = proto.HTTP()
 
+const execFmt = `%s/%s.ocplugin.%s.%s`
+
 // PipelineService exposes CloudCost pipeline controls and diagnostics endpoints
 type PipelineService struct {
 	hourlyIngestor, dailyIngestor *CustomCostIngestor
@@ -57,7 +59,7 @@ func getRegisteredPlugins(configDir string, execDir string) (map[string]*plugin.
 	configs := map[string]*plugin.ClientConfig{}
 	// set up the client config
 	for name, config := range pluginNames {
-		if _, err := os.Stat(execDir + "/" + name + ".ocplugin." + runtime.GOOS + "." + version.Architecture); err != nil {
+		if _, err := os.Stat(fmt.Sprintf(execFmt, execDir, name, runtime.GOOS, version.Architecture)); err != nil {
 			msg := fmt.Sprintf("error reading executable for %s plugin. Plugin executables must be in %s and have name format <plugin name>.ocplugin.<opencost binary archtecture (arm64 or amd64)>", name, execDir)
 			log.Errorf(msg)
 			return nil, fmt.Errorf(msg)
@@ -82,7 +84,7 @@ func getRegisteredPlugins(configDir string, execDir string) (map[string]*plugin.
 		configs[name] = &plugin.ClientConfig{
 			HandshakeConfig: handshakeConfig,
 			Plugins:         pluginMap,
-			Cmd:             exec.Command(execDir+"/"+name+".ocplugin."+runtime.GOOS+"."+version.Architecture, config),
+			Cmd:             exec.Command(fmt.Sprintf(execFmt, execDir, name, runtime.GOOS, version.Architecture), config),
 			Logger:          logger,
 		}
 	}

+ 4 - 7
pkg/customcost/pipelineservice_test.go

@@ -16,13 +16,10 @@ import (
 
 func TestPipelineService(t *testing.T) {
 	// establish temporary test assets dir
-	dir, err := os.MkdirTemp("", "ocplugin-*")
-	if err != nil {
-		t.Fatalf("error creating temp dir: %v", err)
-	}
-	defer os.Remove(dir)
 
-	err = os.MkdirAll(dir+"/config", 0777)
+	dir := t.TempDir()
+
+	err := os.MkdirAll(dir+"/config", 0777)
 	if err != nil {
 		t.Fatalf("error creating temp config dir: %v", err)
 	}
@@ -117,7 +114,7 @@ func TestPipelineService(t *testing.T) {
 	}
 
 	// query data from 4 hours ago (hourly)
-	targetTime = time.Now().UTC().Add(-12 * time.Hour).Truncate(time.Hour)
+	targetTime = time.Now().UTC().Add(-13 * time.Hour).Truncate(time.Hour)
 	log.Infof("querying for data with window start: %v", targetTime)
 	// check for presence of hosts in DD response
 	ddCosts, err = hourlyRepo.Get(targetTime, "datadog")