From 45df04da1b38cf762f3b4ddc85c31f700e33f835 Mon Sep 17 00:00:00 2001 From: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:07:46 +0000 Subject: [PATCH] [ResponseOps][Rules] Move APM rule types params to the @kbn/response-ops-rule-params package (#204637) ## Summary Resolves https://github.com/elastic/kibana/issues/195186 ### Checklist - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .github/CODEOWNERS | 2 +- package.json | 2 +- .../response-ops/rule_params/tsconfig.json | 19 --------- .../response-ops/rule_params/README.md | 0 .../rule_params/apm_anomaly/index.ts | 14 +++++++ .../rule_params/apm_anomaly}/latest.ts | 0 .../rule_params/apm_anomaly/v1.ts | 40 +++++++++++++++++++ .../response-ops/rule_params/common/index.ts | 10 +++++ .../common/search_configuration_schema.ts | 19 +++++++++ .../rule_params/error_count/index.ts | 14 +++++++ .../rule_params/error_count/latest.ts | 10 +++++ .../rule_params/error_count/v1.ts | 25 ++++++++++++ .../response-ops/rule_params/index.ts | 0 .../response-ops/rule_params/jest.config.js | 2 +- .../response-ops/rule_params/kibana.jsonc | 8 ++-- .../shared/response-ops/rule_params/latest.ts | 10 +++++ .../response-ops/rule_params/package.json | 0 .../rule_params/transaction_duration/index.ts | 14 +++++++ .../transaction_duration/latest.ts | 10 +++++ .../rule_params/transaction_duration/v1.ts | 37 +++++++++++++++++ .../transaction_error_rate/index.ts | 14 +++++++ .../transaction_error_rate/latest.ts | 10 +++++ .../rule_params/transaction_error_rate/v1.ts | 26 ++++++++++++ .../response-ops/rule_params/tsconfig.json | 10 +++++ .../response-ops/rule_params/v1.ts | 0 tsconfig.base.json | 4 +- .../rule/methods/bulk_edit/bulk_edit_rules.ts | 2 +- .../apm/common/rules/apm_rule_types.ts | 11 +++++ .../transaction_duration_rule_type/index.tsx | 2 +- .../index.tsx | 2 +- .../anomaly/register_anomaly_rule_type.ts | 8 ++-- .../register_error_count_rule_type.ts | 8 ++-- ...register_transaction_duration_rule_type.ts | 8 ++-- ...gister_transaction_error_rate_rule_type.ts | 8 ++-- .../observability/plugins/apm/tsconfig.json | 3 +- .../services/alerting_api.ts | 2 +- .../alerts/helpers/alerting_api_helper.ts | 3 +- yarn.lock | 2 +- 38 files changed, 311 insertions(+), 48 deletions(-) delete mode 100644 src/platform/packages/private/response-ops/rule_params/tsconfig.json rename src/platform/packages/{private => shared}/response-ops/rule_params/README.md (100%) create mode 100644 src/platform/packages/shared/response-ops/rule_params/apm_anomaly/index.ts rename src/platform/packages/{private/response-ops/rule_params => shared/response-ops/rule_params/apm_anomaly}/latest.ts (100%) create mode 100644 src/platform/packages/shared/response-ops/rule_params/apm_anomaly/v1.ts create mode 100644 src/platform/packages/shared/response-ops/rule_params/common/index.ts create mode 100644 src/platform/packages/shared/response-ops/rule_params/common/search_configuration_schema.ts create mode 100644 src/platform/packages/shared/response-ops/rule_params/error_count/index.ts create mode 100644 src/platform/packages/shared/response-ops/rule_params/error_count/latest.ts create mode 100644 src/platform/packages/shared/response-ops/rule_params/error_count/v1.ts rename src/platform/packages/{private => shared}/response-ops/rule_params/index.ts (100%) rename src/platform/packages/{private => shared}/response-ops/rule_params/jest.config.js (87%) rename src/platform/packages/{private => shared}/response-ops/rule_params/kibana.jsonc (56%) create mode 100644 src/platform/packages/shared/response-ops/rule_params/latest.ts rename src/platform/packages/{private => shared}/response-ops/rule_params/package.json (100%) create mode 100644 src/platform/packages/shared/response-ops/rule_params/transaction_duration/index.ts create mode 100644 src/platform/packages/shared/response-ops/rule_params/transaction_duration/latest.ts create mode 100644 src/platform/packages/shared/response-ops/rule_params/transaction_duration/v1.ts create mode 100644 src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/index.ts create mode 100644 src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/latest.ts create mode 100644 src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/v1.ts create mode 100644 src/platform/packages/shared/response-ops/rule_params/tsconfig.json rename src/platform/packages/{private => shared}/response-ops/rule_params/v1.ts (100%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 35e9af45da3cf..912bb34987171 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -515,7 +515,6 @@ src/platform/packages/private/kbn-repo-packages @elastic/kibana-operations src/platform/packages/private/kbn-ui-shared-deps-npm @elastic/kibana-operations src/platform/packages/private/kbn-ui-shared-deps-src @elastic/kibana-operations src/platform/packages/private/kbn-unsaved-changes-badge @elastic/kibana-data-discovery -src/platform/packages/private/response-ops/rule_params @elastic/response-ops src/platform/packages/shared/deeplinks/analytics @elastic/kibana-data-discovery @elastic/kibana-presentation @elastic/kibana-visualizations src/platform/packages/shared/deeplinks/devtools @elastic/kibana-management src/platform/packages/shared/deeplinks/fleet @elastic/fleet @@ -601,6 +600,7 @@ src/platform/packages/shared/kbn-xstate-utils @elastic/obs-ux-logs-team src/platform/packages/shared/kbn-zod-helpers @elastic/security-detection-rule-management src/platform/packages/shared/presentation/presentation_containers @elastic/kibana-presentation src/platform/packages/shared/presentation/presentation_publishing @elastic/kibana-presentation +src/platform/packages/shared/response-ops/rule_params @elastic/response-ops src/platform/packages/shared/serverless/settings/search_project @elastic/search-kibana @elastic/kibana-management src/platform/packages/shared/serverless/settings/security_project @elastic/security-solution @elastic/kibana-management src/platform/plugins/private/input_control_vis @elastic/kibana-presentation diff --git a/package.json b/package.json index 2497590e9c092..3c7e71ccf9217 100644 --- a/package.json +++ b/package.json @@ -764,7 +764,7 @@ "@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-form": "link:packages/response-ops/rule_form", - "@kbn/response-ops-rule-params": "link:src/platform/packages/private/response-ops/rule_params", + "@kbn/response-ops-rule-params": "link:src/platform/packages/shared/response-ops/rule_params", "@kbn/response-stream-plugin": "link:examples/response_stream", "@kbn/rison": "link:src/platform/packages/shared/kbn-rison", "@kbn/rollup": "link:x-pack/platform/packages/private/rollup", diff --git a/src/platform/packages/private/response-ops/rule_params/tsconfig.json b/src/platform/packages/private/response-ops/rule_params/tsconfig.json deleted file mode 100644 index bd6cfc03c6683..0000000000000 --- a/src/platform/packages/private/response-ops/rule_params/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "extends": "../../../../../../tsconfig.base.json", - "compilerOptions": { - "outDir": "target/types", - "types": [ - "jest", - "node" - ] - }, - "include": [ - "**/*.ts", - ], - "exclude": [ - "target/**/*" - ], - "kbn_references": [ - "@kbn/config-schema", - ] -} diff --git a/src/platform/packages/private/response-ops/rule_params/README.md b/src/platform/packages/shared/response-ops/rule_params/README.md similarity index 100% rename from src/platform/packages/private/response-ops/rule_params/README.md rename to src/platform/packages/shared/response-ops/rule_params/README.md diff --git a/src/platform/packages/shared/response-ops/rule_params/apm_anomaly/index.ts b/src/platform/packages/shared/response-ops/rule_params/apm_anomaly/index.ts new file mode 100644 index 0000000000000..dc6ebfe4ef99e --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/apm_anomaly/index.ts @@ -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". + */ + +export { anomalyParamsSchema } from './latest'; +export { anomalyParamsSchema as anomalyParamsSchemaV1 } from './v1'; + +export type { AnomalyRuleParams } from './latest'; +export type { AnomalyRuleParams as AnomalyRuleParamsV1 } from './v1'; diff --git a/src/platform/packages/private/response-ops/rule_params/latest.ts b/src/platform/packages/shared/response-ops/rule_params/apm_anomaly/latest.ts similarity index 100% rename from src/platform/packages/private/response-ops/rule_params/latest.ts rename to src/platform/packages/shared/response-ops/rule_params/apm_anomaly/latest.ts diff --git a/src/platform/packages/shared/response-ops/rule_params/apm_anomaly/v1.ts b/src/platform/packages/shared/response-ops/rule_params/apm_anomaly/v1.ts new file mode 100644 index 0000000000000..9e550815602a8 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/apm_anomaly/v1.ts @@ -0,0 +1,40 @@ +/* + * 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'; +import { ML_ANOMALY_SEVERITY } from '@kbn/ml-anomaly-utils/anomaly_severity'; + +export enum AnomalyDetectorType { + txLatency = 'txLatency', + txThroughput = 'txThroughput', + txFailureRate = 'txFailureRate', +} + +const detectorsSchema = schema.oneOf([ + schema.literal(AnomalyDetectorType.txLatency), + schema.literal(AnomalyDetectorType.txThroughput), + schema.literal(AnomalyDetectorType.txFailureRate), +]); + +export const anomalyParamsSchema = schema.object({ + serviceName: schema.maybe(schema.string()), + transactionType: schema.maybe(schema.string()), + windowSize: schema.number(), + windowUnit: schema.string(), + environment: schema.string(), + anomalySeverityType: schema.oneOf([ + schema.literal(ML_ANOMALY_SEVERITY.CRITICAL), + schema.literal(ML_ANOMALY_SEVERITY.MAJOR), + schema.literal(ML_ANOMALY_SEVERITY.MINOR), + schema.literal(ML_ANOMALY_SEVERITY.WARNING), + ]), + anomalyDetectorTypes: schema.maybe(schema.arrayOf(detectorsSchema, { minSize: 1 })), +}); + +export type AnomalyRuleParams = TypeOf; diff --git a/src/platform/packages/shared/response-ops/rule_params/common/index.ts b/src/platform/packages/shared/response-ops/rule_params/common/index.ts new file mode 100644 index 0000000000000..4eaa2806a1a10 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/common/index.ts @@ -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 './search_configuration_schema'; diff --git a/src/platform/packages/shared/response-ops/rule_params/common/search_configuration_schema.ts b/src/platform/packages/shared/response-ops/rule_params/common/search_configuration_schema.ts new file mode 100644 index 0000000000000..50b1f3ed1a561 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/common/search_configuration_schema.ts @@ -0,0 +1,19 @@ +/* + * 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 searchConfigurationSchema = schema.object({ + query: schema.object({ + query: schema.oneOf([schema.string(), schema.recordOf(schema.string(), schema.any())]), + language: schema.string(), + }), +}); + +export type SearchConfigurationType = TypeOf; diff --git a/src/platform/packages/shared/response-ops/rule_params/error_count/index.ts b/src/platform/packages/shared/response-ops/rule_params/error_count/index.ts new file mode 100644 index 0000000000000..e14153eb3083f --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/error_count/index.ts @@ -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". + */ + +export { errorCountParamsSchema } from './latest'; +export { errorCountParamsSchema as errorCountParamsSchemaV1 } from './v1'; + +export type { ErrorCountRuleParams } from './latest'; +export type { ErrorCountRuleParams as ErrorCountRuleParamsV1 } from './v1'; diff --git a/src/platform/packages/shared/response-ops/rule_params/error_count/latest.ts b/src/platform/packages/shared/response-ops/rule_params/error_count/latest.ts new file mode 100644 index 0000000000000..f278309c22b03 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/error_count/latest.ts @@ -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'; diff --git a/src/platform/packages/shared/response-ops/rule_params/error_count/v1.ts b/src/platform/packages/shared/response-ops/rule_params/error_count/v1.ts new file mode 100644 index 0000000000000..cbbd6742bf235 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/error_count/v1.ts @@ -0,0 +1,25 @@ +/* + * 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'; +import { searchConfigurationSchema } from '../common/search_configuration_schema'; + +export const errorCountParamsSchema = schema.object({ + windowSize: schema.number(), + windowUnit: schema.string(), + threshold: schema.number(), + serviceName: schema.maybe(schema.string()), + environment: schema.string(), + groupBy: schema.maybe(schema.arrayOf(schema.string())), + errorGroupingKey: schema.maybe(schema.string()), + useKqlFilter: schema.maybe(schema.boolean()), + searchConfiguration: schema.maybe(searchConfigurationSchema), +}); + +export type ErrorCountRuleParams = TypeOf; diff --git a/src/platform/packages/private/response-ops/rule_params/index.ts b/src/platform/packages/shared/response-ops/rule_params/index.ts similarity index 100% rename from src/platform/packages/private/response-ops/rule_params/index.ts rename to src/platform/packages/shared/response-ops/rule_params/index.ts diff --git a/src/platform/packages/private/response-ops/rule_params/jest.config.js b/src/platform/packages/shared/response-ops/rule_params/jest.config.js similarity index 87% rename from src/platform/packages/private/response-ops/rule_params/jest.config.js rename to src/platform/packages/shared/response-ops/rule_params/jest.config.js index 76636c7d4fc78..6df21724dbd84 100644 --- a/src/platform/packages/private/response-ops/rule_params/jest.config.js +++ b/src/platform/packages/shared/response-ops/rule_params/jest.config.js @@ -10,5 +10,5 @@ module.exports = { preset: '@kbn/test/jest_node', rootDir: '../../../../../..', - roots: ['/src/platform/packages/private/response-ops/rule_params'], + roots: ['/src/platform/packages/shared/response-ops/rule_params'], }; diff --git a/src/platform/packages/private/response-ops/rule_params/kibana.jsonc b/src/platform/packages/shared/response-ops/rule_params/kibana.jsonc similarity index 56% rename from src/platform/packages/private/response-ops/rule_params/kibana.jsonc rename to src/platform/packages/shared/response-ops/rule_params/kibana.jsonc index 1315303258949..1bf690c87bfd9 100644 --- a/src/platform/packages/private/response-ops/rule_params/kibana.jsonc +++ b/src/platform/packages/shared/response-ops/rule_params/kibana.jsonc @@ -1,9 +1,7 @@ { "type": "shared-common", "id": "@kbn/response-ops-rule-params", - "owner": [ - "@elastic/response-ops" - ], + "owner": ["@elastic/response-ops"], "group": "platform", - "visibility": "private" -} \ No newline at end of file + "visibility": "shared" +} diff --git a/src/platform/packages/shared/response-ops/rule_params/latest.ts b/src/platform/packages/shared/response-ops/rule_params/latest.ts new file mode 100644 index 0000000000000..f278309c22b03 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/latest.ts @@ -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'; diff --git a/src/platform/packages/private/response-ops/rule_params/package.json b/src/platform/packages/shared/response-ops/rule_params/package.json similarity index 100% rename from src/platform/packages/private/response-ops/rule_params/package.json rename to src/platform/packages/shared/response-ops/rule_params/package.json diff --git a/src/platform/packages/shared/response-ops/rule_params/transaction_duration/index.ts b/src/platform/packages/shared/response-ops/rule_params/transaction_duration/index.ts new file mode 100644 index 0000000000000..baf910d1c033c --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/transaction_duration/index.ts @@ -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". + */ + +export { transactionDurationParamsSchema } from './latest'; +export { transactionDurationParamsSchema as transactionDurationParamsSchemaV1 } from './v1'; + +export type { TransactionDurationRuleParams } from './latest'; +export type { TransactionDurationRuleParams as TransactionDurationRuleParamsV1 } from './v1'; diff --git a/src/platform/packages/shared/response-ops/rule_params/transaction_duration/latest.ts b/src/platform/packages/shared/response-ops/rule_params/transaction_duration/latest.ts new file mode 100644 index 0000000000000..f278309c22b03 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/transaction_duration/latest.ts @@ -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'; diff --git a/src/platform/packages/shared/response-ops/rule_params/transaction_duration/v1.ts b/src/platform/packages/shared/response-ops/rule_params/transaction_duration/v1.ts new file mode 100644 index 0000000000000..ab80398666607 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/transaction_duration/v1.ts @@ -0,0 +1,37 @@ +/* + * 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'; +import { searchConfigurationSchema } from '../common/search_configuration_schema'; + +export enum AggregationType { + Avg = 'avg', + P95 = '95th', + P99 = '99th', +} + +export const transactionDurationParamsSchema = schema.object({ + serviceName: schema.maybe(schema.string()), + transactionType: schema.maybe(schema.string()), + transactionName: schema.maybe(schema.string()), + windowSize: schema.number(), + windowUnit: schema.string(), + threshold: schema.number(), + aggregationType: schema.oneOf([ + schema.literal(AggregationType.Avg), + schema.literal(AggregationType.P95), + schema.literal(AggregationType.P99), + ]), + environment: schema.string(), + groupBy: schema.maybe(schema.arrayOf(schema.string())), + useKqlFilter: schema.maybe(schema.boolean()), + searchConfiguration: schema.maybe(searchConfigurationSchema), +}); + +export type TransactionDurationRuleParams = TypeOf; diff --git a/src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/index.ts b/src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/index.ts new file mode 100644 index 0000000000000..c9630b7347e81 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/index.ts @@ -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". + */ + +export { transactionErrorRateParamsSchema } from './latest'; +export { transactionErrorRateParamsSchema as transactionErrorRateParamsSchemaV1 } from './v1'; + +export type { TransactionErrorRateRuleParams } from './latest'; +export type { TransactionErrorRateRuleParams as TransactionErrorRateRuleParamsV1 } from './v1'; diff --git a/src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/latest.ts b/src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/latest.ts new file mode 100644 index 0000000000000..f278309c22b03 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/latest.ts @@ -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'; diff --git a/src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/v1.ts b/src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/v1.ts new file mode 100644 index 0000000000000..452279d8ddd19 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/transaction_error_rate/v1.ts @@ -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'; +import { searchConfigurationSchema } from '../common/search_configuration_schema'; + +export const transactionErrorRateParamsSchema = schema.object({ + windowSize: schema.number(), + windowUnit: schema.string(), + threshold: schema.number(), + transactionType: schema.maybe(schema.string()), + transactionName: schema.maybe(schema.string()), + serviceName: schema.maybe(schema.string()), + environment: schema.string(), + groupBy: schema.maybe(schema.arrayOf(schema.string())), + useKqlFilter: schema.maybe(schema.boolean()), + searchConfiguration: schema.maybe(searchConfigurationSchema), +}); + +export type TransactionErrorRateRuleParams = TypeOf; diff --git a/src/platform/packages/shared/response-ops/rule_params/tsconfig.json b/src/platform/packages/shared/response-ops/rule_params/tsconfig.json new file mode 100644 index 0000000000000..47b4f90bb2813 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": ["jest", "node"] + }, + "include": ["**/*.ts"], + "exclude": ["target/**/*"], + "kbn_references": ["@kbn/config-schema", "@kbn/ml-anomaly-utils"] +} diff --git a/src/platform/packages/private/response-ops/rule_params/v1.ts b/src/platform/packages/shared/response-ops/rule_params/v1.ts similarity index 100% rename from src/platform/packages/private/response-ops/rule_params/v1.ts rename to src/platform/packages/shared/response-ops/rule_params/v1.ts diff --git a/tsconfig.base.json b/tsconfig.base.json index 0bc6612af95f5..622ffc4fdcd80 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1498,8 +1498,8 @@ "@kbn/response-ops-feature-flag-service/*": ["packages/response-ops/feature_flag_service/*"], "@kbn/response-ops-rule-form": ["packages/response-ops/rule_form"], "@kbn/response-ops-rule-form/*": ["packages/response-ops/rule_form/*"], - "@kbn/response-ops-rule-params": ["src/platform/packages/private/response-ops/rule_params"], - "@kbn/response-ops-rule-params/*": ["src/platform/packages/private/response-ops/rule_params/*"], + "@kbn/response-ops-rule-params": ["src/platform/packages/shared/response-ops/rule_params"], + "@kbn/response-ops-rule-params/*": ["src/platform/packages/shared/response-ops/rule_params/*"], "@kbn/response-stream-plugin": ["examples/response_stream"], "@kbn/response-stream-plugin/*": ["examples/response_stream/*"], "@kbn/rison": ["src/platform/packages/shared/kbn-rison"], diff --git a/x-pack/platform/plugins/shared/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.ts b/x-pack/platform/plugins/shared/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.ts index f7d83545ec193..4ef8a2284c47b 100644 --- a/x-pack/platform/plugins/shared/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.ts +++ b/x-pack/platform/plugins/shared/alerting/server/application/rule/methods/bulk_edit/bulk_edit_rules.ts @@ -513,7 +513,7 @@ async function updateRuleAttributesAndParamsInMemory( // Increment revision if params ended up being modified AND it wasn't already incremented as part of attribute update if ( - shouldIncrementRevision(ruleParams) && + shouldIncrementRevision(ruleParams as Params) && !isParamsUpdateSkipped && rule.attributes.revision === updatedRule.revision ) { diff --git a/x-pack/solutions/observability/plugins/apm/common/rules/apm_rule_types.ts b/x-pack/solutions/observability/plugins/apm/common/rules/apm_rule_types.ts index 151e7db67f52e..d1629348a4e23 100644 --- a/x-pack/solutions/observability/plugins/apm/common/rules/apm_rule_types.ts +++ b/x-pack/solutions/observability/plugins/apm/common/rules/apm_rule_types.ts @@ -13,6 +13,10 @@ import { formatDurationFromTimeUnitChar } from '@kbn/observability-plugin/common import { ML_ANOMALY_SEVERITY } from '@kbn/ml-anomaly-utils/anomaly_severity'; import { ML_ANOMALY_THRESHOLD } from '@kbn/ml-anomaly-utils/anomaly_threshold'; import { ApmRuleType } from '@kbn/rule-data-utils'; +import type { ErrorCountRuleParams } from '@kbn/response-ops-rule-params/error_count'; +import type { TransactionDurationRuleParams } from '@kbn/response-ops-rule-params/transaction_duration'; +import type { AnomalyRuleParams } from '@kbn/response-ops-rule-params/apm_anomaly'; +import type { TransactionErrorRateRuleParams } from '@kbn/response-ops-rule-params/transaction_error_rate'; import { ERROR_GROUP_ID, ERROR_GROUP_NAME, @@ -32,6 +36,13 @@ export enum AggregationType { P99 = '99th', } +export interface ApmRuleParamsType { + [ApmRuleType.TransactionDuration]: TransactionDurationRuleParams; + [ApmRuleType.ErrorCount]: ErrorCountRuleParams; + [ApmRuleType.Anomaly]: AnomalyRuleParams; + [ApmRuleType.TransactionErrorRate]: TransactionErrorRateRuleParams; +} + export const THRESHOLD_MET_GROUP_ID = 'threshold_met'; export type ThresholdMetActionGroupId = typeof THRESHOLD_MET_GROUP_ID; export const THRESHOLD_MET_GROUP: ActionGroup = { diff --git a/x-pack/solutions/observability/plugins/apm/public/components/alerting/rule_types/transaction_duration_rule_type/index.tsx b/x-pack/solutions/observability/plugins/apm/public/components/alerting/rule_types/transaction_duration_rule_type/index.tsx index 1c8e3de75cc0c..2b4f0c4e354c6 100644 --- a/x-pack/solutions/observability/plugins/apm/public/components/alerting/rule_types/transaction_duration_rule_type/index.tsx +++ b/x-pack/solutions/observability/plugins/apm/public/components/alerting/rule_types/transaction_duration_rule_type/index.tsx @@ -15,7 +15,7 @@ import { ForLastExpression, TIME_UNITS } from '@kbn/triggers-actions-ui-plugin/p import { EuiFormRow } from '@elastic/eui'; import { EuiSpacer } from '@elastic/eui'; import type { EuiSwitchEvent } from '@elastic/eui'; -import type { SearchConfigurationType } from '../../../../../common/rules/schema'; +import type { SearchConfigurationType } from '@kbn/response-ops-rule-params/common'; import { AggregationType } from '../../../../../common/rules/apm_rule_types'; import { ENVIRONMENT_ALL } from '../../../../../common/environment_filter_values'; import { getDurationFormatter } from '../../../../../common/utils/formatters'; diff --git a/x-pack/solutions/observability/plugins/apm/public/components/alerting/rule_types/transaction_error_rate_rule_type/index.tsx b/x-pack/solutions/observability/plugins/apm/public/components/alerting/rule_types/transaction_error_rate_rule_type/index.tsx index c023df1cf9a60..78287c223b1fb 100644 --- a/x-pack/solutions/observability/plugins/apm/public/components/alerting/rule_types/transaction_error_rate_rule_type/index.tsx +++ b/x-pack/solutions/observability/plugins/apm/public/components/alerting/rule_types/transaction_error_rate_rule_type/index.tsx @@ -14,7 +14,7 @@ import { ForLastExpression, TIME_UNITS } from '@kbn/triggers-actions-ui-plugin/p import { EuiFormRow } from '@elastic/eui'; import { EuiSpacer } from '@elastic/eui'; import type { EuiSwitchEvent } from '@elastic/eui'; -import type { SearchConfigurationType } from '../../../../../common/rules/schema'; +import type { SearchConfigurationType } from '@kbn/response-ops-rule-params/common'; import { ENVIRONMENT_ALL } from '../../../../../common/environment_filter_values'; import { asPercent } from '../../../../../common/utils/formatters'; import { FETCH_STATUS, isPending, useFetcher } from '../../../../hooks/use_fetcher'; diff --git a/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.ts b/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.ts index 1bc82029eaf3d..4c3baac28c6a0 100644 --- a/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.ts +++ b/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.ts @@ -36,6 +36,7 @@ import type { ObservabilityApmAlert } from '@kbn/alerts-as-data-utils'; import { addSpaceIdToPath } from '@kbn/spaces-plugin/common'; import { asyncForEach } from '@kbn/std'; import { compact } from 'lodash'; +import { anomalyParamsSchema } from '@kbn/response-ops-rule-params/apm_anomaly'; import { getSeverity } from '../../../../../common/anomaly_detection'; import { PROCESSOR_EVENT, @@ -47,7 +48,10 @@ import { getEnvironmentEsField, getEnvironmentLabel, } from '../../../../../common/environment_filter_values'; -import type { THRESHOLD_MET_GROUP } from '../../../../../common/rules/apm_rule_types'; +import type { + THRESHOLD_MET_GROUP, + ApmRuleParamsType, +} from '../../../../../common/rules/apm_rule_types'; import { ANOMALY_ALERT_SEVERITY_TYPES, APM_SERVER_FEATURE_ID, @@ -61,8 +65,6 @@ import { apmActionVariables } from '../../action_variables'; import type { RegisterRuleDependencies } from '../../register_apm_rule_types'; import { ApmRuleTypeAlertDefinition } from '../../register_apm_rule_types'; import { getServiceGroupFieldsForAnomaly } from './get_service_group_fields_for_anomaly'; -import type { ApmRuleParamsType } from '../../../../../common/rules/schema'; -import { anomalyParamsSchema } from '../../../../../common/rules/schema'; import { getAnomalyDetectorIndex, getAnomalyDetectorType, diff --git a/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.ts b/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.ts index 11156d35e0c6f..e0670fc7c1667 100644 --- a/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.ts +++ b/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.ts @@ -32,6 +32,7 @@ import type { ObservabilityApmAlert } from '@kbn/alerts-as-data-utils'; import { getParsedFilterQuery, termQuery } from '@kbn/observability-plugin/server'; import { addSpaceIdToPath } from '@kbn/spaces-plugin/common'; import { asyncForEach } from '@kbn/std'; +import { errorCountParamsSchema } from '@kbn/response-ops-rule-params/error_count'; import { getEnvironmentEsField } from '../../../../../common/environment_filter_values'; import { ERROR_GROUP_ID, @@ -39,14 +40,15 @@ import { SERVICE_ENVIRONMENT, SERVICE_NAME, } from '../../../../../common/es_fields/apm'; -import type { THRESHOLD_MET_GROUP } from '../../../../../common/rules/apm_rule_types'; +import type { + THRESHOLD_MET_GROUP, + ApmRuleParamsType, +} from '../../../../../common/rules/apm_rule_types'; import { APM_SERVER_FEATURE_ID, formatErrorCountReason, RULE_TYPES_CONFIG, } from '../../../../../common/rules/apm_rule_types'; -import type { ApmRuleParamsType } from '../../../../../common/rules/schema'; -import { errorCountParamsSchema } from '../../../../../common/rules/schema'; import { environmentQuery } from '../../../../../common/utils/environment_query'; import { getAlertUrlErrorCount } from '../../../../../common/utils/formatters'; import { apmActionVariables } from '../../action_variables'; diff --git a/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/transaction_duration/register_transaction_duration_rule_type.ts b/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/transaction_duration/register_transaction_duration_rule_type.ts index 1c8db86e9baf6..7d1af451d54ce 100644 --- a/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/transaction_duration/register_transaction_duration_rule_type.ts +++ b/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/transaction_duration/register_transaction_duration_rule_type.ts @@ -33,6 +33,7 @@ import { } from '@kbn/rule-data-utils'; import type { ObservabilityApmAlert } from '@kbn/alerts-as-data-utils'; import { addSpaceIdToPath } from '@kbn/spaces-plugin/common'; +import { transactionDurationParamsSchema } from '@kbn/response-ops-rule-params/transaction_duration'; import { getGroupByTerms } from '../utils/get_groupby_terms'; import { SearchAggregatedTransactionSetting } from '../../../../../common/aggregated_transactions'; import { getEnvironmentEsField } from '../../../../../common/environment_filter_values'; @@ -43,14 +44,15 @@ import { TRANSACTION_NAME, TRANSACTION_TYPE, } from '../../../../../common/es_fields/apm'; -import type { THRESHOLD_MET_GROUP } from '../../../../../common/rules/apm_rule_types'; +import type { + THRESHOLD_MET_GROUP, + ApmRuleParamsType, +} from '../../../../../common/rules/apm_rule_types'; import { APM_SERVER_FEATURE_ID, formatTransactionDurationReason, RULE_TYPES_CONFIG, } from '../../../../../common/rules/apm_rule_types'; -import type { ApmRuleParamsType } from '../../../../../common/rules/schema'; -import { transactionDurationParamsSchema } from '../../../../../common/rules/schema'; import { environmentQuery } from '../../../../../common/utils/environment_query'; import { getAlertUrlTransaction, diff --git a/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.ts b/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.ts index 4217d32934a54..f2a1c633dc4dd 100644 --- a/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.ts +++ b/x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.ts @@ -33,6 +33,7 @@ import { import type { ObservabilityApmAlert } from '@kbn/alerts-as-data-utils'; import { addSpaceIdToPath } from '@kbn/spaces-plugin/common'; import { asyncForEach } from '@kbn/std'; +import { transactionErrorRateParamsSchema } from '@kbn/response-ops-rule-params/transaction_error_rate'; import { SearchAggregatedTransactionSetting } from '../../../../../common/aggregated_transactions'; import { getEnvironmentEsField } from '../../../../../common/environment_filter_values'; import { @@ -44,14 +45,15 @@ import { TRANSACTION_NAME, } from '../../../../../common/es_fields/apm'; import { EventOutcome } from '../../../../../common/event_outcome'; -import type { THRESHOLD_MET_GROUP } from '../../../../../common/rules/apm_rule_types'; +import type { + THRESHOLD_MET_GROUP, + ApmRuleParamsType, +} from '../../../../../common/rules/apm_rule_types'; import { APM_SERVER_FEATURE_ID, formatTransactionErrorRateReason, RULE_TYPES_CONFIG, } from '../../../../../common/rules/apm_rule_types'; -import type { ApmRuleParamsType } from '../../../../../common/rules/schema'; -import { transactionErrorRateParamsSchema } from '../../../../../common/rules/schema'; import { environmentQuery } from '../../../../../common/utils/environment_query'; import { asDecimalOrInteger, getAlertUrlTransaction } from '../../../../../common/utils/formatters'; import { getBackwardCompatibleDocumentTypeFilter } from '../../../../lib/helpers/transactions'; diff --git a/x-pack/solutions/observability/plugins/apm/tsconfig.json b/x-pack/solutions/observability/plugins/apm/tsconfig.json index 8f5c804c267a7..6d3bdcb18df55 100644 --- a/x-pack/solutions/observability/plugins/apm/tsconfig.json +++ b/x-pack/solutions/observability/plugins/apm/tsconfig.json @@ -130,7 +130,8 @@ "@kbn/saved-search-component", "@kbn/saved-search-plugin", "@kbn/charts-theme", - "@kbn/entityManager-plugin", + "@kbn/response-ops-rule-params", + "@kbn/entityManager-plugin" ], "exclude": ["target/**/*"] } diff --git a/x-pack/test/api_integration/deployment_agnostic/services/alerting_api.ts b/x-pack/test/api_integration/deployment_agnostic/services/alerting_api.ts index 7a5cff10d58b1..f75f5d297c740 100644 --- a/x-pack/test/api_integration/deployment_agnostic/services/alerting_api.ts +++ b/x-pack/test/api_integration/deployment_agnostic/services/alerting_api.ts @@ -8,10 +8,10 @@ import type { AggregationsAggregate, SearchResponse } from '@elastic/elasticsearch/lib/api/types'; import { MetricThresholdParams } from '@kbn/infra-plugin/common/alerting/metrics'; import { ThresholdParams } from '@kbn/observability-plugin/common/custom_threshold_rule/types'; -import { ApmRuleParamsType } from '@kbn/apm-plugin/common/rules/schema'; import { RoleCredentials } from '@kbn/ftr-common-functional-services'; import { errors, type Client } from '@elastic/elasticsearch'; import type { TryWithRetriesOptions } from '@kbn/ftr-common-functional-services'; +import { ApmRuleParamsType } from '@kbn/apm-plugin/common/rules/apm_rule_types'; import { v4 as uuidv4 } from 'uuid'; import moment from 'moment'; import { DeploymentAgnosticFtrProviderContext } from '../ftr_provider_context'; diff --git a/x-pack/test/apm_api_integration/tests/alerts/helpers/alerting_api_helper.ts b/x-pack/test/apm_api_integration/tests/alerts/helpers/alerting_api_helper.ts index 86544981bbdb4..69d3664e38679 100644 --- a/x-pack/test/apm_api_integration/tests/alerts/helpers/alerting_api_helper.ts +++ b/x-pack/test/apm_api_integration/tests/alerts/helpers/alerting_api_helper.ts @@ -7,10 +7,11 @@ import { Client, errors } from '@elastic/elasticsearch'; import { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common'; +import { ApmRuleParamsType } from '@kbn/apm-plugin/common/rules/apm_rule_types'; import pRetry from 'p-retry'; import type { Agent as SuperTestAgent } from 'supertest'; import { ApmRuleType } from '@kbn/rule-data-utils'; -import { ApmRuleParamsType } from '@kbn/apm-plugin/common/rules/schema'; + import { ObservabilityApmAlert } from '@kbn/alerts-as-data-utils'; import { APM_ACTION_VARIABLE_INDEX, diff --git a/yarn.lock b/yarn.lock index 31c07c7b76545..711ddeebe5966 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6813,7 +6813,7 @@ version "0.0.0" uid "" -"@kbn/response-ops-rule-params@link:src/platform/packages/private/response-ops/rule_params": +"@kbn/response-ops-rule-params@link:src/platform/packages/shared/response-ops/rule_params": version "0.0.0" uid ""