Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup required properties in HorizontalScalingSummary #637

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/deployments/component_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,8 @@ func TestGetComponents_WithHorizontalScaling(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, components[0].HorizontalScalingSummary)

assert.Equal(t, scenario.minReplicas, components[0].HorizontalScalingSummary.MinReplicas)
assert.Equal(t, scenario.maxReplicas, components[0].HorizontalScalingSummary.MaxReplicas)
assert.Equal(t, scenario.minReplicas, *components[0].HorizontalScalingSummary.MinReplicas)
assert.Equal(t, scenario.maxReplicas, *components[0].HorizontalScalingSummary.MaxReplicas)
assert.EqualValues(t, 2, components[0].HorizontalScalingSummary.CurrentReplicas)
assert.EqualValues(t, 4, components[0].HorizontalScalingSummary.DesiredReplicas)
assert.Nil(t, components[0].HorizontalScalingSummary.CurrentCPUUtilizationPercentage) // nolint:staticcheck // SA1019: Ignore linting deprecated fields
Expand Down
22 changes: 7 additions & 15 deletions api/deployments/models/component_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,66 +410,58 @@ type ReplicaStatus struct {
type HorizontalScalingSummary struct {
// Component minimum replicas. From radixconfig.yaml
//
// required: false
// example: 2
MinReplicas int32 `json:"minReplicas"`
MinReplicas *int32 `json:"minReplicas,omitempty"`

// Component maximum replicas. From radixconfig.yaml
//
// required: false
// example: 5
MaxReplicas int32 `json:"maxReplicas"`
MaxReplicas *int32 `json:"maxReplicas,omitempty"`

// CooldownPeriod in seconds. From radixconfig.yaml
//
// required: false
// example: 300
CooldownPeriod int32 `json:"cooldownPeriod"`
CooldownPeriod *int32 `json:"cooldownPeriod,omitempty"`

// PollingInterval in seconds. From radixconfig.yaml
//
// required: false
// example: 30
PollingInterval int32 `json:"pollingInterval"`
PollingInterval *int32 `json:"pollingInterval,omitempty"`

// Triggers lists status of all triggers found in radixconfig.yaml
//
// required: false
// example: 30
// required: true
Triggers []HorizontalScalingSummaryTriggerStatus `json:"triggers"`

// Deprecated: Component current average CPU utilization over all pods, represented as a percentage of requested CPU. Use Triggers instead. Will be removed from Radix API 2025-01-01.
//
// required: false
// example: 70
CurrentCPUUtilizationPercentage *int32 `json:"currentCPUUtilizationPercentage"`

// Deprecated: Component target average CPU utilization over all pods. Use Triggers instead. Will be removed from Radix API 2025-01-01.
//
// required: false
// example: 80
TargetCPUUtilizationPercentage *int32 `json:"targetCPUUtilizationPercentage"`

// Deprecated: Component current average memory utilization over all pods, represented as a percentage of requested memory. Use Triggers instead. Will be removed from Radix API 2025-01-01.
//
// required: false
// example: 80
CurrentMemoryUtilizationPercentage *int32 `json:"currentMemoryUtilizationPercentage"`

// Deprecated: Component target average memory utilization over all pods. use Triggers instead. Will be removed from Radix API 2025-01-01.
//
// required: false
// example: 80
TargetMemoryUtilizationPercentage *int32 `json:"targetMemoryUtilizationPercentage"`

// CurrentReplicas returns the current number of replicas
// required: false
// example: 1
// required: true
CurrentReplicas int32 `json:"currentReplicas"`

// DesiredReplicas returns the target number of replicas across all triggers
// required: false
// example: 2
// required: true
DesiredReplicas int32 `json:"desiredReplicas"`
}

Expand Down
22 changes: 4 additions & 18 deletions api/models/horizontal_scaling_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ func GetHpaSummary(appName, componentName string, hpaList []autoscalingv2.Horizo
return nil
}

var minReplicas, maxReplicas, cooldownPeriod, pollingInterval int32
if scaler.Spec.MinReplicaCount != nil {
minReplicas = *scaler.Spec.MinReplicaCount
}
if scaler.Spec.MaxReplicaCount != nil {
maxReplicas = *scaler.Spec.MaxReplicaCount
}
if scaler.Spec.CooldownPeriod != nil {
cooldownPeriod = *scaler.Spec.CooldownPeriod
}
if scaler.Spec.PollingInterval != nil {
pollingInterval = *scaler.Spec.PollingInterval
}

currentCpuUtil, targetCpuUtil := getHpaMetrics(&hpa, corev1.ResourceCPU)
currentMemoryUtil, targetMemoryUtil := getHpaMetrics(&hpa, corev1.ResourceMemory)

Expand Down Expand Up @@ -75,10 +61,10 @@ func GetHpaSummary(appName, componentName string, hpaList []autoscalingv2.Horizo
}

hpaSummary := deploymentModels.HorizontalScalingSummary{
MinReplicas: minReplicas,
MaxReplicas: maxReplicas,
CooldownPeriod: cooldownPeriod,
PollingInterval: pollingInterval,
MinReplicas: scaler.Spec.MinReplicaCount,
MaxReplicas: scaler.Spec.MaxReplicaCount,
CooldownPeriod: scaler.Spec.CooldownPeriod,
PollingInterval: scaler.Spec.PollingInterval,
CurrentCPUUtilizationPercentage: currentCpuUtil,
TargetCPUUtilizationPercentage: targetCpuUtil,
CurrentMemoryUtilizationPercentage: currentMemoryUtil,
Expand Down
5 changes: 5 additions & 0 deletions swaggerui/html/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6300,6 +6300,11 @@
"HorizontalScalingSummary": {
"description": "HorizontalScalingSummary describe the summary of horizontal scaling of a component",
"type": "object",
"required": [
"triggers",
"currentReplicas",
"desiredReplicas"
],
"properties": {
"cooldownPeriod": {
"description": "CooldownPeriod in seconds. From radixconfig.yaml",
Expand Down
Loading