-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 136039-rules-status-deploy
- Loading branch information
Showing
18 changed files
with
748 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...terprise_search/public/applications/enterprise_search_content/__mocks__/ml_models.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { | ||
MlTrainedModelDeploymentStats, | ||
MlTrainedModelStats, | ||
} from '@elastic/elasticsearch/lib/api/types'; | ||
import { TrainedModelConfigResponse } from '@kbn/ml-plugin/common/types/trained_models'; | ||
|
||
export const nerModel: TrainedModelConfigResponse = { | ||
inference_config: { | ||
ner: { | ||
classification_labels: [ | ||
'O', | ||
'B_PER', | ||
'I_PER', | ||
'B_ORG', | ||
'I_ORG', | ||
'B_LOC', | ||
'I_LOC', | ||
'B_MISC', | ||
'I_MISC', | ||
], | ||
tokenization: { | ||
bert: { | ||
do_lower_case: false, | ||
max_sequence_length: 512, | ||
span: -1, | ||
truncate: 'first', | ||
with_special_tokens: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
input: { | ||
field_names: ['text_field'], | ||
}, | ||
model_id: 'ner-mocked-model', | ||
model_type: 'pytorch', | ||
tags: [], | ||
version: '1', | ||
}; | ||
|
||
export const textClassificationModel: TrainedModelConfigResponse = { | ||
inference_config: { | ||
text_classification: { | ||
classification_labels: ['anger', 'disgust', 'fear', 'joy', 'neutral', 'sadness', 'surprise'], | ||
num_top_classes: 0, | ||
tokenization: { | ||
roberta: { | ||
add_prefix_space: false, | ||
do_lower_case: false, | ||
max_sequence_length: 512, | ||
span: -1, | ||
truncate: 'first', | ||
with_special_tokens: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
input: { | ||
field_names: ['text_field'], | ||
}, | ||
model_id: 'text-classification-mocked-model', | ||
model_type: 'pytorch', | ||
tags: [], | ||
version: '2', | ||
}; | ||
|
||
export const mlModels: TrainedModelConfigResponse[] = [nerModel, textClassificationModel]; | ||
|
||
export const mlModelStats: { | ||
count: number; | ||
trained_model_stats: MlTrainedModelStats[]; | ||
} = { | ||
count: 2, | ||
trained_model_stats: [ | ||
{ | ||
model_id: nerModel.model_id, | ||
model_size_stats: { | ||
model_size_bytes: 260831121, | ||
required_native_memory_bytes: 773320482, | ||
}, | ||
pipeline_count: 0, | ||
deployment_stats: { | ||
allocation_status: { | ||
allocation_count: 1, | ||
target_allocation_count: 1, | ||
state: 'fully_allocated', | ||
}, | ||
error_count: 0, | ||
inference_count: 0, | ||
nodes: [], | ||
number_of_allocations: 1, | ||
state: 'started', | ||
threads_per_allocation: 1, | ||
} as unknown as MlTrainedModelDeploymentStats, | ||
}, | ||
{ | ||
deployment_stats: { | ||
allocation_status: { | ||
allocation_count: 1, | ||
target_allocation_count: 1, | ||
state: 'fully_allocated', | ||
}, | ||
error_count: 0, | ||
inference_count: 0, | ||
nodes: [], | ||
number_of_allocations: 1, | ||
state: 'started', | ||
threads_per_allocation: 1, | ||
} as unknown as MlTrainedModelDeploymentStats, | ||
model_id: textClassificationModel.model_id, | ||
model_size_stats: { | ||
model_size_bytes: 260831121, | ||
required_native_memory_bytes: 773320482, | ||
}, | ||
pipeline_count: 0, | ||
}, | ||
], | ||
}; |
25 changes: 25 additions & 0 deletions
25
.../public/applications/enterprise_search_content/api/ml_models/ml_model_stats_logic.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { mockHttpValues } from '../../../__mocks__/kea_logic'; | ||
import { mlModelStats } from '../../__mocks__/ml_models.mock'; | ||
|
||
import { getMLModelsStats } from './ml_model_stats_logic'; | ||
|
||
describe('MLModelsApiLogic', () => { | ||
const { http } = mockHttpValues; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
describe('getMLModelsStats', () => { | ||
it('calls the ml api', async () => { | ||
http.get.mockResolvedValue(mlModelStats); | ||
const result = await getMLModelsStats(); | ||
expect(http.get).toHaveBeenCalledWith('/api/ml/trained_models/_stats'); | ||
expect(result).toEqual(mlModelStats); | ||
}); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
...earch/public/applications/enterprise_search_content/api/ml_models/ml_model_stats_logic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { MlTrainedModelStats } from '@elastic/elasticsearch/lib/api/types'; | ||
|
||
import { Actions, createApiLogic } from '../../../shared/api_logic/create_api_logic'; | ||
import { HttpLogic } from '../../../shared/http'; | ||
|
||
export type GetMlModelsStatsArgs = undefined; | ||
|
||
export interface GetMlModelsStatsResponse { | ||
count: number; | ||
trained_model_stats: MlTrainedModelStats[]; | ||
} | ||
|
||
export const getMLModelsStats = async () => { | ||
return await HttpLogic.values.http.get<GetMlModelsStatsResponse>('/api/ml/trained_models/_stats'); | ||
}; | ||
|
||
export const MLModelsStatsApiLogic = createApiLogic( | ||
['ml_models_stats_api_logic'], | ||
getMLModelsStats | ||
); | ||
|
||
export type MLModelsStatsApiLogicActions = Actions<GetMlModelsStatsArgs, GetMlModelsStatsResponse>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.