Skip to content

Commit

Permalink
[Enterprise Search] Add Production Model Name to Allowed List for ELS…
Browse files Browse the repository at this point in the history
…ER API Endpoints (#156020)

## Summary

Small PR to add the production model name to the `acceptableModelNames`
list that the Enteprise Search 1-Click deploy API endpoints use to check
to ensure we have a known, valid model name.

### Checklist
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
markjhoy authored Apr 27, 2023
1 parent afb36f3 commit fbe3aa3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
isResourceNotFoundException,
} from '../../utils/identify_exceptions';

export const acceptableModelNames = ['.elser_model_1_SNAPSHOT'];
export const acceptableModelNames = ['.elser_model_1', '.elser_model_1_SNAPSHOT'];

export function isNotFoundExceptionError(error: unknown): boolean {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import * as mockGetStatus from './get_ml_model_deployment_status';
import { startMlModelDeployment } from './start_ml_model_deployment';

describe('startMlModelDeployment', () => {
const knownModelName = '.elser_model_1_SNAPSHOT';
const productionModelName = '.elser_model_1';
const snapshotModelName = '.elser_model_1_SNAPSHOT';
const mockTrainedModelsProvider = {
getTrainedModels: jest.fn(),
getTrainedModelsStats: jest.fn(),
Expand All @@ -27,7 +28,7 @@ describe('startMlModelDeployment', () => {
});

it('should error when there is no trained model provider', () => {
expect(() => startMlModelDeployment(knownModelName, undefined)).rejects.toThrowError(
expect(() => startMlModelDeployment(productionModelName, undefined)).rejects.toThrowError(
'Machine Learning is not enabled'
);
});
Expand All @@ -49,15 +50,34 @@ describe('startMlModelDeployment', () => {
jest.spyOn(mockGetStatus, 'getMlModelDeploymentStatus').mockReturnValueOnce(
Promise.resolve({
deploymentState: MlModelDeploymentState.Starting,
modelId: knownModelName,
modelId: productionModelName,
nodeAllocationCount: 0,
startTime: 123456,
targetAllocationCount: 3,
})
);

const response = await startMlModelDeployment(
knownModelName,
productionModelName,
mockTrainedModelsProvider as unknown as MlTrainedModels
);

expect(response.deploymentState).toEqual(MlModelDeploymentState.Starting);
});

it('should return the deployment state if not "downloaded" for snapshot model', async () => {
jest.spyOn(mockGetStatus, 'getMlModelDeploymentStatus').mockReturnValueOnce(
Promise.resolve({
deploymentState: MlModelDeploymentState.Starting,
modelId: snapshotModelName,
nodeAllocationCount: 0,
startTime: 123456,
targetAllocationCount: 3,
})
);

const response = await startMlModelDeployment(
snapshotModelName,
mockTrainedModelsProvider as unknown as MlTrainedModels
);

Expand All @@ -70,7 +90,7 @@ describe('startMlModelDeployment', () => {
.mockReturnValueOnce(
Promise.resolve({
deploymentState: MlModelDeploymentState.Downloaded,
modelId: knownModelName,
modelId: productionModelName,
nodeAllocationCount: 0,
startTime: 123456,
targetAllocationCount: 3,
Expand All @@ -79,7 +99,7 @@ describe('startMlModelDeployment', () => {
.mockReturnValueOnce(
Promise.resolve({
deploymentState: MlModelDeploymentState.Starting,
modelId: knownModelName,
modelId: productionModelName,
nodeAllocationCount: 0,
startTime: 123456,
targetAllocationCount: 3,
Expand All @@ -88,7 +108,7 @@ describe('startMlModelDeployment', () => {
mockTrainedModelsProvider.startTrainedModelDeployment.mockImplementation(async () => {});

const response = await startMlModelDeployment(
knownModelName,
productionModelName,
mockTrainedModelsProvider as unknown as MlTrainedModels
);
expect(response.deploymentState).toEqual(MlModelDeploymentState.Starting);
Expand Down

0 comments on commit fbe3aa3

Please sign in to comment.