[ML] Removing log error statements when no ingest pipelines exist (#117281) (#117381)

* [ML] Removing log error statements when no ingest pipileins exist

* removing non 200 status code check

Co-authored-by: James Gowdy <jgowdy@elastic.co>
This commit is contained in:
Kibana Machine 2021-11-04 05:52:31 -04:00 committed by GitHub
parent 1fc225b876
commit e57cb4e761
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -49,26 +49,31 @@ export function modelsProvider(
modelIds.map((id: string) => [id, null])
);
const { body, statusCode } = await client.asCurrentUser.ingest.getPipeline();
try {
const { body } = await client.asCurrentUser.ingest.getPipeline();
if (statusCode !== 200) {
return modelIdsMap;
}
for (const [pipelineName, pipelineDefinition] of Object.entries(body)) {
const { processors } = pipelineDefinition as { processors: Array<Record<string, any>> };
for (const [pipelineName, pipelineDefinition] of Object.entries(body)) {
const { processors } = pipelineDefinition as { processors: Array<Record<string, any>> };
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;
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;