Przeglądaj źródła

`go fmt` Fixes and Automation (#3579)

Signed-off-by: HMetcalfeW <106991365+HMetcalfeW@users.noreply.github.com>
Hunter Metcalfe 3 miesięcy temu
rodzic
commit
0ba6956d71
36 zmienionych plików z 162 dodań i 102 usunięć
  1. 28 0
      .github/workflows/format-check.yaml
  2. 24 2
      CONTRIBUTING.md
  3. 4 4
      core/pkg/diagnostics/exporter/source.go
  4. 4 4
      core/pkg/filter/ast/lexer.go
  5. 4 4
      core/pkg/filter/ast/unicode_test.go
  6. 2 2
      core/pkg/heartbeat/exporter/metadataprovider.go
  7. 2 2
      core/pkg/heartbeat/exporter/metadataprovider_test.go
  8. 1 1
      core/pkg/nodestats/request_test.go
  9. 1 1
      core/pkg/storage/bucketstorage_test.go
  10. 1 1
      core/pkg/util/jsonutil/jsonutil.go
  11. 8 8
      core/pkg/util/jsonutil/jsonutil_test.go
  12. 18 0
      justfile
  13. 0 1
      pkg/cloud/aws/athenaintegration_coverage_test.go
  14. 8 6
      pkg/cloud/aws/athenaintegration_test.go
  15. 1 2
      pkg/cloud/aws/fargate_test.go
  16. 0 1
      pkg/cloud/azure/pricesheetclient_test.go
  17. 3 3
      pkg/cloud/azure/provider.go
  18. 1 1
      pkg/cloud/gcp/authorizer.go
  19. 15 15
      pkg/cloud/gcp/authorizer_test.go
  20. 5 5
      pkg/cloud/gcp/bigqueryconfiguration_test.go
  21. 2 2
      pkg/cloud/gcp/cloudcost_test.go
  22. 1 1
      pkg/cloud/gcp/gpu.go
  23. 1 1
      pkg/cloud/gcp/gpu_test.go
  24. 1 1
      pkg/cloud/models/models_test.go
  25. 1 1
      pkg/cloudcost/ingestionmanager.go
  26. 1 1
      pkg/cmd/agent/agent.go
  27. 4 4
      pkg/cmd/commands.go
  28. 1 0
      pkg/costmodel/clusterinfo_test.go
  29. 8 8
      pkg/costmodel/moq_allocation_model_test.go
  30. 1 1
      pkg/customcost/pipelineservice.go
  31. 1 1
      pkg/env/costmodel.go
  32. 1 1
      pkg/mcp/server_test.go
  33. 1 1
      pkg/metrics/jobmetrics_test.go
  34. 6 6
      pkg/metrics/namespacemetrics_test.go
  35. 1 9
      pkg/metrics/pvcmetrics_test.go
  36. 1 1
      pkg/metrics/pvmetrics_test.go

+ 28 - 0
.github/workflows/format-check.yaml

@@ -0,0 +1,28 @@
+name: Format Check
+
+on:
+  pull_request:
+    branches:
+      - develop
+  merge_group:
+    types: [checks_requested]
+
+permissions:
+  contents: read
+
+jobs:
+  format-check:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+
+      - name: Install Go
+        uses: actions/setup-go@v5
+        with:
+          go-version: 'stable'
+
+      - name: Install just
+        uses: extractions/setup-just@v3
+
+      - name: Check formatting
+        run: just fmt-check

+ 24 - 2
CONTRIBUTING.md

@@ -89,6 +89,26 @@ An example of the full command:
 PROMETHEUS_SERVER_ENDPOINT="http://127.0.0.1:9090" go run main.go
 ```
 
+## Code Formatting
+
+Before submitting a pull request, ensure your code is properly formatted:
+
+```bash
+# Format all Go code
+go fmt ./...
+
+# Or use just command
+just fmt
+```
+
+To check if your code is formatted without making changes:
+
+```bash
+just fmt-check
+```
+
+The CI pipeline will automatically check code formatting on pull requests.
+
 ## Testing code
 
 Testing is provided by the `just test` command which runs
@@ -112,9 +132,11 @@ By contributing to this project, you certify that your contribution was created
 
 ## Committing
 
-Please write a commit message with Fixes Issue # if there is an outstanding issue that is fixed. It’s okay to submit a PR without a corresponding issue; just please try to be detailed in the description of the problem you’re addressing.
+Please write a commit message with Fixes Issue # if there is an outstanding issue that is fixed. It's okay to submit a PR without a corresponding issue; just please try to be detailed in the description of the problem you're addressing.
+
+**Code Formatting:** All code must be formatted with `go fmt ./...` (or `just fmt`) before submitting. The CI pipeline will reject PRs with unformatted code. You can run `just fmt-check` to verify formatting locally.
 
-Please run `go fmt` on the project directory. Lint can be okay (for example, comments on exported functions are nice but not required on the server).
+**Code Quality:** While lint warnings are acceptable in some cases (e.g., comments on exported functions are nice but not strictly required), please address any critical issues reported by `go vet`.
 
 Please reach us on [CNCF Slack](https://slack.cncf.io/) in the [#opencost](https://cloud-native.slack.com/archives/C03D56FPD4G) channel or attend the biweekly [OpenCost Working Group community meeting](https://bit.ly/opencost-meeting) from the [Community Calendar](https://bit.ly/opencost-calendar) to discuss OpenCost development.
 

+ 4 - 4
core/pkg/diagnostics/exporter/source.go

@@ -9,7 +9,7 @@ import (
 
 // DiagnosticSource is an `export.ExportSource` implementation that provides the basic data for a `DiagnosticResult` payload.
 type DiagnosticSource struct {
-	applicationName string
+	applicationName   string
 	diagnosticService diagnostics.DiagnosticService
 }
 
@@ -17,7 +17,7 @@ type DiagnosticSource struct {
 // that will be used to retrieve the diagnostic results.
 func NewDiagnosticSource(applicationName string, diagnosticService diagnostics.DiagnosticService) *DiagnosticSource {
 	return &DiagnosticSource{
-		applicationName: applicationName,
+		applicationName:   applicationName,
 		diagnosticService: diagnosticService,
 	}
 }
@@ -32,9 +32,9 @@ func (ds *DiagnosticSource) Make(t time.Time) *diagnostics.DiagnosticsRunReport
 	}
 
 	return &diagnostics.DiagnosticsRunReport{
-		StartTime: t,
+		StartTime:   t,
 		Application: ds.applicationName,
-		Results:   ds.diagnosticService.Run(ctx),
+		Results:     ds.diagnosticService.Run(ctx),
 	}
 }
 

+ 4 - 4
core/pkg/filter/ast/lexer.go

@@ -135,7 +135,7 @@ func (s *scanner) advance() rune {
 	if s.atEnd() {
 		return 0
 	}
-	
+
 	r, size := utf8.DecodeRuneInString(s.source[s.nextByte:])
 	s.nextByte += size
 	return r
@@ -145,7 +145,7 @@ func (s *scanner) match(expected rune) bool {
 	if s.atEnd() {
 		return false
 	}
-	
+
 	// Get the rune at the current position
 	r, size := utf8.DecodeRuneInString(s.source[s.nextByte:])
 	if r != expected {
@@ -173,7 +173,7 @@ func (s *scanner) peek() rune {
 	if s.atEnd() {
 		return 0
 	}
-	
+
 	// Get the rune at the current position
 	r, _ := utf8.DecodeRuneInString(s.source[s.nextByte:])
 	return r
@@ -259,7 +259,7 @@ func (s *scanner) scanToken() {
 			s.errors = append(s.errors, fmt.Errorf("invalid UTF-8 character at position %d", s.nextByte-1))
 			break
 		}
-		
+
 		// identifiers
 		//
 		// We can keep it simple and not _force_ the first character to be a

+ 4 - 4
core/pkg/filter/ast/unicode_test.go

@@ -47,7 +47,7 @@ func TestUnicodeErrorMessages(t *testing.T) {
 		t.Errorf("expected error but got nil")
 		return
 	}
-	
+
 	// Check that the error message contains Unicode information
 	errStr := err.Error()
 	if len(errStr) == 0 {
@@ -59,13 +59,13 @@ func TestInvalidUTF8(t *testing.T) {
 	// Test invalid UTF-8 sequences
 	// This is a string with an invalid UTF-8 sequence
 	invalidUTF8 := "\xC0\x80" // Invalid UTF-8 sequence
-	
+
 	_, err := lex(invalidUTF8, allocFields, allocMapFields)
 	if err == nil {
 		t.Errorf("expected error for invalid UTF-8 but got nil")
 		return
 	}
-	
+
 	// Check that the error message mentions invalid UTF-8
 	errStr := err.Error()
 	if len(errStr) == 0 || !contains(errStr, "invalid UTF-8") {
@@ -81,4 +81,4 @@ func contains(s, substr string) bool {
 		}
 	}
 	return false
-}
+}

+ 2 - 2
core/pkg/heartbeat/exporter/metadataprovider.go

@@ -42,7 +42,7 @@ func (c *ClusterInfoMetadataProvider) GetMetadata() map[string]any {
 }
 
 // LogLevelMetadataProvider is a `HeartbeatMetadataProvider` implementation that provides the log level.
-type LogLevelMetadataProvider struct {}
+type LogLevelMetadataProvider struct{}
 
 // NewLogLevelMetadataProvider creates a new `LogLevelMetadataProvider` instance.
 func NewLogLevelMetadataProvider() *LogLevelMetadataProvider {
@@ -68,7 +68,7 @@ func NewMultiMetadataProvider(providers ...HeartbeatMetadataProvider) *MultiMeta
 	}
 }
 
-// GetMetadata returns the metadata for new heartbeat instances. 
+// GetMetadata returns the metadata for new heartbeat instances.
 // It uses the `MultiMetadataProvider` to get the metadata from multiple providers and injects it into the metadata map.
 func (m *MultiMetadataProvider) GetMetadata() map[string]any {
 	metadata := make(map[string]any)

+ 2 - 2
core/pkg/heartbeat/exporter/metadataprovider_test.go

@@ -10,7 +10,7 @@ import (
 type MockClusterInfoProvider struct{}
 
 var (
-	logLevel = "trace"
+	logLevel    = "trace"
 	ClusterInfo = map[string]string{
 		clusters.ClusterInfoIdKey:       "test-cluster-id",
 		clusters.ClusterInfoNameKey:     "test-cluster-name",
@@ -106,4 +106,4 @@ func TestMultiMetadataProvider(t *testing.T) {
 	if heartbeatSrc.Name() != "heartbeat-source" {
 		t.Errorf("Expected source name to be 'heartbeat-source', got '%s'", heartbeatSrc.Name())
 	}
-}
+}

+ 1 - 1
core/pkg/nodestats/request_test.go

@@ -252,4 +252,4 @@ func TestNodeHttpClient_RequestMethod(t *testing.T) {
 			}
 		})
 	}
-}
+}

+ 1 - 1
core/pkg/storage/bucketstorage_test.go

@@ -116,4 +116,4 @@ func TestBucketStorage_Validate(t *testing.T) {
 	if err != nil {
 		t.Errorf("failed to validate storage: %s", err.Error())
 	}
-}
+}

+ 1 - 1
core/pkg/util/jsonutil/jsonutil.go

@@ -34,4 +34,4 @@ func Encode(buffer *bytes.Buffer, name string, obj interface{}, comma string) {
 		buffer.Write(bytes)
 	}
 	buffer.WriteString(comma)
-}
+}

+ 8 - 8
core/pkg/util/jsonutil/jsonutil_test.go

@@ -8,7 +8,7 @@ import (
 
 func TestEncodeFloat64(t *testing.T) {
 	buffer := &bytes.Buffer{}
-	
+
 	// Test normal float value
 	buffer.Reset()
 	EncodeFloat64(buffer, "test", 3.14, ",")
@@ -16,7 +16,7 @@ func TestEncodeFloat64(t *testing.T) {
 	if buffer.String() != expected {
 		t.Errorf("Expected %s, got %s", expected, buffer.String())
 	}
-	
+
 	// Test NaN value
 	buffer.Reset()
 	EncodeFloat64(buffer, "test", math.NaN(), ",")
@@ -24,7 +24,7 @@ func TestEncodeFloat64(t *testing.T) {
 	if buffer.String() != expected {
 		t.Errorf("Expected %s, got %s", expected, buffer.String())
 	}
-	
+
 	// Test positive infinity
 	buffer.Reset()
 	EncodeFloat64(buffer, "test", math.Inf(1), ",")
@@ -32,7 +32,7 @@ func TestEncodeFloat64(t *testing.T) {
 	if buffer.String() != expected {
 		t.Errorf("Expected %s, got %s", expected, buffer.String())
 	}
-	
+
 	// Test negative infinity
 	buffer.Reset()
 	EncodeFloat64(buffer, "test", math.Inf(-1), ",")
@@ -53,19 +53,19 @@ func TestEncodeString(t *testing.T) {
 
 func TestEncode(t *testing.T) {
 	buffer := &bytes.Buffer{}
-	
+
 	// Test with a simple struct
 	type testStruct struct {
 		Field string `json:"field"`
 	}
-	
+
 	testObj := testStruct{Field: "test"}
 	Encode(buffer, "key", testObj, ",")
 	expected := `"key":{"field":"test"},`
 	if buffer.String() != expected {
 		t.Errorf("Expected %s, got %s", expected, buffer.String())
 	}
-	
+
 	// Test with nil (should produce null)
 	buffer.Reset()
 	Encode(buffer, "key", nil, ",")
@@ -73,4 +73,4 @@ func TestEncode(t *testing.T) {
 	if buffer.String() != expected {
 		t.Errorf("Expected %s, got %s", expected, buffer.String())
 	}
-}
+}

+ 18 - 0
justfile

@@ -6,6 +6,24 @@ commit := `git rev-parse --short HEAD`
 default:
     just --list
 
+# format all Go code
+fmt:
+    go fmt ./...
+
+# check if code is formatted
+fmt-check:
+    #!/bin/sh
+    echo "Checking code formatting..."
+    unformatted="$(gofmt -l .)"
+    if [ -n "$unformatted" ]; then \
+        echo "The following files are not formatted:"; \
+        echo "$unformatted"; \
+        echo ""; \
+        echo "Run 'just fmt' to format your code"; \
+        exit 1; \
+    fi
+    echo "All files are properly formatted"
+
 # run core unit tests
 test-core: 
     {{commonenv}} cd ./core && go test ./... -coverprofile=coverage.out

+ 0 - 1
pkg/cloud/aws/athenaintegration_coverage_test.go

@@ -205,7 +205,6 @@ func TestAthenaIntegration_GetIsKubernetesColumn(t *testing.T) {
 	}
 }
 
-
 func TestAthenaQuerier_GetStatus(t *testing.T) {
 	aq := &AthenaQuerier{}
 

+ 8 - 6
pkg/cloud/aws/athenaintegration_test.go

@@ -419,13 +419,13 @@ func (m *mockAthenaIntegration) GetPartitionWhere(start, end time.Time) string {
 	month := time.Date(start.Year(), start.Month(), 1, 0, 0, 0, 0, time.UTC)
 	endMonth := time.Date(end.Year(), end.Month(), 1, 0, 0, 0, 0, time.UTC)
 	var disjuncts []string
-	
+
 	// Using our mock's result for billing period partitions
 	useBillingPeriodPartitions := false
 	if m.mockAthenaQuerier.AthenaConfiguration.CURVersion != "1.0" {
 		useBillingPeriodPartitions = m.mockAthenaQuerier.hasBillingPeriodPartitions
 	}
-	
+
 	for !month.After(endMonth) {
 		if m.mockAthenaQuerier.AthenaConfiguration.CURVersion == "1.0" {
 			// CUR 1.0 uses year and month columns for partitioning
@@ -445,10 +445,12 @@ func (m *mockAthenaIntegration) GetPartitionWhere(start, end time.Time) string {
 
 func TestAthenaIntegration_GetPartitionWhere(t *testing.T) {
 	testCases := map[string]struct {
-		integration interface{ GetPartitionWhere(time.Time, time.Time) string }
-		start       time.Time
-		end         time.Time
-		expected    string
+		integration interface {
+			GetPartitionWhere(time.Time, time.Time) string
+		}
+		start    time.Time
+		end      time.Time
+		expected string
 	}{
 		"CUR 1.0 single month": {
 			integration: &AthenaIntegration{

+ 1 - 2
pkg/cloud/aws/fargate_test.go

@@ -527,7 +527,6 @@ func TestFargatePricing_ValidateAWSPricingFormat(t *testing.T) {
 		t.Fatal("Expected OnDemand terms in pricing data, got none - AWS format may have changed")
 	}
 
-	t.Logf("✓ AWS pricing format validated: %d products, %d OnDemand terms", 
+	t.Logf("✓ AWS pricing format validated: %d products, %d OnDemand terms",
 		len(pricing.Products), len(pricing.Terms.OnDemand))
 }
-

+ 0 - 1
pkg/cloud/azure/pricesheetclient_test.go

@@ -178,4 +178,3 @@ func TestPriceSheetClient_MethodRegression(t *testing.T) {
 	assert.Equal(t, "POST", req.Raw().Method, "REGRESSION: HTTP method changed back to GET - this will cause 404 errors with Azure billing API")
 	assert.NotEqual(t, "GET", req.Raw().Method, "HTTP method must not be GET for Azure pricesheet download endpoint")
 }
-

+ 3 - 3
pkg/cloud/azure/provider.go

@@ -833,13 +833,13 @@ func (az *Azure) DownloadPricingData() error {
 
 	// Check for Azure rate card filter environment variables with backward compatibility
 	locale := env.GetAzureLocale() // Defaults to "en-US"
-	
+
 	envCurrency := env.GetAzureCurrency()
 	currency := config.CurrencyCode // Use config default
 	if envCurrency != "" {
 		currency = envCurrency // Override with environment variable if provided
 	}
-	
+
 	envRegionInfo := env.GetAzureRegionInfo()
 	regionInfo := config.AzureBillingRegion // Use config default
 	if envRegionInfo != "" {
@@ -847,7 +847,7 @@ func (az *Azure) DownloadPricingData() error {
 	}
 
 	// Debug logging for rate card configuration
-	log.Debugf("Azure rate card configuration: locale=%s (source: %s), currency=%s (source: %s), regionInfo=%s (source: %s)", 
+	log.Debugf("Azure rate card configuration: locale=%s (source: %s), currency=%s (source: %s), regionInfo=%s (source: %s)",
 		locale, getConfigSource("AZURE_LOCALE", locale, "en-US"),
 		currency, getConfigSource("AZURE_CURRENCY", envCurrency, "config"),
 		regionInfo, getConfigSource("AZURE_REGION_INFO", envRegionInfo, "config"))

+ 1 - 1
pkg/cloud/gcp/authorizer.go

@@ -73,7 +73,7 @@ func (gkc *ServiceAccountKey) Equals(config cloud.Config) bool {
 
 func (gkc *ServiceAccountKey) Sanitize() cloud.Config {
 	redactedMap := make(map[string]string, len(gkc.Key))
-	for key, _ := range gkc.Key {
+	for key := range gkc.Key {
 		redactedMap[key] = cloud.Redacted
 	}
 	return &ServiceAccountKey{

+ 15 - 15
pkg/cloud/gcp/authorizer_test.go

@@ -11,31 +11,31 @@ import (
 
 func TestSelectAuthorizerByType(t *testing.T) {
 	tests := []struct {
-		name        string
+		name           string
 		authorizerType string
-		expectError bool
+		expectError    bool
 	}{
 		{
-			name:        "ServiceAccountKey type",
+			name:           "ServiceAccountKey type",
 			authorizerType: ServiceAccountKeyAuthorizerType,
-			expectError: false,
+			expectError:    false,
 		},
 		{
-			name:        "WorkloadIdentity type",
+			name:           "WorkloadIdentity type",
 			authorizerType: WorkloadIdentityAuthorizerType,
-			expectError: false,
+			expectError:    false,
 		},
 		{
-			name:        "Invalid type",
+			name:           "Invalid type",
 			authorizerType: "InvalidType",
-			expectError: true,
+			expectError:    true,
 		},
 	}
 
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			authorizer, err := SelectAuthorizerByType(tt.authorizerType)
-			
+
 			if tt.expectError {
 				assert.Error(t, err)
 				assert.Nil(t, authorizer)
@@ -50,7 +50,7 @@ func TestSelectAuthorizerByType(t *testing.T) {
 func TestServiceAccountKey_MarshalJSON(t *testing.T) {
 	key := &ServiceAccountKey{
 		Key: map[string]string{
-			"type": "service_account",
+			"type":       "service_account",
 			"project_id": "test-project",
 		},
 	}
@@ -95,7 +95,7 @@ func TestServiceAccountKey_Validate(t *testing.T) {
 		t.Run(tt.name, func(t *testing.T) {
 			saKey := &ServiceAccountKey{Key: tt.key}
 			err := saKey.Validate()
-			
+
 			if tt.expectError {
 				assert.Error(t, err)
 			} else {
@@ -160,7 +160,7 @@ func TestServiceAccountKey_Equals(t *testing.T) {
 func TestServiceAccountKey_Sanitize(t *testing.T) {
 	key := &ServiceAccountKey{
 		Key: map[string]string{
-			"type": "service_account",
+			"type":        "service_account",
 			"private_key": "secret-key",
 		},
 	}
@@ -200,7 +200,7 @@ func TestServiceAccountKey_CreateGCPClientOptions(t *testing.T) {
 		t.Run(tt.name, func(t *testing.T) {
 			saKey := &ServiceAccountKey{Key: tt.key}
 			options, err := saKey.CreateGCPClientOptions()
-			
+
 			if tt.expectError {
 				assert.Error(t, err)
 				assert.Nil(t, options)
@@ -274,7 +274,7 @@ func TestWorkloadIdentity_Equals(t *testing.T) {
 func TestWorkloadIdentity_Sanitize(t *testing.T) {
 	wi := &WorkloadIdentity{}
 	sanitized := wi.Sanitize()
-	
+
 	_, ok := sanitized.(*WorkloadIdentity)
 	assert.True(t, ok)
 }
@@ -282,7 +282,7 @@ func TestWorkloadIdentity_Sanitize(t *testing.T) {
 func TestWorkloadIdentity_CreateGCPClientOptions(t *testing.T) {
 	wi := &WorkloadIdentity{}
 	options, err := wi.CreateGCPClientOptions()
-	
+
 	assert.NoError(t, err)
 	assert.NotNil(t, options)
 	assert.Len(t, options, 0)

+ 5 - 5
pkg/cloud/gcp/bigqueryconfiguration_test.go

@@ -425,7 +425,7 @@ func TestBigQueryConfiguration_Sanitize(t *testing.T) {
 		Table:     "test-table",
 		Authorizer: &ServiceAccountKey{
 			Key: map[string]string{
-				"type": "service_account",
+				"type":        "service_account",
 				"private_key": "secret-key",
 			},
 		},
@@ -457,8 +457,8 @@ func TestConvertBigQueryConfigToConfig(t *testing.T) {
 		expected cloud.KeyedConfig
 	}{
 		{
-			name: "Empty config",
-			bqc:  BigQueryConfig{},
+			name:     "Empty config",
+			bqc:      BigQueryConfig{},
 			expected: nil,
 		},
 		{
@@ -514,14 +514,14 @@ func TestConvertBigQueryConfigToConfig(t *testing.T) {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			result := ConvertBigQueryConfigToConfig(tt.bqc)
-			
+
 			if tt.expected == nil {
 				assert.Nil(t, result)
 			} else {
 				assert.NotNil(t, result)
 				expectedBQC := tt.expected.(*BigQueryConfiguration)
 				resultBQC := result.(*BigQueryConfiguration)
-				
+
 				assert.Equal(t, expectedBQC.ProjectID, resultBQC.ProjectID)
 				assert.Equal(t, expectedBQC.Dataset, resultBQC.Dataset)
 				assert.Equal(t, expectedBQC.Table, resultBQC.Table)

+ 2 - 2
pkg/cloud/gcp/cloudcost_test.go

@@ -82,9 +82,9 @@ func TestParseProviderID(t *testing.T) {
 			expected:   "gke-cluster-3-default-pool-xxxx-yy",
 		},
 		{
-			name:     "Provider ID with trailing slash",
+			name:       "Provider ID with trailing slash",
 			providerID: "projects/123456789/instances/gke-cluster-3-default-pool-xxxx-yy/",
-			expected:  "", // The function doesn't handle trailing slashes, so expect empty string
+			expected:   "", // The function doesn't handle trailing slashes, so expect empty string
 		},
 		{
 			name:       "Provider ID without project prefix",

+ 1 - 1
pkg/cloud/gcp/gpu.go

@@ -69,4 +69,4 @@ func NormalizeGPULabel(desc string) string {
 	}
 
 	return ""
-}
+}

+ 1 - 1
pkg/cloud/gcp/gpu_test.go

@@ -38,4 +38,4 @@ func TestNormalizeGPULabel(t *testing.T) {
 			t.Fatalf("case %d: desc=%q: got %q, want %q", i, tc.desc, got, tc.want)
 		}
 	}
-}
+}

+ 1 - 1
pkg/cloud/models/models_test.go

@@ -145,7 +145,7 @@ func TestCustomPricing_AthenaCURVersion(t *testing.T) {
 			cp := &CustomPricing{
 				AthenaCURVersion: testCase.curVersion,
 			}
-			
+
 			if cp.AthenaCURVersion != testCase.expected {
 				t.Errorf("expected AthenaCURVersion to be '%s', got '%s'", testCase.expected, cp.AthenaCURVersion)
 			}

+ 1 - 1
pkg/cloudcost/ingestionmanager.go

@@ -61,7 +61,7 @@ func (im *IngestionManager) SetConfigs(configs map[string]cloud.KeyedConfig) {
 	im.lock.Lock()
 	defer im.lock.Unlock()
 	// delete any exiting ingestors
-	for key, _ := range im.ingestors {
+	for key := range im.ingestors {
 		im.deleteIngestor(key)
 	}
 	// create  ingestors for provided

+ 1 - 1
pkg/cmd/agent/agent.go

@@ -170,6 +170,6 @@ func Execute(opts *AgentOpts) error {
 	if port == 0 {
 		port = env.GetKubecostMetricsPort()
 	}
-	
+
 	return http.ListenAndServe(fmt.Sprintf(":%d", port), handler)
 }

+ 4 - 4
pkg/cmd/commands.go

@@ -106,7 +106,7 @@ func newCostModelCommand() *cobra.Command {
 			// Init logging here so cobra/viper has processed the command line args and flags
 			// otherwise only envvars are available during init
 			log.InitLogging(true)
-			
+
 			// Update config with command-line flag values if they were explicitly set
 			if cmd.Flags().Changed("port") {
 				port, _ := cmd.Flags().GetInt("port")
@@ -128,7 +128,7 @@ func newCostModelCommand() *cobra.Command {
 				customCostEnabled, _ := cmd.Flags().GetBool("custom-cost-enabled")
 				config.CustomCostEnabled = customCostEnabled
 			}
-			
+
 			return costmodel.Execute(config)
 		},
 	}
@@ -153,13 +153,13 @@ func newAgentCommand() *cobra.Command {
 			// Init logging here so cobra/viper has processed the command line args and flags
 			// otherwise only envvars are available during init
 			log.InitLogging(true)
-			
+
 			// Update opts with command-line flag values if they were explicitly set
 			if cmd.Flags().Changed("port") {
 				port, _ := cmd.Flags().GetInt("port")
 				opts.Port = port
 			}
-			
+
 			return agent.Execute(opts)
 		},
 	}

+ 1 - 0
pkg/costmodel/clusterinfo_test.go

@@ -1,4 +1,5 @@
 package costmodel
+
 import (
 	"testing"
 

+ 8 - 8
pkg/costmodel/moq_allocation_model_test.go

@@ -63,11 +63,11 @@ func (mock *AllocationModelMock) ComputeAllocation(start time.Time, end time.Tim
 		panic("AllocationModelMock.ComputeAllocationFunc: method is nil but AllocationModel.ComputeAllocation was just called")
 	}
 	callInfo := struct {
-		Start      time.Time
-		End        time.Time
+		Start time.Time
+		End   time.Time
 	}{
-		Start:      start,
-		End:        end,
+		Start: start,
+		End:   end,
 	}
 	mock.lockComputeAllocation.Lock()
 	mock.calls.ComputeAllocation = append(mock.calls.ComputeAllocation, callInfo)
@@ -80,12 +80,12 @@ func (mock *AllocationModelMock) ComputeAllocation(start time.Time, end time.Tim
 //
 //	len(mockedAllocationModel.ComputeAllocationCalls())
 func (mock *AllocationModelMock) ComputeAllocationCalls() []struct {
-	Start      time.Time
-	End        time.Time
+	Start time.Time
+	End   time.Time
 } {
 	var calls []struct {
-		Start      time.Time
-		End        time.Time
+		Start time.Time
+		End   time.Time
 	}
 	mock.lockComputeAllocation.RLock()
 	calls = mock.calls.ComputeAllocation

+ 1 - 1
pkg/customcost/pipelineservice.go

@@ -134,7 +134,7 @@ func NewPipelineService(hourlyrepo, dailyrepo Repository, ingConf CustomCostInge
 	dailyIngestor.Start(false)
 
 	var domains []string
-	for domain, _ := range registeredPlugins {
+	for domain := range registeredPlugins {
 		domains = append(domains, domain)
 	}
 

+ 1 - 1
pkg/env/costmodel.go

@@ -34,7 +34,7 @@ const (
 
 	AzureOfferIDEnvVar        = "AZURE_OFFER_ID"
 	AzureBillingAccountEnvVar = "AZURE_BILLING_ACCOUNT"
-	
+
 	// Azure rate card filter environment variables
 	AzureLocaleEnvVar     = "AZURE_LOCALE"
 	AzureCurrencyEnvVar   = "AZURE_CURRENCY"

+ 1 - 1
pkg/mcp/server_test.go

@@ -1497,7 +1497,7 @@ func TestQueryCloudCosts_ContextCancellation(t *testing.T) {
 
 	// Query should fail with context cancelled error
 	_, err := s.QueryCloudCosts(ctx, req)
-	
+
 	// Verify context cancellation was detected
 	assert.Error(t, err)
 	assert.True(t, caq.contextWasCancelled, "Context cancellation should be detected by querier")

+ 1 - 1
pkg/metrics/jobmetrics_test.go

@@ -88,4 +88,4 @@ func TestKubeJobStatusFailedMetric_Write(t *testing.T) {
 	if !foundUID {
 		t.Error("Expected uid label not found")
 	}
-}
+}

+ 6 - 6
pkg/metrics/namespacemetrics_test.go

@@ -29,7 +29,7 @@ func TestKubecostNamespaceCollector_Collect(t *testing.T) {
 			},
 		},
 	}
-	
+
 	collector := KubecostNamespaceCollector{
 		KubeClusterCache: cache,
 		metricsConfig:    MetricsConfig{},
@@ -62,7 +62,7 @@ func TestKubeNamespaceCollector_Collect(t *testing.T) {
 			},
 		},
 	}
-	
+
 	collector := KubeNamespaceCollector{
 		KubeClusterCache: cache,
 		metricsConfig:    MetricsConfig{},
@@ -123,7 +123,7 @@ func TestNamespaceAnnotationsMetric_Write(t *testing.T) {
 func TestKubeNamespaceLabelsMetric_Write(t *testing.T) {
 	metric := newKubeNamespaceLabelsMetric(
 		"test_metric",
-		"test-ns", 
+		"test-ns",
 		"test-uid",
 		[]string{"env"},
 		[]string{"prod"},
@@ -158,7 +158,7 @@ func TestKubeNamespaceLabelsMetric_Write(t *testing.T) {
 
 func TestKubecostNamespaceCollector_Describe(t *testing.T) {
 	collector := KubecostNamespaceCollector{metricsConfig: MetricsConfig{}}
-	
+
 	ch := make(chan *prometheus.Desc, 1)
 	go func() {
 		collector.Describe(ch)
@@ -177,7 +177,7 @@ func TestKubecostNamespaceCollector_Describe(t *testing.T) {
 
 func TestKubeNamespaceCollector_Describe(t *testing.T) {
 	collector := KubeNamespaceCollector{metricsConfig: MetricsConfig{}}
-	
+
 	ch := make(chan *prometheus.Desc, 1)
 	go func() {
 		collector.Describe(ch)
@@ -192,4 +192,4 @@ func TestKubeNamespaceCollector_Describe(t *testing.T) {
 	if count != 1 {
 		t.Errorf("Expected 1 descriptor, got %d", count)
 	}
-}
+}

+ 1 - 9
pkg/metrics/pvcmetrics_test.go

@@ -25,7 +25,6 @@ func collectMetrics(collector KubePVCCollector) []prometheus.Metric {
 	return metrics
 }
 
-
 func TestKubePVCCollector_Describe(t *testing.T) {
 	collector := KubePVCCollector{metricsConfig: MetricsConfig{}}
 	ch := make(chan *prometheus.Desc, 5)
@@ -44,7 +43,6 @@ func TestKubePVCCollector_Describe(t *testing.T) {
 	}
 }
 
-
 func TestKubePVCCollector_Collect(t *testing.T) {
 	storageSize := resource.MustParse("1Gi")
 	pvc := &clustercache.PersistentVolumeClaim{
@@ -89,7 +87,6 @@ func TestKubePVCCollector_Collect(t *testing.T) {
 	}
 }
 
-
 func TestKubePVCMetrics_UIDLabel(t *testing.T) {
 	metric := newKubePVCResourceRequestsStorageBytesMetric(
 		"test_metric", "test-pvc", "test-namespace", "test-uid", 1000.0,
@@ -109,11 +106,6 @@ func TestKubePVCMetrics_UIDLabel(t *testing.T) {
 	t.Error("UID label not found in metric")
 }
 
-
-
-
-
-
 type FakePVCCache struct {
 	clustercache.ClusterCache
 	pvcs []*clustercache.PersistentVolumeClaim
@@ -127,4 +119,4 @@ func NewFakePVCCache(pvcs []*clustercache.PersistentVolumeClaim) FakePVCCache {
 	return FakePVCCache{
 		pvcs: pvcs,
 	}
-}
+}

+ 1 - 1
pkg/metrics/pvmetrics_test.go

@@ -121,4 +121,4 @@ func NewFakePVCache(pvs []*clustercache.PersistentVolume) FakePVCache {
 	return FakePVCache{
 		pvs: pvs,
 	}
-}
+}