Bläddra i källkod

Fixed logging format errors and leftover merge conflicts.

Matt Bolt 1 år sedan
förälder
incheckning
d7da8ed0e3

+ 1 - 1
pkg/cloudcost/ingestor.go

@@ -249,7 +249,7 @@ func (ing *ingestor) build(rebuild bool) {
 		e = e.Add(-ing.config.QueryWindow)
 	}
 
-	log.Infof(fmt.Sprintf("CloudCost[%s]: ingestor: build[%s]: completed in %v", ing.key, ing.runID, time.Since(buildStart)))
+	log.Infof("CloudCost[%s]: ingestor: build[%s]: completed in %v", ing.key, ing.runID, time.Since(buildStart))
 
 	// In order to be able to Stop, we have to wait on an exit message
 	// here

+ 26 - 26
pkg/costmodel/allocation_helpers_test.go

@@ -8,7 +8,6 @@ import (
 	"github.com/opencost/opencost/core/pkg/opencost"
 	"github.com/opencost/opencost/core/pkg/source"
 	"github.com/opencost/opencost/core/pkg/util"
-	"github.com/opencost/opencost/pkg/prom"
 )
 
 const Ki = 1024
@@ -212,9 +211,6 @@ func TestBuildPVMap(t *testing.T) {
 		pvMap1NoBytes[thisPVKey] = clonePV
 	}
 
