From a96a1079eb98c1f236a0def49b8343ac1a7d965b Mon Sep 17 00:00:00 2001 From: Manuel Ganter Date: Fri, 13 Feb 2026 12:30:32 +0100 Subject: [PATCH] fix: now sizer does not round up to the next Gi when in between two --- internal/receiver/sizing.go | 11 ++--------- internal/receiver/sizing_test.go | 12 ++++++------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/internal/receiver/sizing.go b/internal/receiver/sizing.go index f037585..928a2f5 100644 --- a/internal/receiver/sizing.go +++ b/internal/receiver/sizing.go @@ -76,16 +76,9 @@ func selectCPUValue(stats summary.StatSummary, percentile string) float64 { } } -// formatMemoryK8s converts bytes to Kubernetes memory format (Mi or Gi) +// formatMemoryK8s converts bytes to Kubernetes memory format (Mi) func formatMemoryK8s(bytes float64) string { - const ( - Mi = 1024 * 1024 - Gi = 1024 * 1024 * 1024 - ) - - if bytes >= Gi { - return fmt.Sprintf("%.0fGi", math.Ceil(bytes/Gi)) - } + const Mi = 1024 * 1024 return fmt.Sprintf("%.0fMi", math.Ceil(bytes/Mi)) } diff --git a/internal/receiver/sizing_test.go b/internal/receiver/sizing_test.go index fc16129..a1ac3c5 100644 --- a/internal/receiver/sizing_test.go +++ b/internal/receiver/sizing_test.go @@ -18,9 +18,9 @@ func TestFormatMemoryK8s(t *testing.T) { {1024 * 1024, "1Mi"}, {256 * 1024 * 1024, "256Mi"}, {512 * 1024 * 1024, "512Mi"}, - {1024 * 1024 * 1024, "1Gi"}, - {2 * 1024 * 1024 * 1024, "2Gi"}, - {1.5 * 1024 * 1024 * 1024, "2Gi"}, // rounds up + {1024 * 1024 * 1024, "1024Mi"}, + {2 * 1024 * 1024 * 1024, "2048Mi"}, + {1.5 * 1024 * 1024 * 1024, "1536Mi"}, {100 * 1024 * 1024, "100Mi"}, } @@ -185,12 +185,12 @@ func TestComputeSizing_SingleRun(t *testing.T) { t.Errorf("CPU limit = %q, want %q", c.CPU.Limit, "1") } - // Memory: 512Mi * 1.2 = 614.4Mi -> 615Mi request, 1Gi limit (1024Mi = 1Gi) + // Memory: 512Mi * 1.2 = 614.4Mi -> 615Mi request, 1024Mi limit if c.Memory.Request != "615Mi" { t.Errorf("Memory request = %q, want %q", c.Memory.Request, "615Mi") } - if c.Memory.Limit != "1Gi" { - t.Errorf("Memory limit = %q, want %q", c.Memory.Limit, "1Gi") + if c.Memory.Limit != "1024Mi" { + t.Errorf("Memory limit = %q, want %q", c.Memory.Limit, "1024Mi") } if resp.Meta.RunsAnalyzed != 1 {