From 34aeb5119676ff772cc8787819db512a71f9c9b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilson=20J=C3=BAnior?= Date: Mon, 13 Nov 2023 18:05:48 -0300 Subject: [PATCH] Change view of Autoscale --- cmd/plugin/rpaasv2/cmd/autoscale.go | 35 +++++----------- cmd/plugin/rpaasv2/cmd/autoscale_test.go | 52 +++++++++++++----------- cmd/plugin/rpaasv2/cmd/info_test.go | 14 ++++--- 3 files changed, 49 insertions(+), 52 deletions(-) diff --git a/cmd/plugin/rpaasv2/cmd/autoscale.go b/cmd/plugin/rpaasv2/cmd/autoscale.go index 5286a02ab..62944e322 100644 --- a/cmd/plugin/rpaasv2/cmd/autoscale.go +++ b/cmd/plugin/rpaasv2/cmd/autoscale.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "strconv" "strings" "github.com/olekukonko/tablewriter" @@ -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 { @@ -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() } diff --git a/cmd/plugin/rpaasv2/cmd/autoscale_test.go b/cmd/plugin/rpaasv2/cmd/autoscale_test.go index 868e3b2a8..ed9665e09 100644 --- a/cmd/plugin/rpaasv2/cmd/autoscale_test.go +++ b/cmd/plugin/rpaasv2/cmd/autoscale_test.go @@ -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 | ++----------+-----------------+ `, }, @@ -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" | ++-------------+--------------------------+ `, }, diff --git a/cmd/plugin/rpaasv2/cmd/info_test.go b/cmd/plugin/rpaasv2/cmd/info_test.go index ffe7ab46d..b05803846 100644 --- a/cmd/plugin/rpaasv2/cmd/info_test.go +++ b/cmd/plugin/rpaasv2/cmd/info_test.go @@ -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: +----------------------+------+