Skip to content

Commit

Permalink
Add ML fields to route schemae
Browse files Browse the repository at this point in the history
* threshold and job id are conditional on type
* makes query and language mutually exclusive with above
  • Loading branch information
rylnd committed Mar 18, 2020
1 parent f692e01 commit 1aa4321
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
references,
note,
version,
anomaly_threshold,
machine_learning_job_id,
} from './schemas';
/* eslint-enable @typescript-eslint/camelcase */

Expand All @@ -49,6 +51,11 @@ import { DEFAULT_MAX_SIGNALS } from '../../../../../common/constants';
* - index is a required field that must exist
*/
export const addPrepackagedRulesSchema = Joi.object({
anomaly_threshold: anomaly_threshold.when('type', {
is: 'machine_learning',
then: Joi.required(),
otherwise: Joi.forbidden(),
}),
description: description.required(),
enabled: enabled.default(false),
false_positives: false_positives.default([]),
Expand All @@ -61,8 +68,21 @@ export const addPrepackagedRulesSchema = Joi.object({
.valid(true),
index: index.required(),
interval: interval.default('5m'),
query: query.allow('').default(''),
language: language.default('kuery'),
query: query.when('type', {
is: 'machine_learning',
then: Joi.forbidden(),
otherwise: query.allow('').default(''),
}),
language: language.when('type', {
is: 'machine_learning',
then: Joi.forbidden(),
otherwise: language.default('kuery'),
}),
machine_learning_job_id: machine_learning_job_id.when('type', {
is: 'machine_learning',
then: Joi.required(),
otherwise: Joi.forbidden(),
}),
saved_id: saved_id.when('type', {
is: 'saved_query',
then: Joi.required(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {
references,
note,
version,
anomaly_threshold,
machine_learning_job_id,
} from './schemas';
/* eslint-enable @typescript-eslint/camelcase */

Expand All @@ -55,6 +57,11 @@ import { DEFAULT_MAX_SIGNALS } from '../../../../../common/constants';
* - updated_by is optional (but ignored in the import code)
*/
export const importRulesSchema = Joi.object({
anomaly_threshold: anomaly_threshold.when('type', {
is: 'machine_learning',
then: Joi.required(),
otherwise: Joi.forbidden(),
}),
id,
description: description.required(),
enabled: enabled.default(true),
Expand All @@ -65,9 +72,22 @@ export const importRulesSchema = Joi.object({
immutable: immutable.default(false).valid(false),
index,
interval: interval.default('5m'),
query: query.allow('').default(''),
language: language.default('kuery'),
query: query.when('type', {
is: 'machine_learning',
then: Joi.forbidden(),
otherwise: query.allow('').default(''),
}),
language: language.when('type', {
is: 'machine_learning',
then: Joi.forbidden(),
otherwise: language.default('kuery'),
}),
output_index,
machine_learning_job_id: machine_learning_job_id.when('type', {
is: 'machine_learning',
then: Joi.required(),
otherwise: Joi.forbidden(),
}),
saved_id: saved_id.when('type', {
is: 'saved_query',
then: Joi.required(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ import {
note,
id,
version,
anomaly_threshold,
machine_learning_job_id,
} from './schemas';
/* eslint-enable @typescript-eslint/camelcase */

export const patchRulesSchema = Joi.object({
anomaly_threshold,
description,
enabled,
false_positives,
Expand All @@ -50,6 +53,7 @@ export const patchRulesSchema = Joi.object({
interval,
query: query.allow(''),
language,
machine_learning_job_id,
output_index,
saved_id,
timeline_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
id,
note,
version,
anomaly_threshold,
machine_learning_job_id,
} from './schemas';
/* eslint-enable @typescript-eslint/camelcase */

Expand All @@ -48,6 +50,11 @@ import { DEFAULT_MAX_SIGNALS } from '../../../../../common/constants';
* - id is on here because you can pass in an id to update using it instead of rule_id.
*/
export const updateRulesSchema = Joi.object({
anomaly_threshold: anomaly_threshold.when('type', {
is: 'machine_learning',
then: Joi.required(),
otherwise: Joi.forbidden(),
}),
description: description.required(),
enabled: enabled.default(true),
id,
Expand All @@ -57,8 +64,21 @@ export const updateRulesSchema = Joi.object({
rule_id,
index,
interval: interval.default('5m'),
query: query.allow('').default(''),
language: language.default('kuery'),
query: query.when('type', {
is: 'machine_learning',
then: Joi.forbidden(),
otherwise: query.allow('').default(''),
}),
language: language.when('type', {
is: 'machine_learning',
then: Joi.forbidden(),
otherwise: language.default('kuery'),
}),
machine_learning_job_id: machine_learning_job_id.when('type', {
is: 'machine_learning',
then: Joi.required(),
otherwise: Joi.forbidden(),
}),
output_index,
saved_id: saved_id.when('type', {
is: 'saved_query',
Expand Down

0 comments on commit 1aa4321

Please sign in to comment.