fix: now sizer does not round up to the next Gi when in between two
This commit is contained in:
parent
8101e9b20e
commit
a96a1079eb
2 changed files with 8 additions and 15 deletions
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue