[ML] Better handling of recognizer module manifest parsing errors (#29322)

This commit is contained in:
James Gowdy 2019-01-28 10:32:15 +00:00 committed by GitHub
parent 50d7f6229a
commit ec607e26b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 5 deletions

View file

@ -29,6 +29,7 @@ import { jobServiceRoutes } from './server/routes/job_service';
import { jobAuditMessagesRoutes } from './server/routes/job_audit_messages';
import { fileDataVisualizerRoutes } from './server/routes/file_data_visualizer';
import { i18n } from '@kbn/i18n';
import { initMlServerLog } from './server/client/log';
export const ml = (kibana) => {
return new kibana.Plugin({
@ -108,6 +109,8 @@ export const ml = (kibana) => {
jobServiceRoutes(server, commonRouteConfig);
jobAuditMessagesRoutes(server, commonRouteConfig);
fileDataVisualizerRoutes(server, commonRouteConfig);
initMlServerLog(server);
}
});

View file

@ -49,6 +49,9 @@ export class DataRecognizer extends Component {
this.setState({
results
});
})
.catch((e) => {
console.error('Error attempting to recognize index', e);
});
}

View file

@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
export let mlLog = () => {};
export function initMlServerLog(server) {
mlLog = (level, message) => server.log(['ml', level], message);
}

View file

@ -5,6 +5,7 @@
*/
import { callWithInternalUserFactory } from '../../client/call_with_internal_user_factory';
import { mlLog } from '../../client/log';
import {
ML_ANNOTATIONS_INDEX_ALIAS_READ,
@ -42,7 +43,7 @@ export async function isAnnotationsFeatureAvailable(server) {
if (!annotationsWriteAliasExists) return false;
} catch (err) {
server.log(['info', 'ml'], 'Disabling ML annotations feature because the index/alias integrity check failed.');
mlLog('info', 'Disabling ML annotations feature because the index/alias integrity check failed.');
return false;
}

View file

@ -9,6 +9,7 @@
import fs from 'fs';
import Boom from 'boom';
import { prefixDatafeedId } from '../../../common/util/job_utils';
import { mlLog } from '../../client/log';
const ML_DIR = 'ml';
const KIBANA_DIR = 'kibana';
@ -63,10 +64,14 @@ export class DataRecognizer {
const dirs = await this.listDirs(this.modulesDir);
await Promise.all(dirs.map(async (dir) => {
const file = await this.readFile(`${this.modulesDir}/${dir}/manifest.json`);
configs.push({
dirName: dir,
json: JSON.parse(file)
});
try {
configs.push({
dirName: dir,
json: JSON.parse(file)
});
} catch (error) {
mlLog('warning', `Error parsing ${dir}/manifest.json`);
}
}));
return configs;