Skip to content

Commit

Permalink
Add cpu limit form group component
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlycoconuts committed May 23, 2024
1 parent 4104721 commit 6af3304
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { autoscalingPolicyOptions } from "../../form/components/autoscaling_poli
import { ConfigMultiSectionPanel } from "../../../../components/config_multi_section_panel/ConfigMultiSectionPanel"

const ResourcesSection = ({
resourceRequest: { cpu_request, memory_request, min_replica, max_replica },
resourceRequest: { cpu_request, cpu_limit, memory_request, min_replica, max_replica },
}) => {
const items = [
{
Expand All @@ -26,6 +26,13 @@ const ResourcesSection = ({
},
];

if (cpu_limit !== "0") {
items.push({
title: "CPU Limit",
description: cpu_limit,
});
}

return (
<EuiDescriptionList
compressed
Expand Down
44 changes: 44 additions & 0 deletions ui/src/router/components/form/components/CPULimitsFormGroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { Fragment } from "react";
import { FormLabelWithToolTip } from "@caraml-dev/ui-lib";
import { EuiDescribedFormGroup, EuiFieldText, EuiFormRow } from "@elastic/eui";


export const CPULimitsFormGroup = ({
resourcesConfig,
onChange,
errors,
}) => {
return (
<EuiDescribedFormGroup
title={<p>CPU Limits</p>}
description={
<Fragment>
Use this field to override the platform-level default CPU limit.
</Fragment>
}
fullWidth
>
<EuiFormRow
label={
<FormLabelWithToolTip
label="CPU Limits"
content="Specify the maximum amount of CPU available for your model.
The value 0 correponds to not setting any CPU limit."
/>
}
isInvalid={!!errors}
error={errors}
fullWidth
>
<EuiFieldText
placeholder="500m"
value={resourcesConfig?.cpu_limit}
onChange={onChange}
isInvalid={!!errors}
name="cpu_limit"
fullWidth
/>
</EuiFormRow>
</EuiDescribedFormGroup>
)
}
15 changes: 15 additions & 0 deletions ui/src/router/components/form/components/ResourcesPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
EuiForm,
EuiFormRow,
EuiSpacer,
EuiAccordion,
} from "@elastic/eui";
import { FormLabelWithToolTip } from "../../../../components/form/label_with_tooltip/FormLabelWithToolTip";
import { useOnChangeHandler } from "../../../../components/form/hooks/useOnChangeHandler";
import { CPULimitsFormGroup } from "./CPULimitsFormGroup";

export const ResourcesPanel = ({
resourcesConfig,
Expand Down Expand Up @@ -46,6 +48,7 @@ export const ResourcesPanel = ({
onChange={(e) => onChange("cpu_request")(e.target.value)}
isInvalid={!!errors.cpu_request}
name="cpu"
fullWidth
/>
</EuiFormRow>
</EuiFlexItem>
Expand All @@ -67,6 +70,7 @@ export const ResourcesPanel = ({
onChange={(e) => onChange("memory_request")(e.target.value)}
isInvalid={!!errors.memory_request}
name="memory"
fullWidth
/>
</EuiFormRow>
</EuiFlexItem>
Expand Down Expand Up @@ -102,6 +106,17 @@ export const ResourcesPanel = ({
aria-label="autoscaling"
/>
</EuiFormRow>
<EuiSpacer size="s" />
<EuiAccordion
id="adv config"
buttonContent="Advanced configurations">
<EuiSpacer size="s" />
<CPULimitsFormGroup
resourcesConfig={resourcesConfig}
onChange={(e) => onChange("cpu_limit")(e.target.value)}
errors={errors.cpu_limit}
/>
</EuiAccordion>
</EuiForm>
</Panel>
);
Expand Down
6 changes: 6 additions & 0 deletions ui/src/router/components/form/validation/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ const resourceRequestSchema = (maxAllowedReplica) =>
cpuRequestRegex,
'Valid CPU value is required, e.g "2" or "500m"'
),
cpu_limit: yup
.string()
.matches(
cpuRequestRegex,
{ message: 'Valid CPU value is required, e.g "2" or "500m"', excludeEmptyString: true }
),
memory_request: yup
.string()
.matches(memRequestRegex, "Valid RAM value is required, e.g. 512Mi"),
Expand Down
1 change: 1 addition & 0 deletions ui/src/services/ensembler/DockerEnsembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class DockerEnsembler extends Ensembler {
port: 8080,
resource_request: {
cpu_request: "500m",
cpu_limit: "0",
memory_request: "512Mi",
min_replica: 0,
max_replica: 2,
Expand Down
1 change: 1 addition & 0 deletions ui/src/services/ensembler/PyFuncEnsembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class PyFuncEnsembler extends Ensembler {
project_id: project_id,
resource_request: {
cpu_request: "500m",
cpu_limit: "0",
memory_request: "512Mi",
min_replica: 0,
max_replica: 2,
Expand Down
2 changes: 2 additions & 0 deletions ui/src/services/router/TuringRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class TuringRouter {
rules: [],
resource_request: {
cpu_request: "500m",
cpu_limit: "0",
memory_request: "512Mi",
min_replica: 0,
max_replica: 2,
Expand All @@ -40,6 +41,7 @@ export class TuringRouter {
port: 8080,
resource_request: {
cpu_request: "500m",
cpu_limit: "0",
memory_request: "512Mi",
min_replica: 0,
max_replica: 2,
Expand Down

0 comments on commit 6af3304

Please sign in to comment.