From 2cd007ebfc64249a0d54d387e61d7a284832f151 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Wed, 3 Nov 2021 16:54:20 +0000 Subject: [PATCH] [ML] Removing log error statements when no ingest pipelines exist (#117281) * [ML] Removing log error statements when no ingest pipileins exist * removing non 200 status code check --- .../data_frame_analytics/models_provider.ts | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/ml/server/models/data_frame_analytics/models_provider.ts b/x-pack/plugins/ml/server/models/data_frame_analytics/models_provider.ts index fb8480d621d55..2f40081f1458d 100644 --- a/x-pack/plugins/ml/server/models/data_frame_analytics/models_provider.ts +++ b/x-pack/plugins/ml/server/models/data_frame_analytics/models_provider.ts @@ -49,26 +49,31 @@ export function modelsProvider( modelIds.map((id: string) => [id, null]) ); - const { body, statusCode } = await client.asCurrentUser.ingest.getPipeline(); - - if (statusCode !== 200) { - return modelIdsMap; - } - - for (const [pipelineName, pipelineDefinition] of Object.entries(body)) { - const { processors } = pipelineDefinition as { processors: Array> }; - - for (const processor of processors) { - const id = processor.inference?.model_id; - if (modelIdsMap.has(id)) { - const obj = modelIdsMap.get(id); - if (obj === null) { - modelIdsMap.set(id, { [pipelineName]: pipelineDefinition }); - } else { - obj![pipelineName] = pipelineDefinition; + try { + const { body } = await client.asCurrentUser.ingest.getPipeline(); + + for (const [pipelineName, pipelineDefinition] of Object.entries(body)) { + const { processors } = pipelineDefinition as { processors: Array> }; + + for (const processor of processors) { + const id = processor.inference?.model_id; + if (modelIdsMap.has(id)) { + const obj = modelIdsMap.get(id); + if (obj === null) { + modelIdsMap.set(id, { [pipelineName]: pipelineDefinition }); + } else { + obj![pipelineName] = pipelineDefinition; + } } } } + } catch (error) { + if (error.statusCode === 404) { + // ES returns 404 when there are no pipelines + // Instead, we should return the modelIdsMap and a 200 + return modelIdsMap; + } + throw error; } return modelIdsMap;