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 all 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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

This file was deleted.

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';
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>;
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>;
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';
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';
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>;
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../../../..',
roots: ['<rootDir>/src/platform/packages/private/response-ops/rule_params'],
roots: ['<rootDir>/src/platform/packages/shared/response-ops/rule_params'],
};
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"
}
10 changes: 10 additions & 0 deletions src/platform/packages/shared/response-ops/rule_params/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';
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';
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';
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>;
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';
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';
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>;
Original file line number Diff line number Diff line change
@@ -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"]
}
4 changes: 2 additions & 2 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
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 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,
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
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading
Loading