Skip to content

Commit

Permalink
Change view of Autoscale
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Nov 13, 2023
1 parent 07a3745 commit 34aeb51
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 52 deletions.
35 changes: 11 additions & 24 deletions cmd/plugin/rpaasv2/cmd/autoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"io"
"strconv"
"strings"

"github.com/olekukonko/tablewriter"
Expand Down Expand Up @@ -228,44 +227,29 @@ func writeAutoscale(w io.Writer, autoscale *autogenerated.Autoscale) {
return
}

fmt.Fprintf(w, "min replicas: %d\n", autoscale.MinReplicas)
fmt.Fprintf(w, "max replicas: %d\n", autoscale.MaxReplicas)

table := tablewriter.NewWriter(w)
table.SetHeader([]string{"Min replicas", "Max replicas", "CPU target (%)", "Memory target (%)", "RPS target (req/s)", "Schedule(s)"})
table.SetHeader([]string{"Triggers", "trigger details"})
table.SetAutoFormatHeaders(false)
table.SetHeaderAlignment(tablewriter.ALIGN_CENTER)
table.SetAutoWrapText(false)
table.SetRowLine(false)

table.SetColumnAlignment([]int{
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_LEFT,
})

min := strconv.Itoa(int(autoscale.MinReplicas))
max := strconv.Itoa(int(autoscale.MaxReplicas))

cpu := "N/A"
if autoscale.Cpu != nil {
cpu = strconv.Itoa(int(*autoscale.Cpu))
table.Append([]string{"CPU", fmt.Sprintf("%d%%", int(*autoscale.Cpu))})
}

mem := "N/A"
if autoscale.Memory != nil {
mem = strconv.Itoa(int(*autoscale.Memory))
table.Append([]string{"Memory", fmt.Sprintf("%d%%", int(*autoscale.Memory))})
}

rps := "N/A"
if autoscale.Rps != nil {
rps = strconv.Itoa(int(*autoscale.Rps))
table.Append([]string{"RPS", fmt.Sprintf("%d req/s", int(*autoscale.Rps))})
}

var schedules strings.Builder
if len(autoscale.Schedules) == 0 {
fmt.Fprint(&schedules, "N/A")
}

for i, s := range autoscale.Schedules {
if i > 0 {
Expand All @@ -279,7 +263,10 @@ func writeAutoscale(w io.Writer, autoscale *autogenerated.Autoscale) {
fmt.Fprintf(&schedules, " End: %q", s.End)
}

table.Append([]string{min, max, cpu, mem, rps, schedules.String()})
if text := schedules.String(); text != "" {
table.Append([]string{"Schedule(s)", text})

}
table.Render()
}

Expand Down
52 changes: 29 additions & 23 deletions cmd/plugin/rpaasv2/cmd/autoscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ func TestGetAutoscale(t *testing.T) {
Rps: autogenerated.PtrInt32(100),
})
}),
expected: `+--------------+--------------+----------------+-------------------+--------------------+-------------+
| Min replicas | Max replicas | CPU target (%) | Memory target (%) | RPS target (req/s) | Schedule(s) |
+--------------+--------------+----------------+-------------------+--------------------+-------------+
| 2 | 5 | 50 | 55 | 100 | N/A |
+--------------+--------------+----------------+-------------------+--------------------+-------------+
expected: `min replicas: 2
max replicas: 5
+----------+-----------------+
| Triggers | trigger details |
+----------+-----------------+
| CPU | 50% |
| Memory | 55% |
| RPS | 100 req/s |
+----------+-----------------+
`,
},

Expand All @@ -70,24 +74,26 @@ func TestGetAutoscale(t *testing.T) {
},
})
}),
expected: `+--------------+--------------+----------------+-------------------+--------------------+--------------------------+
| Min replicas | Max replicas | CPU target (%) | Memory target (%) | RPS target (req/s) | Schedule(s) |
+--------------+--------------+----------------+-------------------+--------------------+--------------------------+
| 0 | 100 | N/A | N/A | N/A | Window 1: |
| | | | | | Min replicas: 1 |
| | | | | | Start: "00 08 * * 1-5" |
| | | | | | End: "00 20 * * 1-5" |
| | | | | | |
| | | | | | Window 2: |
| | | | | | Min replicas: 5 |
| | | | | | Start: "00 20 * * 2" |
| | | | | | End: "00 01 * * 3" |
| | | | | | |
| | | | | | Window 3: |
| | | | | | Min replicas: 5 |
| | | | | | Start: "00 22 * * 0" |
| | | | | | End: "00 02 * * 1" |
+--------------+--------------+----------------+-------------------+--------------------+--------------------------+
expected: `min replicas: 0
max replicas: 100
+-------------+--------------------------+
| Triggers | trigger details |
+-------------+--------------------------+
| Schedule(s) | Window 1: |
| | Min replicas: 1 |
| | Start: "00 08 * * 1-5" |
| | End: "00 20 * * 1-5" |
| | |
| | Window 2: |
| | Min replicas: 5 |
| | Start: "00 20 * * 2" |
| | End: "00 01 * * 3" |
| | |
| | Window 3: |
| | Min replicas: 5 |
| | Start: "00 22 * * 0" |
| | End: "00 02 * * 1" |
+-------------+--------------------------+
`,
},

Expand Down
14 changes: 9 additions & 5 deletions cmd/plugin/rpaasv2/cmd/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,15 @@ Errors:
+--------------------+------------------------------+----------------------------------------------+
Autoscale:
+--------------+--------------+----------------+-------------------+--------------------+-------------+
| Min replicas | Max replicas | CPU target (%) | Memory target (%) | RPS target (req/s) | Schedule(s) |
+--------------+--------------+----------------+-------------------+--------------------+-------------+
| 2 | 5 | 55 | 77 | 100 | N/A |
+--------------+--------------+----------------+-------------------+--------------------+-------------+
min replicas: 2
max replicas: 5
+----------+-----------------+
| Triggers | trigger details |
+----------+-----------------+
| CPU | 55% |
| Memory | 77% |
| RPS | 100 req/s |
+----------+-----------------+
ACLs:
+----------------------+------+
Expand Down

0 comments on commit 34aeb51

Please sign in to comment.