Skip to content

Commit

Permalink
Display scale down behavior just when is available
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Nov 13, 2024
1 parent 58042b7 commit 960d19d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
15 changes: 7 additions & 8 deletions tsuru/client/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,14 +792,13 @@ func (a *app) String(simplified bool) string {
prometheusInfo,
}))
}
scaleDown := getParamsScaleDownJson(as.Behavior)
autoScaleTable.AddRow([]string{
"Scale Down Behavior",
fmt.Sprintf("Units: %s\nPercentage: %s%%\nStabilization Window: %ss",
scaleDown.UnitsPolicyValue,
scaleDown.PercentagePolicyValue,
scaleDown.StabilizationWindow),
})
scaleDownLines := getParamsScaleDownLines(as.Behavior)
if len(scaleDownLines) > 0 {
autoScaleTable.AddRow([]string{
"Scale down behavior",
strings.Join(scaleDownLines, "\n"),
})
}
autoScaleTables = append(autoScaleTables, autoScaleTable)
}

Expand Down
16 changes: 8 additions & 8 deletions tsuru/client/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1627,9 +1627,9 @@ Process: web (v10), Min Units: 1, Max Units: 10
+---------------------+----------------------------+
| CPU | Target: 50% |
+---------------------+----------------------------+
| Scale Down Behavior | Units: 20 |
| Scale down behavior | Units: 20 |
| | Percentage: 30% |
| | Stabilization Window: 100s |
| | Stabilization window: 100s |
+---------------------+----------------------------+
Process: worker (v10), Min Units: 2, Max Units: 5
Expand All @@ -1638,9 +1638,9 @@ Process: worker (v10), Min Units: 2, Max Units: 5
+---------------------+---------------------------+
| CPU | Target: 200% |
+---------------------+---------------------------+
| Scale Down Behavior | Units: 10 |
| Scale down behavior | Units: 10 |
| | Percentage: 10% |
| | Stabilization Window: 60s |
| | Stabilization window: 60s |
+---------------------+---------------------------+
`
Expand Down Expand Up @@ -1804,9 +1804,9 @@ Process: web (v10), Min Units: 1, Max Units: 10
| | Threshold: 5 |
| | PrometheusAddress: exemple.prometheus.com |
+---------------------+-------------------------------------------+
| Scale Down Behavior | Units: 25 |
| Scale down behavior | Units: 25 |
| | Percentage: 21% |
| | Stabilization Window: 50s |
| | Stabilization window: 50s |
+---------------------+-------------------------------------------+
Process: worker (v10), Min Units: 2, Max Units: 5
Expand All @@ -1820,9 +1820,9 @@ Process: worker (v10), Min Units: 2, Max Units: 5
| | Units: 1 |
| | Timezone: America/Sao_Paulo |
+---------------------+--------------------------------+
| Scale Down Behavior | Units: 7 |
| Scale down behavior | Units: 7 |
| | Percentage: 5% |
| | Stabilization Window: 60s |
| | Stabilization window: 60s |
+---------------------+--------------------------------+
`
Expand Down
24 changes: 10 additions & 14 deletions tsuru/client/apps_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,27 @@ type scaleDownJson struct {
StabilizationWindow *int32 `json:"stabilizationWindow,omitempty"`
}

type scaleDownOutput struct {
UnitsPolicyValue string `json:"unitsPolicyValue,omitempty"`
PercentagePolicyValue string `json:"percentagePolicyValue,omitempty"`
StabilizationWindow string `json:"stabilizationWindow,omitempty"`
}

func getParamsScaleDownJson(behavior tsuru.AutoScaleSpecBehavior) scaleDownOutput {
func getParamsScaleDownLines(behavior tsuru.AutoScaleSpecBehavior) []string {
b, err := json.Marshal(behavior)
if err != nil {
return scaleDownOutput{}
return nil
}
var behaviorJson behaviorScaleDownJson
err = json.Unmarshal(b, &behaviorJson)
if err != nil {
return scaleDownOutput{}
return nil
}
output := scaleDownOutput{}

lines := []string{}

if behaviorJson.ScaleDown.UnitsPolicyValue != nil {
output.UnitsPolicyValue = fmt.Sprintf("%d", *behaviorJson.ScaleDown.UnitsPolicyValue)
lines = append(lines, fmt.Sprintf("Units: %d", *behaviorJson.ScaleDown.UnitsPolicyValue))
}
if behaviorJson.ScaleDown.PercentagePolicyValue != nil {
output.PercentagePolicyValue = fmt.Sprintf("%d", *behaviorJson.ScaleDown.PercentagePolicyValue)
lines = append(lines, fmt.Sprintf("Percentage: %d%%", *behaviorJson.ScaleDown.PercentagePolicyValue))
}
if behaviorJson.ScaleDown.StabilizationWindow != nil {
output.StabilizationWindow = fmt.Sprintf("%d", *behaviorJson.ScaleDown.StabilizationWindow)
lines = append(lines, fmt.Sprintf("Stabilization window: %ds", *behaviorJson.ScaleDown.StabilizationWindow))
}
return output
return lines
}

0 comments on commit 960d19d

Please sign in to comment.