Skip to content

Commit

Permalink
Adjust CPU recommendations from the API to render in cores
Browse files Browse the repository at this point in the history
  • Loading branch information
jgustie committed Dec 22, 2022
1 parent 49eb361 commit 0f04041
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/command/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ type RecommendationRow struct {
}

func NewRecommendationRow(item *applications.RecommendationItem) *RecommendationRow {
for i := range item.Parameters {
for j := range item.Parameters[i].ContainerResources {
fixCPU(item.Parameters[i].ContainerResources[j])
}
}

return &RecommendationRow{
Name: item.Name,
DeployedAtMachine: formatTime(item.DeployedAt, time.RFC3339),
Expand Down Expand Up @@ -616,3 +622,21 @@ func (s *sorter) Swap(i, j int) {
s.keys[i], s.keys[j] = s.keys[j], s.keys[i]
s.Output.Swap(i, j)
}

// fixCPU is a hack to adjust the CPU value for display.
func fixCPU(value interface{}) {
switch value := value.(type) {
case []interface{}:
for i := range value {
fixCPU(value[i])
}
case map[string]interface{}:
for k, v := range value {
if f, ok := v.(float64); ok && k == "cpu" {
value[k] = f / 1000
} else {
fixCPU(v)
}
}
}
}

0 comments on commit 0f04041

Please sign in to comment.