Skip to content

Commit

Permalink
validate threading params
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Nov 24, 2023
1 parent df16cd9 commit ea06a35
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/ml/common/types/ml_server_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface MlServerDefaults {
export interface MlServerLimits {
max_model_memory_limit?: string;
effective_max_model_memory_limit?: string;
max_single_ml_node_processors?: number;
total_ml_processors?: number;
}

export interface MlInfoResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type { I18nStart, OverlayStart, ThemeServiceStart } from '@kbn/core/publi
import { css } from '@emotion/react';
import { numberValidator } from '@kbn/ml-agg-utils';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { isCloudTrial } from '../services/ml_server_info';
import { getNewJobLimits, isCloudTrial } from '../services/ml_server_info';
import {
composeValidators,
dictionaryValidator,
Expand All @@ -42,7 +42,7 @@ import { ModelItem } from './models_list';
interface DeploymentSetupProps {
config: ThreadingParams;
onConfigChange: (config: ThreadingParams) => void;
errors: Partial<Record<keyof ThreadingParams, object>>;
errors: Partial<Record<keyof ThreadingParams, Record<string, unknown>>>;
isUpdate?: boolean;
deploymentsParams?: Record<string, ThreadingParams>;
}
Expand All @@ -66,6 +66,11 @@ export const DeploymentSetup: FC<DeploymentSetupProps> = ({
isUpdate,
deploymentsParams,
}) => {
const {
total_ml_processors: totalMlProcessors,
max_single_ml_node_processors: maxSingleMlNodeProcessors,
} = getNewJobLimits();

const numOfAllocation = config.numOfAllocations;
const threadsPerAllocations = config.threadsPerAllocations;

Expand All @@ -76,17 +81,20 @@ export const DeploymentSetup: FC<DeploymentSetupProps> = ({

const threadsPerAllocationsOptions = useMemo(
() =>
new Array(THREADS_MAX_EXPONENT).fill(null).map((v, i) => {
const value = Math.pow(2, i);
const id = value.toString();

return {
id,
label: id,
value,
};
}),
[]
new Array(THREADS_MAX_EXPONENT)
.fill(null)
.map((v, i) => Math.pow(2, i))
.filter(maxSingleMlNodeProcessors ? (v) => v <= maxSingleMlNodeProcessors : (v) => v)
.map((value) => {
const id = value.toString();

return {
id,
label: id,
value,
};
}),
[maxSingleMlNodeProcessors]
);

const disableThreadingControls = config.priority === 'low';
Expand Down Expand Up @@ -251,11 +259,28 @@ export const DeploymentSetup: FC<DeploymentSetupProps> = ({
}
hasChildLabel={false}
isDisabled={disableThreadingControls}
isInvalid={!!errors.numOfAllocations}
error={
errors?.numOfAllocations?.min ? (
<FormattedMessage
id="xpack.ml.trainedModels.modelsList.startDeployment.numbersOfAllocationsMinError"
defaultMessage="At least one allocation is required."
/>
) : errors?.numOfAllocations?.max ? (
<FormattedMessage
id="xpack.ml.trainedModels.modelsList.startDeployment.numbersOfAllocationsMaxError"
defaultMessage="Number of allocations cannot exceed {max}."
values={{ max: totalMlProcessors }}
/>
) : null
}
>
<EuiFieldNumber
disabled={disableThreadingControls}
isInvalid={!!errors.numOfAllocations}
fullWidth
min={1}
max={totalMlProcessors}
step={1}
name={'numOfAllocations'}
value={disableThreadingControls ? 1 : numOfAllocation}
Expand Down Expand Up @@ -346,6 +371,8 @@ export const StartUpdateDeploymentModal: FC<StartDeploymentModalProps> = ({
}) => {
const isUpdate = !!initialParams;

const { total_ml_processors: totalMlProcessors } = getNewJobLimits();

const [config, setConfig] = useState<ThreadingParams>(
initialParams ?? {
numOfAllocations: 1,
Expand Down Expand Up @@ -373,7 +400,7 @@ export const StartUpdateDeploymentModal: FC<StartDeploymentModalProps> = ({

const numOfAllocationsValidator = composeValidators(
requiredValidator(),
numberValidator({ min: 1, integerOnly: true })
numberValidator({ min: 1, max: totalMlProcessors, integerOnly: true })
);

const numOfAllocationsErrors = numOfAllocationsValidator(config.numOfAllocations);
Expand Down

0 comments on commit ea06a35

Please sign in to comment.