Skip to content

Commit

Permalink
Add scale_up_step and scale_down_step inputs for HAS
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelaossa committed Oct 22, 2024
1 parent 3d1ac0c commit 0b7e5a6
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/app/test/app-detail-service-scale.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,17 @@ describe("AppDetailServiceScalePage", () => {
const scaleUpInput = await screen.findByLabelText(
"Scale Up Threshold (CPU Usage)",
);
const scaleUpStepInput = await screen.findByLabelText("Scale Up Steps");
const scaleDownStepInput =
await screen.findByLabelText("Scale Down Steps");

// Check initial values
expect(minContainersInput).toHaveValue(2);
expect(maxContainersInput).toHaveValue(4);
expect(scaleDownInput).toHaveValue(0.1);
expect(scaleUpInput).toHaveValue(0.9);
expect(scaleDownStepInput).toHaveValue(1);
expect(scaleUpStepInput).toHaveValue(1);

// Change the value to 1 should show a warning
fireEvent.change(minContainersInput, { target: { value: 1 } });
Expand Down
8 changes: 8 additions & 0 deletions src/deploy/service-sizing-policy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface DeployServiceSizingPolicyResponse {
max_containers: number | null;
min_cpu_threshold: number | null;
max_cpu_threshold: number | null;
scale_up_step: number;
scale_down_step: number;
created_at: string;
updated_at: string;
_links: {
Expand Down Expand Up @@ -61,6 +63,8 @@ export const defaultServiceSizingPolicyResponse = (
max_containers: 4,
min_cpu_threshold: 0.1,
max_cpu_threshold: 0.9,
scale_up_step: 1,
scale_down_step: 1,
created_at: now,
updated_at: now,
_type: "service_sizing_policy",
Expand Down Expand Up @@ -94,6 +98,8 @@ export const deserializeDeployServiceSizingPolicy = (
maximumMemory: payload.maximum_memory,
minContainers: payload.min_containers,
maxContainers: payload.max_containers,
scaleUpStep: payload.scale_up_step,
scaleDownStep: payload.scale_down_step,
minCpuThreshold: payload.min_cpu_threshold,
maxCpuThreshold: payload.max_cpu_threshold,
createdAt: payload.created_at,
Expand Down Expand Up @@ -155,6 +161,8 @@ export interface ServiceSizingPolicyEditProps {
maxContainers: number | null;
minCpuThreshold: number | null;
maxCpuThreshold: number | null;
scaleUpStep: number;
scaleDownStep: number;
}

const serializeServiceSizingPolicyEditProps = (
Expand Down
2 changes: 2 additions & 0 deletions src/schema/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ export const defaultServiceSizingPolicy = (
maxContainers: 4,
minCpuThreshold: 0.1,
maxCpuThreshold: 0.9,
scaleUpStep: 1,
scaleDownStep: 1,
createdAt: now,
updatedAt: now,
...m,
Expand Down
2 changes: 2 additions & 0 deletions src/types/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ export interface DeployServiceSizingPolicy extends Timestamps {
maxContainers: number | null;
minCpuThreshold: number | null;
maxCpuThreshold: number | null;
scaleUpStep: number;
scaleDownStep: number;
}

export interface DeploySource {
Expand Down
58 changes: 56 additions & 2 deletions src/ui/pages/app-detail-service-scale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ const PolicySummary = ({
value: policy.maxCpuThreshold?.toString() || "",
},
);
if (policy.scaleUpStep > 1)
data.push({
key: "Scale Up Steps",
value: policy.scaleUpStep.toString(),
});
if (policy.scaleDownStep > 1)
data.push({
key: "Scale Down Steps",
value: policy.scaleDownStep.toString(),
});
break;
case "vertical":
data.push(
Expand Down Expand Up @@ -527,7 +537,7 @@ const AutoscalingSection = ({
</h2>
<FormGroup
splitWidthInputs
description="Containers are scaled one at a time sequentially"
description="Containers are scaled based on scale up steps, sequentially"
feedbackMessage={
errors.minContainers ||
((nextPolicy.minContainers ?? 0) < 2
Expand Down Expand Up @@ -558,7 +568,7 @@ const AutoscalingSection = ({
</FormGroup>
<FormGroup
splitWidthInputs
description="Containers are scaled one at a time sequentially"
description="Containers are scaled based on scale up steps, sequentially"
feedbackMessage={errors.maxContainers}
feedbackVariant="danger"
label="Maximum Container Count"
Expand All @@ -580,6 +590,50 @@ const AutoscalingSection = ({
}
/>
</FormGroup>
<FormGroup
splitWidthInputs
description="How many containers to increase by on an autoscale event"
label="Scale Up Steps"
htmlFor="scale-up-step"
>
<Input
id="scale-up-step"
name="scale-up-step"
type="number"
value={nextPolicy.scaleUpStep || "1"}
min="1"
max="9999"
placeholder=""
onChange={(e) =>
updatePolicy(
"scaleUpStep",
Number.parseInt(e.currentTarget.value, 10),
)
}
/>
</FormGroup>
<FormGroup
splitWidthInputs
description="How many containers to decrease by on an autoscale event"
label="Scale Down Steps"
htmlFor="scale-down-step"
>
<Input
id="scale-down-step"
name="scale-down-step"
type="number"
value={nextPolicy.scaleDownStep || "1"}
min="1"
max="9999"
placeholder=""
onChange={(e) =>
updatePolicy(
"scaleDownStep",
Number.parseInt(e.currentTarget.value, 10),
)
}
/>
</FormGroup>
<FormGroup
splitWidthInputs
description="Percent of CPU usage that will trigger a scale down"
Expand Down

0 comments on commit 0b7e5a6

Please sign in to comment.