Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResponseOps][Rules] Move APM rule types params to the @kbn/response-ops-rule-params package #204637

Merged
merged 21 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bdfec09
initial commit
js-jankisalvi Dec 17, 2024
84dbe9b
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Dec 17, 2024
024689e
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Dec 17, 2024
bcdccab
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Dec 17, 2024
93ffacb
set rule params package visibility to shared
js-jankisalvi Dec 18, 2024
9f117f9
Merge branch 'apm-rule-types-package' of https://github.com/js-jankis…
js-jankisalvi Dec 18, 2024
32dd405
Merge remote-tracking branch 'upstream/main' into apm-rule-types-package
js-jankisalvi Dec 18, 2024
d5c1b5c
fix lint
js-jankisalvi Dec 18, 2024
da8f451
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Dec 18, 2024
539132e
update schema names
js-jankisalvi Dec 23, 2024
d83a323
Merge remote-tracking branch 'upstream/main' into apm-rule-types-package
js-jankisalvi Dec 23, 2024
2cf7b29
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Dec 23, 2024
cd5cddc
revert ruleParamsSchema update
js-jankisalvi Dec 23, 2024
b6da21c
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Dec 23, 2024
117c797
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Dec 23, 2024
bd89658
Merge remote-tracking branch 'upstream/main' into apm-rule-types-package
js-jankisalvi Dec 24, 2024
0c1c2ee
Merge remote-tracking branch 'upstream/main' into apm-rule-types-package
js-jankisalvi Jan 2, 2025
e84196b
move rule params package to shared
js-jankisalvi Jan 2, 2025
35e8e62
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Jan 2, 2025
03456f5
Merge remote-tracking branch 'upstream/main' into apm-rule-types-package
js-jankisalvi Jan 2, 2025
12a9e52
lint fix
js-jankisalvi Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,328 changes: 1,230 additions & 98 deletions oas_docs/bundle.json

Large diffs are not rendered by default.

1,328 changes: 1,230 additions & 98 deletions oas_docs/bundle.serverless.json

Large diffs are not rendered by default.

760 changes: 748 additions & 12 deletions oas_docs/output/kibana.serverless.yaml

Large diffs are not rendered by default.

760 changes: 748 additions & 12 deletions oas_docs/output/kibana.yaml

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions packages/response-ops/rule_params/apm_anomaly/index.ts
Original file line number Diff line number Diff line change
@@ -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';
10 changes: 10 additions & 0 deletions packages/response-ops/rule_params/apm_anomaly/latest.ts
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';
40 changes: 40 additions & 0 deletions packages/response-ops/rule_params/apm_anomaly/v1.ts
Original file line number Diff line number Diff line change
@@ -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<typeof anomalyParamsSchema>;
10 changes: 10 additions & 0 deletions packages/response-ops/rule_params/common/index.ts
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 './search_configuration_schema';
Original file line number Diff line number Diff line change
@@ -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<typeof searchConfigurationSchema>;
14 changes: 14 additions & 0 deletions packages/response-ops/rule_params/error_count/index.ts
Original file line number Diff line number Diff line change
@@ -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';
10 changes: 10 additions & 0 deletions packages/response-ops/rule_params/error_count/latest.ts
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';
25 changes: 25 additions & 0 deletions packages/response-ops/rule_params/error_count/v1.ts
Original file line number Diff line number Diff line change
@@ -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<typeof errorCountParamsSchema>;
8 changes: 3 additions & 5 deletions packages/response-ops/rule_params/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -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"
}
"visibility": "shared"
}
14 changes: 14 additions & 0 deletions packages/response-ops/rule_params/transaction_duration/index.ts
Original file line number Diff line number Diff line change
@@ -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';
10 changes: 10 additions & 0 deletions packages/response-ops/rule_params/transaction_duration/latest.ts
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';
37 changes: 37 additions & 0 deletions packages/response-ops/rule_params/transaction_duration/v1.ts
Original file line number Diff line number Diff line change
@@ -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<typeof transactionDurationParamsSchema>;
14 changes: 14 additions & 0 deletions packages/response-ops/rule_params/transaction_error_rate/index.ts
Original file line number Diff line number Diff line change
@@ -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';
10 changes: 10 additions & 0 deletions packages/response-ops/rule_params/transaction_error_rate/latest.ts
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';
26 changes: 26 additions & 0 deletions packages/response-ops/rule_params/transaction_error_rate/v1.ts
Original file line number Diff line number Diff line change
@@ -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<typeof transactionErrorRateParamsSchema>;
17 changes: 4 additions & 13 deletions packages/response-ops/rule_params/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
"types": ["jest", "node"]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/config-schema",
]
"include": ["**/*.ts"],
"exclude": ["target/**/*"],
"kbn_references": ["@kbn/config-schema", "@kbn/ml-anomaly-utils"]
}
16 changes: 13 additions & 3 deletions packages/response-ops/rule_params/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
*/

import { TypeOf, schema } from '@kbn/config-schema';
import { transactionDurationParamsSchema as transactionDurationParamsSchemaV1 } from './transaction_duration/v1';
import { anomalyParamsSchema as anomalyParamsSchemaV1 } from './apm_anomaly/v1';
import { errorCountParamsSchema as errorCountParamsSchemaV1 } from './error_count/v1';
import { transactionErrorRateParamsSchema as transactionErrorRateParamsSchemaV1 } from './transaction_error_rate/v1';

export const ruleParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()), {
meta: { description: 'The parameters for the rule.' },
});
export const ruleParamsSchema = schema.oneOf([
transactionDurationParamsSchemaV1,
anomalyParamsSchemaV1,
errorCountParamsSchemaV1,
transactionErrorRateParamsSchemaV1,
schema.recordOf(schema.string(), schema.maybe(schema.any()), {
meta: { description: 'The parameters for the rule.' },
}),
]);

export const ruleParamsSchemaWithDefaultValue = schema.recordOf(
schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ async function updateRuleAttributesAndParamsInMemory<Params extends RuleParams>(

// 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
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { ErrorCountRuleParams } from '@kbn/response-ops-rule-params/error_count';
import { TransactionDurationRuleParams } from '@kbn/response-ops-rule-params/transaction_duration';
import { AnomalyRuleParams } from '@kbn/response-ops-rule-params/apm_anomaly';
import { TransactionErrorRateRuleParams } from '@kbn/response-ops-rule-params/transaction_error_rate';
import {
ERROR_GROUP_ID,
ERROR_GROUP_NAME,
Expand All @@ -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<ThresholdMetActionGroupId> = {
Expand Down
Loading
Loading