[ML] translate models (#27888) (#28664)

[ML] translate models
This commit is contained in:
pavel06081991 2019-01-14 14:05:52 +03:00 committed by GitHub
parent a944705110
commit abc3815fd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 18 deletions

View file

@ -122,8 +122,8 @@ export function estimateBucketSpanFactory(callWithRequest, server) {
run() {
return new Promise((resolve, reject) => {
if (this.checkers.length === 0) {
console.log('BucketSpanEstimator: run has stopped because no checks where created');
reject('BucketSpanEstimator: run has stopped because no checks where created');
console.log('BucketSpanEstimator: run has stopped because no checks were created');
reject('BucketSpanEstimator: run has stopped because no checks were created');
}
this.polledDataChecker.run()

View file

@ -5,6 +5,7 @@
*/
import { i18n } from '@kbn/i18n';
import { JOB_STATE, DATAFEED_STATE } from '../../../common/constants/states';
import { fillResultsWithTimeouts, isRequestTimeout } from './error_utils';
@ -51,7 +52,9 @@ export function datafeedsProvider(callWithRequest) {
results[datafeedId] = { started: false, error };
}
} else {
results[datafeedId] = { started: false, error: 'Job has no datafeed' };
results[datafeedId] = { started: false, error: i18n.translate('xpack.ml.models.jobService.jobHasNoDatafeedErrorMessage', {
defaultMessage: 'Job has no datafeed',
}) };
}
}

View file

@ -5,6 +5,7 @@
*/
import { i18n } from '@kbn/i18n';
import { JOB_STATE, DATAFEED_STATE } from '../../../common/constants/states';
const REQUEST_TIMEOUT = 'RequestTimeout';
@ -17,13 +18,23 @@ export function isRequestTimeout(error) {
// for the ids which haven't already been set
export function fillResultsWithTimeouts(results, id, ids, status) {
const action = getAction(status);
const extra = ((ids.length - Object.keys(results).length) > 1) ? ' All other requests cancelled.' : '';
const extra = ((ids.length - Object.keys(results).length) > 1) ?
i18n.translate('xpack.ml.models.jobService.allOtherRequestsCancelledDescription', {
defaultMessage: ' All other requests cancelled.',
}) : '';
const error = {
response: {
error: {
root_cause: [{
reason: `Request to ${action} '${id}' timed out.${extra}`
reason: i18n.translate('xpack.ml.models.jobService.requestToActionTimedOutErrorMessage', {
defaultMessage: `Request to {action} '{id}' timed out.{extra}`,
values: {
id,
action,
extra,
},
})
}]
}
}

View file

@ -6,6 +6,7 @@
import { i18n } from '@kbn/i18n';
import Boom from 'boom';
import { fieldsServiceProvider } from '../fields_service';
@ -23,22 +24,34 @@ import { validateTimeRange, isValidTimeField } from './validate_time_range';
export async function validateJob(callWithRequest, payload, kbnVersion = 'current', server) {
try {
if (typeof payload !== 'object' || payload === null) {
throw new Error('Invalid payload: Needs to be an object.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.payloadIsNotObjectErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be an object.',
values: { invalidParamName: 'payload' },
}));
}
const { fields, job } = payload;
let { duration } = payload;
if (typeof job !== 'object') {
throw new Error('Invalid job: Needs to be an object.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.jobIsNotObjectErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be an object.',
values: { invalidParamName: 'job' },
}));
}
if (typeof job.analysis_config !== 'object') {
throw new Error('Invalid job.analysis_config: Needs to be an object.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.analysisConfigIsNotObjectErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be an object.',
values: { invalidParamName: 'job.analysis_config' },
}));
}
if (!Array.isArray(job.analysis_config.detectors)) {
throw new Error('Invalid job.analysis_config.detectors: Needs to be an array.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.detectorsAreNotArrayErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be an array.',
values: { invalidParamName: 'job.analysis_config.detectors' },
}));
}
// check if basic tests pass the requirements to run the extended tests.
@ -118,7 +131,10 @@ export async function validateJob(callWithRequest, payload, kbnVersion = 'curren
message.status = VALIDATION_STATUS[messages[message.id].status];
} else {
message.text = `${message.id} (unknown message id)`;
message.text = i18n.translate('xpack.ml.models.jobValidation.unknownMessageIdErrorMessage', {
defaultMessage: '{messageId} (unknown message id)',
values: { messageId: message.id },
});
}
return message;

View file

@ -5,31 +5,56 @@
*/
import { i18n } from '@kbn/i18n';
export function validateJobObject(job) {
if (job === null || typeof job !== 'object') {
throw new Error('Invalid job: Needs to be an object.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.validateJobObject.jobIsNotObjectErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be an object.',
values: { invalidParamName: 'job' },
}));
}
if (job.analysis_config === null || typeof job.analysis_config !== 'object') {
throw new Error('Invalid analysis_config: Needs to be an object.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.validateJobObject.analysisConfigIsNotObjectErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be an object.',
values: { invalidParamName: 'job.analysis_config' },
}));
}
if (!Array.isArray(job.analysis_config.influencers)) {
throw new Error('Invalid job.analysis_config.influencers: Needs to be an array.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.validateJobObject.influencersAreNotArrayErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be an array.',
values: { invalidParamName: 'job.analysis_config.influencers' },
}));
}
if (!Array.isArray(job.analysis_config.detectors)) {
throw new Error('Invalid job.analysis_config.detectors: Needs to be an array.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.validateJobObject.detectorsAreNotArrayErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be an array.',
values: { invalidParamName: 'job.analysis_config.detectors' },
}));
}
if (job.datafeed_config === null || typeof job.datafeed_config !== 'object') {
throw new Error('Invalid datafeed_config: Needs to be an object.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.validateJobObject.datafeedConfigIsNotObjectErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be an object.',
values: { invalidParamName: 'job.datafeed_config' },
}));
}
if (!Array.isArray(job.datafeed_config.indices)) {
throw new Error('Invalid indices: Needs to be an Array.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.validateJobObject.indicesAreNotArrayErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be an Array.',
values: { invalidParamName: 'job.datafeed_config.indices' },
}));
}
if (job.data_description === null || typeof job.data_description !== 'object') {
throw new Error('Invalid data_description: Needs to be an object.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.validateJobObject.dataDescriptionIsNotObjectErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be an object.',
values: { invalidParamName: 'job.data_description' },
}));
}
if (typeof job.data_description.time_field !== 'string') {
throw new Error('Invalid time_field: Needs to be a string.');
throw new Error(i18n.translate('xpack.ml.models.jobValidation.validateJobObject.timeFieldIsNotStringErrorMessage', {
defaultMessage: 'Invalid {invalidParamName}: Needs to be a string.',
values: { invalidParamName: 'job.data_description.time_field' },
}));
}
}