mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
[ResponseOps][Rules] Create the rule params package (#196971)
## Summary This PR creates a package containing the schema of the params of all rule types. It starts as `schema.recordOf(schema.string(), schema.maybe(schema.any()))` which is the current one. In subsequent PRs, the schema will be updated to `schema.oneOf([apmRuleType, esQueryRuleType, ....])`. I also substituted the definition of `params` in the alerting plugin with the `params` exported from the package. Towards: https://github.com/elastic/kibana/issues/187356 Fixes: https://github.com/elastic/kibana/issues/195183 ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels) - [ ] This will appear in the **Release Notes** and follow the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
af139b4038
commit
a7a81c2897
24 changed files with 141 additions and 32 deletions
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
|
@ -729,6 +729,7 @@ packages/kbn-resizable-layout @elastic/kibana-data-discovery
|
|||
examples/resizable_layout_examples @elastic/kibana-data-discovery
|
||||
x-pack/test/plugin_functional/plugins/resolver_test @elastic/security-solution
|
||||
packages/response-ops/feature_flag_service @elastic/response-ops
|
||||
packages/response-ops/rule_params @elastic/response-ops
|
||||
examples/response_stream @elastic/ml-ui
|
||||
packages/kbn-rison @elastic/kibana-operations
|
||||
x-pack/packages/rollup @elastic/kibana-management
|
||||
|
|
|
@ -747,6 +747,7 @@
|
|||
"@kbn/resizable-layout-examples-plugin": "link:examples/resizable_layout_examples",
|
||||
"@kbn/resolver-test-plugin": "link:x-pack/test/plugin_functional/plugins/resolver_test",
|
||||
"@kbn/response-ops-feature-flag-service": "link:packages/response-ops/feature_flag_service",
|
||||
"@kbn/response-ops-rule-params": "link:packages/response-ops/rule_params",
|
||||
"@kbn/response-stream-plugin": "link:examples/response_stream",
|
||||
"@kbn/rison": "link:packages/kbn-rison",
|
||||
"@kbn/rollup": "link:x-pack/packages/rollup",
|
||||
|
|
3
packages/response-ops/rule_params/README.md
Normal file
3
packages/response-ops/rule_params/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# @kbn/response-ops-rule-params
|
||||
|
||||
The package is responsible for the parameters' schema of all rule types. The alerting plugin uses this package to generate OAS documentation for the `params` property in the rule in requests and responses.
|
23
packages/response-ops/rule_params/index.ts
Normal file
23
packages/response-ops/rule_params/index.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* 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 { ruleParamsSchema, ruleParamsSchemaWithDefaultValue } from './latest';
|
||||
|
||||
export {
|
||||
ruleParamsSchema as ruleParamsSchemaV1,
|
||||
ruleParamsSchemaWithDefaultValue as ruleParamsSchemaWithDefaultValueV1,
|
||||
} from './v1';
|
||||
|
||||
export type { RuleParams } from './latest';
|
||||
export type { RuleParamsWithDefaultValue } from './latest';
|
||||
|
||||
export type {
|
||||
RuleParams as RuleParamsV1,
|
||||
RuleParamsWithDefaultValue as RuleParamsWithDefaultValueV1,
|
||||
} from './v1';
|
14
packages/response-ops/rule_params/jest.config.js
Normal file
14
packages/response-ops/rule_params/jest.config.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* 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".
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
preset: '@kbn/test/jest_node',
|
||||
rootDir: '../../..',
|
||||
roots: ['<rootDir>/packages/response-ops/rule_params'],
|
||||
};
|
5
packages/response-ops/rule_params/kibana.jsonc
Normal file
5
packages/response-ops/rule_params/kibana.jsonc
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"type": "shared-common",
|
||||
"id": "@kbn/response-ops-rule-params",
|
||||
"owner": "@elastic/response-ops"
|
||||
}
|
10
packages/response-ops/rule_params/latest.ts
Normal file
10
packages/response-ops/rule_params/latest.ts
Normal file
|
@ -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';
|
6
packages/response-ops/rule_params/package.json
Normal file
6
packages/response-ops/rule_params/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "@kbn/response-ops-rule-params",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0"
|
||||
}
|
19
packages/response-ops/rule_params/tsconfig.json
Normal file
19
packages/response-ops/rule_params/tsconfig.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "target/types",
|
||||
"types": [
|
||||
"jest",
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
],
|
||||
"exclude": [
|
||||
"target/**/*"
|
||||
],
|
||||
"kbn_references": [
|
||||
"@kbn/config-schema",
|
||||
]
|
||||
}
|
26
packages/response-ops/rule_params/v1.ts
Normal file
26
packages/response-ops/rule_params/v1.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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 { TypeOf, schema } from '@kbn/config-schema';
|
||||
|
||||
export const ruleParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()), {
|
||||
meta: { description: 'The parameters for the rule.' },
|
||||
});
|
||||
|
||||
export const ruleParamsSchemaWithDefaultValue = schema.recordOf(
|
||||
schema.string(),
|
||||
schema.maybe(schema.any()),
|
||||
{
|
||||
defaultValue: {},
|
||||
meta: { description: 'The parameters for the rule.' },
|
||||
}
|
||||
);
|
||||
|
||||
export type RuleParams = TypeOf<typeof ruleParamsSchema>;
|
||||
export type RuleParamsWithDefaultValue = TypeOf<typeof ruleParamsSchemaWithDefaultValue>;
|
|
@ -1452,6 +1452,8 @@
|
|||
"@kbn/resolver-test-plugin/*": ["x-pack/test/plugin_functional/plugins/resolver_test/*"],
|
||||
"@kbn/response-ops-feature-flag-service": ["packages/response-ops/feature_flag_service"],
|
||||
"@kbn/response-ops-feature-flag-service/*": ["packages/response-ops/feature_flag_service/*"],
|
||||
"@kbn/response-ops-rule-params": ["packages/response-ops/rule_params"],
|
||||
"@kbn/response-ops-rule-params/*": ["packages/response-ops/rule_params/*"],
|
||||
"@kbn/response-stream-plugin": ["examples/response_stream"],
|
||||
"@kbn/response-stream-plugin/*": ["examples/response_stream/*"],
|
||||
"@kbn/rison": ["packages/kbn-rison"],
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ruleParamsSchemaV1 } from '@kbn/response-ops-rule-params';
|
||||
import { adHocRunStatus } from '../../../../constants';
|
||||
|
||||
export const statusSchema = schema.oneOf([
|
||||
|
@ -26,7 +27,7 @@ export const backfillResponseSchema = schema.object({
|
|||
name: schema.string(),
|
||||
tags: schema.arrayOf(schema.string()),
|
||||
rule_type_id: schema.string(),
|
||||
params: schema.recordOf(schema.string(), schema.maybe(schema.any())),
|
||||
params: ruleParamsSchemaV1,
|
||||
api_key_owner: schema.nullable(schema.string()),
|
||||
api_key_created_by_user: schema.maybe(schema.nullable(schema.boolean())),
|
||||
consumer: schema.string(),
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ruleParamsSchemaWithDefaultValueV1 } from '@kbn/response-ops-rule-params';
|
||||
import { validateDurationV1, validateHoursV1, validateTimezoneV1 } from '../../../validation';
|
||||
import { notifyWhenSchemaV1, alertDelaySchemaV1 } from '../../../response';
|
||||
import { alertsFilterQuerySchemaV1 } from '../../../../alerts_filter_query';
|
||||
|
@ -166,10 +167,7 @@ export const createBodySchema = schema.object({
|
|||
})
|
||||
)
|
||||
),
|
||||
params: schema.recordOf(schema.string(), schema.maybe(schema.any()), {
|
||||
defaultValue: {},
|
||||
meta: { description: 'The parameters for the rule.' },
|
||||
}),
|
||||
params: ruleParamsSchemaWithDefaultValueV1,
|
||||
schedule: schema.object(
|
||||
{
|
||||
interval: schema.string({
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ruleParamsSchemaWithDefaultValueV1 } from '@kbn/response-ops-rule-params';
|
||||
import { validateDurationV1, validateHoursV1, validateTimezoneV1 } from '../../../validation';
|
||||
import { notifyWhenSchemaV1, alertDelaySchemaV1 } from '../../../response';
|
||||
import { alertsFilterQuerySchemaV1 } from '../../../../alerts_filter_query';
|
||||
|
@ -152,10 +153,7 @@ export const updateBodySchema = schema.object({
|
|||
})
|
||||
)
|
||||
),
|
||||
params: schema.recordOf(schema.string(), schema.any(), {
|
||||
defaultValue: {},
|
||||
meta: { description: 'The parameters for the rule.' },
|
||||
}),
|
||||
params: ruleParamsSchemaWithDefaultValueV1,
|
||||
actions: schema.arrayOf(actionSchema, { defaultValue: [] }),
|
||||
notify_when: schema.maybe(schema.nullable(notifyWhenSchemaV1)),
|
||||
alert_delay: schema.maybe(alertDelaySchemaV1),
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
export {
|
||||
ruleParamsSchema,
|
||||
actionParamsSchema,
|
||||
mappedParamsSchema,
|
||||
ruleExecutionStatusSchema,
|
||||
|
@ -18,16 +17,9 @@ export {
|
|||
scheduleIdsSchema,
|
||||
} from './schemas/latest';
|
||||
|
||||
export type {
|
||||
RuleParams,
|
||||
RuleResponse,
|
||||
RuleSnoozeSchedule,
|
||||
RuleLastRun,
|
||||
Monitoring,
|
||||
} from './types/latest';
|
||||
export type { RuleResponse, RuleSnoozeSchedule, RuleLastRun, Monitoring } from './types/latest';
|
||||
|
||||
export {
|
||||
ruleParamsSchema as ruleParamsSchemaV1,
|
||||
actionParamsSchema as actionParamsSchemaV1,
|
||||
mappedParamsSchema as mappedParamsSchemaV1,
|
||||
ruleExecutionStatusSchema as ruleExecutionStatusSchemaV1,
|
||||
|
@ -41,9 +33,14 @@ export {
|
|||
} from './schemas/v1';
|
||||
|
||||
export type {
|
||||
RuleParams as RuleParamsV1,
|
||||
RuleResponse as RuleResponseV1,
|
||||
RuleSnoozeSchedule as RuleSnoozeScheduleV1,
|
||||
RuleLastRun as RuleLastRunV1,
|
||||
Monitoring as MonitoringV1,
|
||||
} from './types/v1';
|
||||
|
||||
export { ruleParamsSchemaV1 } from '@kbn/response-ops-rule-params';
|
||||
export { ruleParamsSchema } from '@kbn/response-ops-rule-params';
|
||||
|
||||
export type { RuleParamsV1 } from '@kbn/response-ops-rule-params';
|
||||
export type { RuleParams } from '@kbn/response-ops-rule-params';
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ruleParamsSchemaV1 } from '@kbn/response-ops-rule-params';
|
||||
import { rRuleResponseSchemaV1 } from '../../../r_rule';
|
||||
import { alertsFilterQuerySchemaV1 } from '../../../alerts_filter_query';
|
||||
import {
|
||||
|
@ -18,9 +19,6 @@ import {
|
|||
import { validateNotifyWhenV1 } from '../../validation';
|
||||
import { flappingSchemaV1 } from '../../common';
|
||||
|
||||
export const ruleParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()), {
|
||||
meta: { description: 'The parameters for the rule.' },
|
||||
});
|
||||
export const actionParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()), {
|
||||
meta: {
|
||||
description:
|
||||
|
@ -497,7 +495,7 @@ export const ruleResponseSchema = schema.object({
|
|||
}),
|
||||
schedule: intervalScheduleSchema,
|
||||
actions: schema.arrayOf(actionSchema),
|
||||
params: ruleParamsSchema,
|
||||
params: ruleParamsSchemaV1,
|
||||
mapped_params: schema.maybe(mappedParamsSchema),
|
||||
scheduled_task_id: schema.maybe(
|
||||
schema.string({
|
||||
|
|
|
@ -6,22 +6,21 @@
|
|||
*/
|
||||
|
||||
import type { TypeOf } from '@kbn/config-schema';
|
||||
import { RuleParamsV1 } from '@kbn/response-ops-rule-params';
|
||||
import {
|
||||
ruleParamsSchemaV1,
|
||||
ruleResponseSchemaV1,
|
||||
ruleSnoozeScheduleSchemaV1,
|
||||
ruleLastRunSchemaV1,
|
||||
monitoringSchemaV1,
|
||||
} from '..';
|
||||
|
||||
export type RuleParams = TypeOf<typeof ruleParamsSchemaV1>;
|
||||
export type RuleSnoozeSchedule = TypeOf<typeof ruleSnoozeScheduleSchemaV1>;
|
||||
export type RuleLastRun = TypeOf<typeof ruleLastRunSchemaV1>;
|
||||
export type Monitoring = TypeOf<typeof monitoringSchemaV1>;
|
||||
|
||||
type RuleResponseSchemaType = TypeOf<typeof ruleResponseSchemaV1>;
|
||||
|
||||
export interface RuleResponse<Params extends RuleParams = never> {
|
||||
export interface RuleResponse<Params extends RuleParamsV1 = never> {
|
||||
id: RuleResponseSchemaType['id'];
|
||||
enabled: RuleResponseSchemaType['enabled'];
|
||||
name: RuleResponseSchemaType['name'];
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ruleParamsSchema } from '@kbn/response-ops-rule-params';
|
||||
import { adHocRunStatus } from '../../../../../common/constants';
|
||||
|
||||
export const statusSchema = schema.oneOf([
|
||||
|
@ -32,7 +33,7 @@ export const backfillSchema = schema.object({
|
|||
name: schema.string(),
|
||||
tags: schema.arrayOf(schema.string()),
|
||||
alertTypeId: schema.string(),
|
||||
params: schema.recordOf(schema.string(), schema.maybe(schema.any())),
|
||||
params: ruleParamsSchema,
|
||||
apiKeyOwner: schema.nullable(schema.string()),
|
||||
apiKeyCreatedByUser: schema.maybe(schema.nullable(schema.boolean())),
|
||||
consumer: schema.string(),
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ruleParamsSchemaWithDefaultValue } from '@kbn/response-ops-rule-params';
|
||||
import { validateDuration } from '../../../validation';
|
||||
import {
|
||||
notifyWhenSchema,
|
||||
|
@ -23,7 +24,7 @@ export const createRuleDataSchema = schema.object(
|
|||
consumer: schema.string(),
|
||||
tags: schema.arrayOf(schema.string(), { defaultValue: [] }),
|
||||
throttle: schema.maybe(schema.nullable(schema.string({ validate: validateDuration }))),
|
||||
params: schema.recordOf(schema.string(), schema.maybe(schema.any()), { defaultValue: {} }),
|
||||
params: ruleParamsSchemaWithDefaultValue,
|
||||
schedule: schema.object({
|
||||
interval: schema.string({ validate: validateDuration }),
|
||||
}),
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ruleParamsSchemaWithDefaultValue } from '@kbn/response-ops-rule-params';
|
||||
import { validateDuration } from '../../../validation';
|
||||
import {
|
||||
notifyWhenSchema,
|
||||
|
@ -23,7 +24,7 @@ export const updateRuleDataSchema = schema.object(
|
|||
interval: schema.string({ validate: validateDuration }),
|
||||
}),
|
||||
throttle: schema.maybe(schema.nullable(schema.string({ validate: validateDuration }))),
|
||||
params: schema.recordOf(schema.string(), schema.maybe(schema.any()), { defaultValue: {} }),
|
||||
params: ruleParamsSchemaWithDefaultValue,
|
||||
actions: schema.arrayOf(actionRequestSchema, { defaultValue: [] }),
|
||||
systemActions: schema.maybe(schema.arrayOf(systemActionRequestSchema, { defaultValue: [] })),
|
||||
notifyWhen: schema.maybe(schema.nullable(notifyWhenSchema)),
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ruleParamsSchema } from '@kbn/response-ops-rule-params';
|
||||
import {
|
||||
ruleLastRunOutcomeValues,
|
||||
ruleExecutionStatusValues,
|
||||
|
@ -18,7 +19,6 @@ import { notifyWhenSchema } from './notify_when_schema';
|
|||
import { actionSchema, systemActionSchema } from './action_schemas';
|
||||
import { flappingSchema } from './flapping_schema';
|
||||
|
||||
export const ruleParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()));
|
||||
export const mappedParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()));
|
||||
|
||||
export const intervalScheduleSchema = schema.object({
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { TypeOf } from '@kbn/config-schema';
|
||||
import { ruleParamsSchema } from '@kbn/response-ops-rule-params';
|
||||
import {
|
||||
ruleNotifyWhen,
|
||||
ruleLastRunOutcomeValues,
|
||||
|
@ -14,7 +15,6 @@ import {
|
|||
ruleExecutionStatusWarningReason,
|
||||
} from '../constants';
|
||||
import {
|
||||
ruleParamsSchema,
|
||||
snoozeScheduleSchema,
|
||||
ruleExecutionStatusSchema,
|
||||
ruleLastRunSchema,
|
||||
|
|
|
@ -73,7 +73,8 @@
|
|||
"@kbn/core-security-server",
|
||||
"@kbn/core-http-server",
|
||||
"@kbn/zod",
|
||||
"@kbn/core-saved-objects-base-server-internal"
|
||||
"@kbn/core-saved-objects-base-server-internal",
|
||||
"@kbn/response-ops-rule-params"
|
||||
],
|
||||
"exclude": [
|
||||
"target/**/*"
|
||||
|
|
|
@ -6169,6 +6169,10 @@
|
|||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/response-ops-rule-params@link:packages/response-ops/rule_params":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/response-stream-plugin@link:examples/response_stream":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue