Skip to content

Commit

Permalink
[ML] New Platform server shim: update anomaly detectors routes to use…
Browse files Browse the repository at this point in the history
… new platform router (#56717)

* update job routes to NP

* call notify.error properly on mlMessageBarService

* add route documentation annotation to job routes

* update schema and route doc

* update apidoc file with routes
  • Loading branch information
alvarezmelissa87 committed Feb 6, 2020
1 parent 981f53c commit 70ec649
Show file tree
Hide file tree
Showing 5 changed files with 574 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class JobService {
return { success: true };
})
.catch(err => {
msgs.error(
msgs.notify.error(
i18n.translate('xpack.ml.jobService.couldNotUpdateJobErrorMessage', {
defaultMessage: 'Could not update job: {jobId}',
values: { jobId },
Expand All @@ -435,7 +435,7 @@ class JobService {
return { success: true, messages };
})
.catch(err => {
msgs.error(
msgs.notify.error(
i18n.translate('xpack.ml.jobService.jobValidationErrorMessage', {
defaultMessage: 'Job Validation Error: {errorMessage}',
values: { errorMessage: err.message },
Expand Down Expand Up @@ -628,7 +628,7 @@ class JobService {
return { success: true };
})
.catch(err => {
msgs.error(
msgs.notify.error(
i18n.translate('xpack.ml.jobService.couldNotUpdateDatafeedErrorMessage', {
defaultMessage: 'Could not update datafeed: {datafeedId}',
values: { datafeedId },
Expand Down Expand Up @@ -659,7 +659,7 @@ class JobService {
})
.catch(err => {
console.log('jobService error starting datafeed:', err);
msgs.error(
msgs.notify.error(
i18n.translate('xpack.ml.jobService.couldNotStartDatafeedErrorMessage', {
defaultMessage: 'Could not start datafeed for {jobId}',
values: { jobId },
Expand Down Expand Up @@ -692,15 +692,15 @@ class JobService {
);

if (err.statusCode === 500) {
msgs.error(couldNotStopDatafeedErrorMessage);
msgs.error(
msgs.notify.error(couldNotStopDatafeedErrorMessage);
msgs.notify.error(
i18n.translate('xpack.ml.jobService.requestMayHaveTimedOutErrorMessage', {
defaultMessage:
'Request may have timed out and may still be running in the background.',
})
);
} else {
msgs.error(couldNotStopDatafeedErrorMessage, err);
msgs.notify.error(couldNotStopDatafeedErrorMessage, err);
}
reject(err);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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.
*/

import { schema } from '@kbn/config-schema';

const detectorSchema = schema.object({
identifier: schema.maybe(schema.string()),
function: schema.string(),
field_name: schema.maybe(schema.string()),
by_field_name: schema.maybe(schema.string()),
over_field_name: schema.maybe(schema.string()),
partition_field_name: schema.maybe(schema.string()),
detector_description: schema.maybe(schema.string()),
});

const customUrlSchema = {
url_name: schema.string(),
url_value: schema.string(),
time_range: schema.maybe(schema.any()),
};

const customSettingsSchema = schema.object({
created_by: schema.maybe(schema.string()),
custom_urls: schema.maybe(schema.arrayOf(schema.maybe(schema.object({ ...customUrlSchema })))),
});

export const anomalyDetectionUpdateJobSchema = {
description: schema.maybe(schema.string()),
detectors: schema.maybe(
schema.arrayOf(
schema.maybe(
schema.object({
detector_index: schema.number(),
custom_rules: schema.arrayOf(
schema.maybe(
schema.object({
actions: schema.arrayOf(schema.string()),
conditions: schema.arrayOf(schema.any()),
scope: schema.maybe(schema.any()),
})
)
),
})
)
)
),
custom_settings: schema.maybe(customSettingsSchema),
analysis_limits: schema.object({
categorization_examples_limit: schema.maybe(schema.number()),
model_memory_limit: schema.maybe(schema.string()),
}),
groups: schema.maybe(schema.arrayOf(schema.maybe(schema.string()))),
};

export const anomalyDetectionJobSchema = {
analysis_config: schema.object({
bucket_span: schema.maybe(schema.string()),
summary_count_field_name: schema.maybe(schema.string()),
detectors: schema.arrayOf(detectorSchema),
influencers: schema.arrayOf(schema.maybe(schema.string())),
categorization_field_name: schema.maybe(schema.string()),
}),
analysis_limits: schema.object({
categorization_examples_limit: schema.maybe(schema.number()),
model_memory_limit: schema.maybe(schema.string()),
}),
create_time: schema.maybe(schema.number()),
custom_settings: schema.maybe(customSettingsSchema),
allow_lazy_open: schema.maybe(schema.any()),
data_counts: schema.maybe(schema.any()),
data_description: schema.object({
time_field: schema.string(),
time_format: schema.maybe(schema.string()),
}),
datafeed_config: schema.maybe(schema.any()),
description: schema.maybe(schema.string()),
established_model_memory: schema.maybe(schema.number()),
finished_time: schema.maybe(schema.number()),
job_id: schema.string(),
job_type: schema.maybe(schema.string()),
job_version: schema.maybe(schema.string()),
groups: schema.arrayOf(schema.maybe(schema.string())),
model_plot_config: schema.maybe(schema.any()),
model_size_stats: schema.maybe(schema.any()),
model_snapshot_id: schema.maybe(schema.string()),
model_snapshot_min_version: schema.maybe(schema.string()),
model_snapshot_retention_days: schema.maybe(schema.number()),
results_index_name: schema.maybe(schema.string()),
state: schema.maybe(schema.string()),
};
202 changes: 0 additions & 202 deletions x-pack/legacy/plugins/ml/server/routes/anomaly_detectors.js

This file was deleted.

Loading

0 comments on commit 70ec649

Please sign in to comment.