forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ResponseOps] Move custom threshold rule params to the package (elast…
…ic#208686) Fixes: elastic#195191 Move log threshold rule type params to the new package. P.S.: I've moved function `validateKQLStringFilter` and test for it in my previous PR: elastic#205507 --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
3d7ccc5
commit 07557b6
Showing
10 changed files
with
114 additions
and
126 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/platform/packages/shared/response-ops/rule_params/custom_threshold/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
export { customThresholdParamsSchema } from './latest'; | ||
export { customThresholdParamsSchema as customThresholdParamsSchemaV1 } from './v1'; |
10 changes: 10 additions & 0 deletions
10
src/platform/packages/shared/response-ops/rule_params/custom_threshold/latest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
export * from './v1'; |
87 changes: 87 additions & 0 deletions
87
src/platform/packages/shared/response-ops/rule_params/custom_threshold/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
import { COMPARATORS } from '@kbn/alerting-comparators'; | ||
import { dataViewSpecSchema } from '../common'; | ||
import { oneOfLiterals, validateKQLStringFilter, LEGACY_COMPARATORS } from '../common/utils'; | ||
|
||
const allowedAggregators = [ | ||
'avg', | ||
'sum', | ||
'min', | ||
'max', | ||
'cardinality', | ||
'rate', | ||
'p95', | ||
'p99', | ||
'last_value', | ||
]; | ||
|
||
const comparators = Object.values({ ...COMPARATORS, ...LEGACY_COMPARATORS }); | ||
|
||
const searchConfigSchema = schema.object({ | ||
index: schema.oneOf([schema.string(), dataViewSpecSchema]), | ||
query: schema.object({ | ||
language: schema.string(), | ||
query: schema.string({ | ||
validate: validateKQLStringFilter, | ||
}), | ||
}), | ||
filter: schema.maybe( | ||
schema.arrayOf( | ||
schema.object({ | ||
query: schema.maybe(schema.recordOf(schema.string(), schema.any())), | ||
meta: schema.recordOf(schema.string(), schema.any()), | ||
}) | ||
) | ||
), | ||
}); | ||
|
||
const customCriterion = schema.object({ | ||
threshold: schema.arrayOf(schema.number()), | ||
comparator: oneOfLiterals(comparators), | ||
timeUnit: schema.string(), | ||
timeSize: schema.number(), | ||
aggType: schema.maybe(schema.literal('custom')), | ||
metric: schema.never(), | ||
metrics: schema.arrayOf( | ||
schema.oneOf([ | ||
schema.object({ | ||
name: schema.string(), | ||
aggType: oneOfLiterals(allowedAggregators), | ||
field: schema.string(), | ||
filter: schema.never(), | ||
}), | ||
schema.object({ | ||
name: schema.string(), | ||
aggType: schema.literal('count'), | ||
filter: schema.maybe( | ||
schema.string({ | ||
validate: validateKQLStringFilter, | ||
}) | ||
), | ||
field: schema.never(), | ||
}), | ||
]) | ||
), | ||
equation: schema.maybe(schema.string()), | ||
label: schema.maybe(schema.string()), | ||
}); | ||
|
||
export const customThresholdParamsSchema = schema.object( | ||
{ | ||
criteria: schema.arrayOf(customCriterion), | ||
groupBy: schema.maybe(schema.oneOf([schema.string(), schema.arrayOf(schema.string())])), | ||
alertOnNoData: schema.maybe(schema.boolean()), | ||
alertOnGroupDisappear: schema.maybe(schema.boolean()), | ||
searchConfiguration: searchConfigSchema, | ||
}, | ||
{ unknowns: 'allow' } | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters