Skip to content

Commit

Permalink
[8.8] [Enterprise Search] Add Production Model Name to Allowed List f…
Browse files Browse the repository at this point in the history
…or ELSER API Endpoints (#156020) (#156062)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Enterprise Search] Add Production Model Name to Allowed List for
ELSER API Endpoints
(#156020)](#156020)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Mark J.
Hoy","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-04-27T17:22:30Z","message":"[Enterprise
Search] Add Production Model Name to Allowed List for ELSER API
Endpoints (#156020)\n\n## Summary\r\n\r\nSmall PR to add the production
model name to the `acceptableModelNames`\r\nlist that the Enteprise
Search 1-Click deploy API endpoints use to check\r\nto ensure we have a
known, valid model name.\r\n\r\n### Checklist\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"fbe3aa36b31c0e6499d03b6afb14d4d628d05312","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:feature","Team:EnterpriseSearch","v8.8.0","v8.9.0"],"number":156020,"url":"https://github.com/elastic/kibana/pull/156020","mergeCommit":{"message":"[Enterprise
Search] Add Production Model Name to Allowed List for ELSER API
Endpoints (#156020)\n\n## Summary\r\n\r\nSmall PR to add the production
model name to the `acceptableModelNames`\r\nlist that the Enteprise
Search 1-Click deploy API endpoints use to check\r\nto ensure we have a
known, valid model name.\r\n\r\n### Checklist\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"fbe3aa36b31c0e6499d03b6afb14d4d628d05312"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156020","number":156020,"mergeCommit":{"message":"[Enterprise
Search] Add Production Model Name to Allowed List for ELSER API
Endpoints (#156020)\n\n## Summary\r\n\r\nSmall PR to add the production
model name to the `acceptableModelNames`\r\nlist that the Enteprise
Search 1-Click deploy API endpoints use to check\r\nto ensure we have a
known, valid model name.\r\n\r\n### Checklist\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"fbe3aa36b31c0e6499d03b6afb14d4d628d05312"}}]}]
BACKPORT-->

Co-authored-by: Mark J. Hoy <[email protected]>
  • Loading branch information
kibanamachine and markjhoy authored Apr 27, 2023
1 parent 7cd0cdd commit 77f9279
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 77f9279

Please sign in to comment.