From 679824c15dbadaaf27ba8e25955475e591865e91 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Wed, 16 Oct 2024 17:28:01 +0100 Subject: [PATCH 1/6] [ML] File data visualizer filter running inference services --- x-pack/plugins/data_visualizer/server/routes.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/data_visualizer/server/routes.ts b/x-pack/plugins/data_visualizer/server/routes.ts index 05234fc5583ee..7a6347c274a66 100644 --- a/x-pack/plugins/data_visualizer/server/routes.ts +++ b/x-pack/plugins/data_visualizer/server/routes.ts @@ -86,8 +86,17 @@ export function routes(coreSetup: CoreSetup, logger: Logger) const { endpoints } = await esClient.asCurrentUser.inference.get({ inference_id: '_all', }); + const { trained_model_stats: stats } = + await esClient.asCurrentUser.ml.getTrainedModelsStats(); - return response.ok({ body: endpoints }); + const runningInferenceServices = endpoints.filter((endpoint) => { + const endpointStats = stats.find( + (stat) => stat.model_id === endpoint.service_settings.model_id + ); + return endpointStats?.deployment_stats?.state === 'started'; + }); + + return response.ok({ body: runningInferenceServices }); } catch (e) { return response.customError(wrapError(e)); } From 72f59847a8fd985074ecd81f841bf2d1cfee7972 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Thu, 17 Oct 2024 13:48:33 +0100 Subject: [PATCH 2/6] improving deployment check and renaming endpoint --- .../combined_fields/semantic_text.tsx | 32 +++++++++---------- .../plugins/data_visualizer/server/routes.ts | 18 +++++++---- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/combined_fields/semantic_text.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/combined_fields/semantic_text.tsx index 5ec9216f599c6..e323b5d7ebdf4 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/combined_fields/semantic_text.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/combined_fields/semantic_text.tsx @@ -41,8 +41,8 @@ export const SemanticTextForm: FC = ({ addCombinedField, hasNameCollision const { services: { http }, } = useDataVisualizerKibana(); - const [inferenceServices, setInferenceServices] = useState([]); - const [selectedInference, setSelectedInference] = useState(); + const [inferenceEndpoints, setInferenceEndpoints] = useState([]); + const [selectedInferenceEndpoint, setSelectedInferenceEndpoint] = useState(); const [selectedFieldOption, setSelectedFieldOption] = useState(); const [renameToFieldOption, setRenameToFieldOption] = useState(''); const [fieldError, setFieldError] = useState(); @@ -61,17 +61,17 @@ export const SemanticTextForm: FC = ({ addCombinedField, hasNameCollision useEffect(() => { http - .fetch('/internal/data_visualizer/inference_services', { + .fetch('/internal/data_visualizer/inference_endpoints', { method: 'GET', version: '1', }) .then((response) => { - const inferenceServiceOptions = response.map((service) => ({ - value: service.inference_id, - text: service.inference_id, + const inferenceEndpointOptions = response.map((endpoint) => ({ + value: endpoint.inference_id, + text: endpoint.inference_id, })); - setInferenceServices(inferenceServiceOptions); - setSelectedInference(inferenceServiceOptions[0]?.value ?? undefined); + setInferenceEndpoints(inferenceEndpointOptions); + setSelectedInferenceEndpoint(inferenceEndpointOptions[0]?.value ?? undefined); }); }, [http]); @@ -88,7 +88,7 @@ export const SemanticTextForm: FC = ({ addCombinedField, hasNameCollision renameToFieldOption === '' || renameToFieldOption === undefined || selectedFieldOption === undefined || - selectedInference === undefined + selectedInferenceEndpoint === undefined ) { return; } @@ -103,7 +103,7 @@ export const SemanticTextForm: FC = ({ addCombinedField, hasNameCollision newMappings.properties![renameToFieldOption ?? selectedFieldOption] = { // @ts-ignore types are missing semantic_text type: 'semantic_text', - inference_id: selectedInference, + inference_id: selectedInferenceEndpoint, }; return newMappings; }, @@ -138,12 +138,12 @@ export const SemanticTextForm: FC = ({ addCombinedField, hasNameCollision const isInvalid = useMemo(() => { return ( - !selectedInference || + !selectedInferenceEndpoint || !selectedFieldOption || renameToFieldOption === '' || fieldError !== undefined ); - }, [selectedInference, selectedFieldOption, renameToFieldOption, fieldError]); + }, [selectedInferenceEndpoint, selectedFieldOption, renameToFieldOption, fieldError]); return ( <> @@ -185,13 +185,13 @@ export const SemanticTextForm: FC = ({ addCombinedField, hasNameCollision setSelectedInference(e.target.value)} + options={inferenceEndpoints} + value={selectedInferenceEndpoint} + onChange={(e) => setSelectedInferenceEndpoint(e.target.value)} /> diff --git a/x-pack/plugins/data_visualizer/server/routes.ts b/x-pack/plugins/data_visualizer/server/routes.ts index 7a6347c274a66..7d46b2705dcd1 100644 --- a/x-pack/plugins/data_visualizer/server/routes.ts +++ b/x-pack/plugins/data_visualizer/server/routes.ts @@ -69,7 +69,7 @@ export function routes(coreSetup: CoreSetup, logger: Logger) router.versioned .get({ - path: '/internal/data_visualizer/inference_services', + path: '/internal/data_visualizer/inference_endpoints', access: 'internal', options: { tags: ['access:fileUpload:analyzeFile'], @@ -89,14 +89,20 @@ export function routes(coreSetup: CoreSetup, logger: Logger) const { trained_model_stats: stats } = await esClient.asCurrentUser.ml.getTrainedModelsStats(); - const runningInferenceServices = endpoints.filter((endpoint) => { - const endpointStats = stats.find( - (stat) => stat.model_id === endpoint.service_settings.model_id + const deployedInferenceEndpoints = endpoints.filter((endpoint) => { + const modelId = endpoint.service_settings.model_id; + const inferenceId = endpoint.inference_id; + // Check to see if there is a started deployment which + // matches the model ID and the inference ID + const modelStats = stats.find( + (stat) => + modelId === stat.deployment_stats?.model_id && + inferenceId === stat.deployment_stats?.deployment_id ); - return endpointStats?.deployment_stats?.state === 'started'; + return modelStats?.deployment_stats?.state === 'started'; }); - return response.ok({ body: runningInferenceServices }); + return response.ok({ body: deployedInferenceEndpoints }); } catch (e) { return response.customError(wrapError(e)); } From 2dd52c5b4d63760e85b16c9f825d69409003bf0a Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Thu, 17 Oct 2024 14:01:18 +0100 Subject: [PATCH 3/6] typo --- .../common/components/combined_fields/semantic_text.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/combined_fields/semantic_text.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/combined_fields/semantic_text.tsx index e323b5d7ebdf4..c1f56214e2ce1 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/combined_fields/semantic_text.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/combined_fields/semantic_text.tsx @@ -185,7 +185,7 @@ export const SemanticTextForm: FC = ({ addCombinedField, hasNameCollision Date: Thu, 17 Oct 2024 16:15:55 +0100 Subject: [PATCH 4/6] fixing deployment check --- x-pack/plugins/data_visualizer/server/routes.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/data_visualizer/server/routes.ts b/x-pack/plugins/data_visualizer/server/routes.ts index 7d46b2705dcd1..91fa7e6917c57 100644 --- a/x-pack/plugins/data_visualizer/server/routes.ts +++ b/x-pack/plugins/data_visualizer/server/routes.ts @@ -91,14 +91,9 @@ export function routes(coreSetup: CoreSetup, logger: Logger) const deployedInferenceEndpoints = endpoints.filter((endpoint) => { const modelId = endpoint.service_settings.model_id; - const inferenceId = endpoint.inference_id; // Check to see if there is a started deployment which - // matches the model ID and the inference ID - const modelStats = stats.find( - (stat) => - modelId === stat.deployment_stats?.model_id && - inferenceId === stat.deployment_stats?.deployment_id - ); + // matches the model ID + const modelStats = stats.find((stat) => modelId === stat.deployment_stats?.model_id); return modelStats?.deployment_stats?.state === 'started'; }); From 40dce066ef595f4d78289b8de080fe430db5233f Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Thu, 17 Oct 2024 17:07:51 +0100 Subject: [PATCH 5/6] adding endpoint description --- x-pack/plugins/data_visualizer/server/routes.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/x-pack/plugins/data_visualizer/server/routes.ts b/x-pack/plugins/data_visualizer/server/routes.ts index 91fa7e6917c57..a0cbcd35a34d1 100644 --- a/x-pack/plugins/data_visualizer/server/routes.ts +++ b/x-pack/plugins/data_visualizer/server/routes.ts @@ -67,6 +67,13 @@ export function routes(coreSetup: CoreSetup, logger: Logger) } ); + /** + * @apiGroup DataVisualizer + * + * @api {get} /internal/data_visualizer/inference_endpoints Returns a list of inference endpoints which are currently deployed + * @apiName inferenceEndpoints + * @apiDescription Returns a list of inference endpoints where the underlying model is currently deployed + */ router.versioned .get({ path: '/internal/data_visualizer/inference_endpoints', From fdc075eb5c370826b2d6bae1046e064ca12d19e7 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Fri, 18 Oct 2024 15:35:01 +0100 Subject: [PATCH 6/6] fitlering endpoints based on type --- x-pack/plugins/data_visualizer/server/routes.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/data_visualizer/server/routes.ts b/x-pack/plugins/data_visualizer/server/routes.ts index a0cbcd35a34d1..e04ba7521bfa4 100644 --- a/x-pack/plugins/data_visualizer/server/routes.ts +++ b/x-pack/plugins/data_visualizer/server/routes.ts @@ -93,18 +93,16 @@ export function routes(coreSetup: CoreSetup, logger: Logger) const { endpoints } = await esClient.asCurrentUser.inference.get({ inference_id: '_all', }); - const { trained_model_stats: stats } = - await esClient.asCurrentUser.ml.getTrainedModelsStats(); - const deployedInferenceEndpoints = endpoints.filter((endpoint) => { - const modelId = endpoint.service_settings.model_id; - // Check to see if there is a started deployment which - // matches the model ID - const modelStats = stats.find((stat) => modelId === stat.deployment_stats?.model_id); - return modelStats?.deployment_stats?.state === 'started'; + const filteredInferenceEndpoints = endpoints.filter((endpoint) => { + return ( + endpoint.task_type === 'sparse_embedding' || endpoint.task_type === 'text_embedding' + // TODO: add this back in when the fix has made it into es in 8.16 + // && endpoint.service_settings.num_allocations > 0 + ); }); - return response.ok({ body: deployedInferenceEndpoints }); + return response.ok({ body: filteredInferenceEndpoints }); } catch (e) { return response.customError(wrapError(e)); }