-	// These test cases are mocking behavior from Prometheus v3+
-	prometheusVersion = "3.0.0"
-
 	testCases := map[string]struct {
 		resolution              time.Duration
 		resultsPVCostPerGiBHour []*source.QueryResult
@@ -280,6 +276,9 @@ func TestBuildPVMap(t *testing.T) {
 						"persistentvolume": "pv1",
 					},
 					[]*util.Vector{
+						{
+							Timestamp: startFloat,
+						},
 						{
 							Timestamp: startFloat + (hour * 6),
 						},
@@ -298,6 +297,9 @@ func TestBuildPVMap(t *testing.T) {
 						"persistentvolume": "pv2",
 					},
 					[]*util.Vector{
+						{
+							Timestamp: startFloat,
+						},
 						{
 							Timestamp: startFloat + (hour * 6),
 						},
@@ -319,6 +321,9 @@ func TestBuildPVMap(t *testing.T) {
 						"persistentvolume": "pv3",
 					},
 					[]*util.Vector{
+						{
+							Timestamp: startFloat + (hour * 6),
+						},
 						{
 							Timestamp: startFloat + (hour * 12),
 						},
@@ -334,6 +339,9 @@ func TestBuildPVMap(t *testing.T) {
 						"persistentvolume": "pv4",
 					},
 					[]*util.Vector{
+						{
+							Timestamp: startFloat,
+						},
 						{
 							Timestamp: startFloat + (hour * 6),
 						},
@@ -457,9 +465,6 @@ func TestGetUnmountedPodForCluster(t *testing.T) {
 }
 
 func TestCalculateStartAndEnd(t *testing.T) {
-	// These test cases are mocking behavior from Prometheus v3+
-	prometheusVersion = "3.0.0"
-
 	testCases := map[string]struct {
 		resolution    time.Duration   // User defined config when querying Prometheus
 		window        opencost.Window // User defined config when querying Allocations/Assets
@@ -475,6 +480,9 @@ func TestCalculateStartAndEnd(t *testing.T) {
 			expectedEnd:   windowStart.Add(time.Hour),
 			result: &source.QueryResult{
 				Values: []*util.Vector{
+					{
+						Timestamp: startFloat,
+					},
 					{
 						Timestamp: startFloat + (minute * 60),
 					},
@@ -489,6 +497,9 @@ func TestCalculateStartAndEnd(t *testing.T) {
 			expectedEnd:   windowStart.Add(time.Hour),
 			result: &source.QueryResult{
 				Values: []*util.Vector{
+					{
+						Timestamp: startFloat,
+					},
 					{
 						Timestamp: startFloat + (minute * 30),
 					},
@@ -506,6 +517,9 @@ func TestCalculateStartAndEnd(t *testing.T) {
 			expectedEnd:   windowStart.Add(time.Minute * 45),
 			result: &source.QueryResult{
 				Values: []*util.Vector{
+					{
+						Timestamp: startFloat + (minute * 0),
+					},
 					{
 						Timestamp: startFloat + (minute * 15),
 					},
@@ -525,6 +539,9 @@ func TestCalculateStartAndEnd(t *testing.T) {
 			expectedEnd:   windowStart.Add(time.Minute * 20),
 			result: &source.QueryResult{
 				Values: []*util.Vector{
+					{
+						Timestamp: startFloat + (minute * 15),
+					},
 					{
 						Timestamp: startFloat + (minute * 16),
 					},
@@ -543,23 +560,6 @@ func TestCalculateStartAndEnd(t *testing.T) {
 				},
 			},
 		},
-		// Example: avg(node_total_hourly_cost{}) by (node, provider_id)[5m:1m]
-		"1 minute resolution, 5 minute window, partial data": {
-			resolution:    time.Minute,
-			window:        opencost.NewClosedWindow(windowStart.Add(time.Minute*15), windowStart.Add(time.Minute*20)),
-			expectedStart: windowStart.Add(time.Minute * 18),
-			expectedEnd:   windowStart.Add(time.Minute * 20),
-			result: &prom.QueryResult{
-				Values: []*util.Vector{
-					{
-						Timestamp: startFloat + (minute * 19),
-					},
-					{
-						Timestamp: startFloat + (minute * 20),
-					},
-				},
-			},
-		},
 		// Example: avg(node_total_hourly_cost{}) by (node, provider_id)[1m:1m]
 		"1 minute resolution, 1 minute window": {
 			resolution:    time.Minute,
@@ -569,7 +569,7 @@ func TestCalculateStartAndEnd(t *testing.T) {
 			result: &source.QueryResult{
 				Values: []*util.Vector{
 					{
-						Timestamp: startFloat + (minute * 15) + (second * 30),
+						Timestamp: startFloat + (minute * 15),
 					},
 				},
 			},
@@ -583,7 +583,7 @@ func TestCalculateStartAndEnd(t *testing.T) {
 			result: &source.QueryResult{
 				Values: []*util.Vector{
 					{
-						Timestamp: startFloat + (second * 30),
+						Timestamp: startFloat,
 					},
 				},
 			},

+ 1 - 1
pkg/costmodel/costmodel.go

@@ -1333,7 +1333,7 @@ func getPodStatefulsets(cache clustercache.ClusterCache, podList []*clustercache
 		}
 		s, err := metav1.LabelSelectorAsSelector(ss.SpecSelector)
 		if err != nil {
-			log.Errorf("Error doing deployment label conversion: " + err.Error())
+			log.Errorf("Error doing deployment label conversion: %s", err.Error())
 		}
 		for _, pod := range podList {
 			labelSet := labels.Set(pod.Labels)

+ 1 - 1
pkg/customcost/ingestor.go

@@ -299,7 +299,7 @@ func (ing *CustomCostIngestor) build(rebuild bool) {
 		ing.LoadWindow(s, e)
 	}
 
-	log.Infof(fmt.Sprintf("CustomCost[%s]: ingestor: build[%s]: completed in %v", ing.key, ing.runID, time.Since(buildStart)))
+	log.Infof("CustomCost[%s]: ingestor: build[%s]: completed in %v", ing.key, ing.runID, time.Since(buildStart))
 
 	// In order to be able to Stop, we have to wait on an exit message
 	// here

+ 3 - 3
pkg/customcost/pipelineservice.go

@@ -68,9 +68,9 @@ func getRegisteredPlugins(configDir string, execDir string) (map[string]*plugin.
 		file := fmt.Sprintf(execFmt, execDir, name, runtime.GOOS, runtime.GOARCH)
 		log.Debugf("looking for file: %s", file)
 		if _, err := os.Stat(file); err != nil {
-			msg := fmt.Sprintf("error reading executable for %s plugin. Plugin executables must be in %s and have name format <plugin name>.ocplugin.<os>.<opencost binary archtecture (arm64 or amd64)>", name, execDir)
-			log.Errorf(msg)
-			return nil, fmt.Errorf(msg)
+			err := fmt.Errorf("error reading executable for %s plugin. Plugin executables must be in %s and have name format <plugin name>.ocplugin.<os>.<opencost binary archtecture (arm64 or amd64)>", name, execDir)
+			log.Errorf("err: %v", err)
+			return nil, err
 		}
 
 		var handshakeConfig = plugin.HandshakeConfig{