From b7a5e785512766ae460c21ebcfe9b8dd68970457 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Mon, 13 Sep 2021 17:14:41 +0200 Subject: [PATCH 01/29] [ML] init public code --- .../public/doc_links/doc_links_service.ts | 2 + x-pack/plugins/transform/common/constants.ts | 4 ++ .../transform/common/types/alerting.ts | 13 +++++ x-pack/plugins/transform/kibana.json | 10 +++- .../transform/public/alerting/index.ts | 8 +++ .../alerting/register_alerting_rules.ts | 28 ++++++++++ .../transform_health_rule_type/index.ts | 8 +++ .../register_transform_health_rule.ts | 56 +++++++++++++++++++ .../transform_health_rule_trigger.tsx | 38 +++++++++++++ x-pack/plugins/transform/public/plugin.ts | 12 +++- 10 files changed, 175 insertions(+), 4 deletions(-) create mode 100644 x-pack/plugins/transform/common/types/alerting.ts create mode 100644 x-pack/plugins/transform/public/alerting/index.ts create mode 100644 x-pack/plugins/transform/public/alerting/register_alerting_rules.ts create mode 100644 x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts create mode 100644 x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts create mode 100644 x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx diff --git a/src/core/public/doc_links/doc_links_service.ts b/src/core/public/doc_links/doc_links_service.ts index 72fa6c5553f77..a61d7de08848c 100644 --- a/src/core/public/doc_links/doc_links_service.ts +++ b/src/core/public/doc_links/doc_links_service.ts @@ -270,6 +270,8 @@ export class DocLinksService { }, transforms: { guide: `${ELASTICSEARCH_DOCS}transforms.html`, + // TODO add valid docs URL + alertingRules: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-configuring-alerts.html`, }, visualize: { guide: `${KIBANA_DOCS}dashboard.html`, diff --git a/x-pack/plugins/transform/common/constants.ts b/x-pack/plugins/transform/common/constants.ts index 423b2d001381c..40742935b7474 100644 --- a/x-pack/plugins/transform/common/constants.ts +++ b/x-pack/plugins/transform/common/constants.ts @@ -105,3 +105,7 @@ export const TRANSFORM_FUNCTION = { } as const; export type TransformFunction = typeof TRANSFORM_FUNCTION[keyof typeof TRANSFORM_FUNCTION]; + +export const TRANSFORM_RULE_TYPE = { + TRANSFORM_HEALTH: 'transform_health', +} as const; diff --git a/x-pack/plugins/transform/common/types/alerting.ts b/x-pack/plugins/transform/common/types/alerting.ts new file mode 100644 index 0000000000000..54cf3fb30402a --- /dev/null +++ b/x-pack/plugins/transform/common/types/alerting.ts @@ -0,0 +1,13 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { AlertTypeParams } from '../../../alerting/common'; + +export type TransformHealthRuleParams = { + includeTransforms: string[]; + excludeTransforms?: string[]; +} & AlertTypeParams; diff --git a/x-pack/plugins/transform/kibana.json b/x-pack/plugins/transform/kibana.json index c9f6beeee5aff..ee2de2770067a 100644 --- a/x-pack/plugins/transform/kibana.json +++ b/x-pack/plugins/transform/kibana.json @@ -10,11 +10,14 @@ "management", "features", "savedObjects", - "share" + "share", + "triggersActionsUi", + "fieldFormats" ], "optionalPlugins": [ "security", - "usageCollection" + "usageCollection", + "alerting" ], "configPath": ["xpack", "transform"], "requiredBundles": [ @@ -22,7 +25,8 @@ "discover", "kibanaUtils", "kibanaReact", - "ml" + "ml", + "fieldFormats" ], "owner": { "name": "Machine Learning UI", diff --git a/x-pack/plugins/transform/public/alerting/index.ts b/x-pack/plugins/transform/public/alerting/index.ts new file mode 100644 index 0000000000000..3b64b78285a86 --- /dev/null +++ b/x-pack/plugins/transform/public/alerting/index.ts @@ -0,0 +1,8 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { registerAlertingRules } from './register_alerting_rules'; diff --git a/x-pack/plugins/transform/public/alerting/register_alerting_rules.ts b/x-pack/plugins/transform/public/alerting/register_alerting_rules.ts new file mode 100644 index 0000000000000..bf75d0dc9cac3 --- /dev/null +++ b/x-pack/plugins/transform/public/alerting/register_alerting_rules.ts @@ -0,0 +1,28 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { TriggersAndActionsUIPublicPluginSetup } from '../../../triggers_actions_ui/public'; +import type { PluginSetupContract as AlertingSetup } from '../../../alerting/public'; +import { registerTransformHealthRule } from './transform_health_rule_type'; +import { PLUGIN, TRANSFORM_RULE_TYPE } from '../../common/constants'; + +export function registerAlertingRules( + triggersActionsUi: TriggersAndActionsUIPublicPluginSetup, + alerting?: AlertingSetup +) { + registerTransformHealthRule(triggersActionsUi); + + if (alerting) { + registerNavigation(alerting); + } +} + +export function registerNavigation(alerting: AlertingSetup) { + alerting.registerNavigation(PLUGIN.ID, TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH, (alert) => { + return ''; + }); +} diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts new file mode 100644 index 0000000000000..654182967a260 --- /dev/null +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts @@ -0,0 +1,8 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { registerTransformHealthRule } from './register_transform_health_rule'; diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts new file mode 100644 index 0000000000000..ab83f76eddd9c --- /dev/null +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts @@ -0,0 +1,56 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { lazy } from 'react'; +import { i18n } from '../../../../../../../../../../private/var/tmp/_bazel_darnautov/1afe62330ff0d9ae1ca2013aad33fd76/execroot/kibana/bazel-out/darwin-fastbuild/bin/packages/kbn-i18n'; +import type { TriggersAndActionsUIPublicPluginSetup } from '../../../../triggers_actions_ui/public'; +import { TRANSFORM_RULE_TYPE } from '../../../common/constants'; +import type { TransformHealthRuleParams } from '../../../common/types/alerting'; + +export function registerTransformHealthRule( + triggersActionsUi: TriggersAndActionsUIPublicPluginSetup +) { + triggersActionsUi.ruleTypeRegistry.register({ + id: TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH, + description: i18n.translate('xpack.transform.alertingRuleTypes.transformHealth.description', { + defaultMessage: 'Alert when transform jobs experience operational issues.', + }), + iconClass: 'bell', + documentationUrl(docLinks) { + return docLinks.links.transforms.alertingRules; + }, + alertParamsExpression: lazy(() => import('./transform_health_rule_trigger')), + validate: (alertParams: TransformHealthRuleParams) => { + const validationResult = { + errors: { + includeTransforms: new Array(), + } as Record, + }; + + return validationResult; + }, + requiresAppContext: false, + defaultActionMessage: i18n.translate( + 'xpack.ml.alertTypes.jobsHealthAlertingRule.defaultActionMessage', + { + defaultMessage: `[\\{\\{rule.name\\}\\}] Transforms health check result: +\\{\\{context.message\\}\\} +\\{\\{#context.results\\}\\} + Transform ID: \\{\\{transform_id\\}\\} + \\{\\{#description\\}\\}Transform description: \\{\\{description\\}\\} + \\{\\{/description\\}\\}\\{\\{#transform_state\\}\\}Transform state: \\{\\{transform_state\\}\\} + \\{\\{/transform_state\\}\\}\\{\\{#failure_reason\\}\\}Failure reason: \\{\\{failure_reason\\}\\} + \\{\\{/failure_reason\\}\\}\\{\\{#notification_message\\}\\}Notification message: \\{\\{notification_message\\}\\} + \\{\\{/notification_message\\}\\}\\{\\{#node_name\\}\\}Node name: \\{\\{node_name\\}\\} + \\{\\{/node_name\\}\\}\\{\\{#timestamp\\}\\}Timestamp: \\{\\{timestamp\\}\\} + \\{\\{/timestamp\\}\\} +\\{\\{/context.results\\}\\} +`, + } + ), + }); +} diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx new file mode 100644 index 0000000000000..7440a819f40e2 --- /dev/null +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx @@ -0,0 +1,38 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { EuiForm } from '@elastic/eui'; +import React, { FC } from 'react'; +import type { AlertTypeParamsExpressionProps } from '../../../../triggers_actions_ui/public'; +import type { TransformHealthRuleParams } from '../../../common/types/alerting'; + +export type TransformHealthRuleTriggerProps = AlertTypeParamsExpressionProps; + +const TransformHealthRuleTrigger: FC = ({ + alertParams, + setAlertParams, + errors, +}) => { + const formErrors = Object.values(errors).flat(); + const isFormInvalid = formErrors.length > 0; + + return ( + +
+ + ); +}; + +// Default export is required for React.lazy loading + +// eslint-disable-next-line import/no-default-export +export default TransformHealthRuleTrigger; diff --git a/x-pack/plugins/transform/public/plugin.ts b/x-pack/plugins/transform/public/plugin.ts index b058be46d677b..4231bf377faa3 100644 --- a/x-pack/plugins/transform/public/plugin.ts +++ b/x-pack/plugins/transform/public/plugin.ts @@ -14,6 +14,9 @@ import type { SavedObjectsStart } from 'src/plugins/saved_objects/public'; import type { ManagementSetup } from 'src/plugins/management/public'; import type { SharePluginStart } from 'src/plugins/share/public'; import { registerFeature } from './register_feature'; +import type { PluginSetupContract as AlertingSetup } from '../../alerting/public'; +import type { TriggersAndActionsUIPublicPluginSetup } from '../../triggers_actions_ui/public'; +import { registerAlertingRules } from './alerting'; export interface PluginsDependencies { data: DataPublicPluginStart; @@ -21,11 +24,13 @@ export interface PluginsDependencies { home: HomePublicPluginSetup; savedObjects: SavedObjectsStart; share: SharePluginStart; + alerting?: AlertingSetup; + triggersActionsUi?: TriggersAndActionsUIPublicPluginSetup; } export class TransformUiPlugin { public setup(coreSetup: CoreSetup, pluginsSetup: PluginsDependencies): void { - const { management, home } = pluginsSetup; + const { management, home, alerting, triggersActionsUi } = pluginsSetup; // Register management section const esSection = management.sections.section.data; @@ -41,6 +46,11 @@ export class TransformUiPlugin { }, }); registerFeature(home); + + // TODO add capability for creating alerting rules for transform + if (triggersActionsUi) { + registerAlertingRules(triggersActionsUi, alerting); + } } public start() {} From 22764b1d3a9bf554eb98be42bd62d30ac8fd2774 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Tue, 14 Sep 2021 12:59:02 +0200 Subject: [PATCH 02/29] [ML] init transform rule type from the monitoring plugin --- x-pack/plugins/monitoring/common/constants.ts | 4 +- x-pack/plugins/monitoring/kibana.json | 2 +- x-pack/plugins/monitoring/public/plugin.ts | 2 + x-pack/plugins/monitoring/server/plugin.ts | 3 + x-pack/plugins/monitoring/tsconfig.json | 1 + x-pack/plugins/transform/common/index.ts | 8 ++ x-pack/plugins/transform/kibana.json | 6 +- .../transform/public/alerting/index.ts | 1 + .../transform_health_rule_type/index.ts | 2 +- .../register_transform_health_rule.ts | 16 ++-- x-pack/plugins/transform/public/index.ts | 2 + x-pack/plugins/transform/public/plugin.ts | 8 +- x-pack/plugins/transform/server/index.ts | 2 + .../transform/server/lib/alerting/index.ts | 8 ++ .../register_transform_alerting_rules.ts | 18 +++++ .../transform_health_rule_type/index.ts | 8 ++ .../register_transform_health_rule_type.ts | 78 +++++++++++++++++++ .../transform_health_rule_type/schema.ts | 15 ++++ x-pack/plugins/transform/server/types.ts | 2 + 19 files changed, 165 insertions(+), 21 deletions(-) create mode 100644 x-pack/plugins/transform/common/index.ts create mode 100644 x-pack/plugins/transform/server/lib/alerting/index.ts create mode 100644 x-pack/plugins/transform/server/lib/alerting/register_transform_alerting_rules.ts create mode 100644 x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/index.ts create mode 100644 x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts create mode 100644 x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts diff --git a/x-pack/plugins/monitoring/common/constants.ts b/x-pack/plugins/monitoring/common/constants.ts index 3f03680e687b1..db4fb208f1728 100644 --- a/x-pack/plugins/monitoring/common/constants.ts +++ b/x-pack/plugins/monitoring/common/constants.ts @@ -8,6 +8,7 @@ import { i18n } from '@kbn/i18n'; import { CommonAlertParamDetail } from './types/alerts'; import { AlertParamType } from './enums'; +import { TRANSFORM_RULE_TYPE } from '../../transform/common'; /** * Helper string to add as a tag in every logging call @@ -538,7 +539,8 @@ export const RULES = [ RULE_THREAD_POOL_WRITE_REJECTIONS, RULE_CCR_READ_EXCEPTIONS, RULE_LARGE_SHARD_SIZE, -]; + TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH, +] as const; /** * A list of all legacy rules, which means they are powered by watcher diff --git a/x-pack/plugins/monitoring/kibana.json b/x-pack/plugins/monitoring/kibana.json index bf5e0ff2e16e3..20a1bc5e51b29 100644 --- a/x-pack/plugins/monitoring/kibana.json +++ b/x-pack/plugins/monitoring/kibana.json @@ -27,5 +27,5 @@ ], "server": true, "ui": true, - "requiredBundles": ["kibanaUtils", "home", "alerting", "kibanaReact", "licenseManagement"] + "requiredBundles": ["kibanaUtils", "home", "alerting", "kibanaReact", "licenseManagement", "transform"] } diff --git a/x-pack/plugins/monitoring/public/plugin.ts b/x-pack/plugins/monitoring/public/plugin.ts index 6f625194287ba..6370d53a819b3 100644 --- a/x-pack/plugins/monitoring/public/plugin.ts +++ b/x-pack/plugins/monitoring/public/plugin.ts @@ -37,6 +37,7 @@ import { createMemoryUsageAlertType } from './alerts/memory_usage_alert'; import { createCCRReadExceptionsAlertType } from './alerts/ccr_read_exceptions_alert'; import { createLargeShardSizeAlertType } from './alerts/large_shard_size_alert'; import { setConfig } from './external_config'; +import { createTransformHealthRuleType } from '../../transform/public'; interface MonitoringSetupPluginDependencies { home?: HomePublicPluginSetup; @@ -213,6 +214,7 @@ export class MonitoringPlugin ); ruleTypeRegistry.register(createCCRReadExceptionsAlertType()); ruleTypeRegistry.register(createLargeShardSizeAlertType()); + ruleTypeRegistry.register(createTransformHealthRuleType()); const legacyAlertTypes = createLegacyAlertTypes(); for (const legacyAlertType of legacyAlertTypes) { ruleTypeRegistry.register(legacyAlertType); diff --git a/x-pack/plugins/monitoring/server/plugin.ts b/x-pack/plugins/monitoring/server/plugin.ts index 1d6af9f080dc0..ae7c4b4326e6a 100644 --- a/x-pack/plugins/monitoring/server/plugin.ts +++ b/x-pack/plugins/monitoring/server/plugin.ts @@ -51,6 +51,7 @@ import { PluginsStart, RequestHandlerContextMonitoringPlugin, } from './types'; +import { getTransformHealthRuleType } from '../../transform/server'; // This is used to test the version of kibana const snapshotRegex = /-snapshot/i; @@ -127,6 +128,8 @@ export class MonitoringPlugin for (const alert of alerts) { plugins.alerting?.registerType(alert.getRuleType()); } + plugins.alerting?.registerType(getTransformHealthRuleType()); + const config = createConfig(this.initializerContext.config.get>()); // Register collector objects for stats to show up in the APIs diff --git a/x-pack/plugins/monitoring/tsconfig.json b/x-pack/plugins/monitoring/tsconfig.json index 756b8528865ce..4bc5e55800fcb 100644 --- a/x-pack/plugins/monitoring/tsconfig.json +++ b/x-pack/plugins/monitoring/tsconfig.json @@ -31,5 +31,6 @@ { "path": "../observability/tsconfig.json" }, { "path": "../telemetry_collection_xpack/tsconfig.json" }, { "path": "../triggers_actions_ui/tsconfig.json" }, + { "path": "../transform/tsconfig.json" }, ] } diff --git a/x-pack/plugins/transform/common/index.ts b/x-pack/plugins/transform/common/index.ts new file mode 100644 index 0000000000000..3b2ac4da14c6a --- /dev/null +++ b/x-pack/plugins/transform/common/index.ts @@ -0,0 +1,8 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { TRANSFORM_RULE_TYPE } from './constants'; diff --git a/x-pack/plugins/transform/kibana.json b/x-pack/plugins/transform/kibana.json index ee2de2770067a..5e1c1fb938a86 100644 --- a/x-pack/plugins/transform/kibana.json +++ b/x-pack/plugins/transform/kibana.json @@ -25,8 +25,10 @@ "discover", "kibanaUtils", "kibanaReact", - "ml", - "fieldFormats" + "ml" + ], + "extraPublicDirs": [ + "common" ], "owner": { "name": "Machine Learning UI", diff --git a/x-pack/plugins/transform/public/alerting/index.ts b/x-pack/plugins/transform/public/alerting/index.ts index 3b64b78285a86..6b7929cdd6b22 100644 --- a/x-pack/plugins/transform/public/alerting/index.ts +++ b/x-pack/plugins/transform/public/alerting/index.ts @@ -6,3 +6,4 @@ */ export { registerAlertingRules } from './register_alerting_rules'; +export { createTransformHealthRuleType } from './transform_health_rule_type'; diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts index 654182967a260..a6941d088696c 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts @@ -5,4 +5,4 @@ * 2.0. */ -export { registerTransformHealthRule } from './register_transform_health_rule'; +export { createTransformHealthRuleType } from './register_transform_health_rule'; diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts index ab83f76eddd9c..dfcf3976b64bf 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts @@ -6,15 +6,13 @@ */ import { lazy } from 'react'; -import { i18n } from '../../../../../../../../../../private/var/tmp/_bazel_darnautov/1afe62330ff0d9ae1ca2013aad33fd76/execroot/kibana/bazel-out/darwin-fastbuild/bin/packages/kbn-i18n'; -import type { TriggersAndActionsUIPublicPluginSetup } from '../../../../triggers_actions_ui/public'; -import { TRANSFORM_RULE_TYPE } from '../../../common/constants'; +import { i18n } from '@kbn/i18n'; +import { TRANSFORM_RULE_TYPE } from '../../../common'; import type { TransformHealthRuleParams } from '../../../common/types/alerting'; +import type { AlertTypeModel } from '../../../../triggers_actions_ui/public'; -export function registerTransformHealthRule( - triggersActionsUi: TriggersAndActionsUIPublicPluginSetup -) { - triggersActionsUi.ruleTypeRegistry.register({ +export function createTransformHealthRuleType(): AlertTypeModel { + return { id: TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH, description: i18n.translate('xpack.transform.alertingRuleTypes.transformHealth.description', { defaultMessage: 'Alert when transform jobs experience operational issues.', @@ -35,7 +33,7 @@ export function registerTransformHealthRule( }, requiresAppContext: false, defaultActionMessage: i18n.translate( - 'xpack.ml.alertTypes.jobsHealthAlertingRule.defaultActionMessage', + 'xpack.transform.alertTypes.transformHealth.defaultActionMessage', { defaultMessage: `[\\{\\{rule.name\\}\\}] Transforms health check result: \\{\\{context.message\\}\\} @@ -52,5 +50,5 @@ export function registerTransformHealthRule( `, } ), - }); + }; } diff --git a/x-pack/plugins/transform/public/index.ts b/x-pack/plugins/transform/public/index.ts index e4f630e23afce..d05117b7ddd72 100644 --- a/x-pack/plugins/transform/public/index.ts +++ b/x-pack/plugins/transform/public/index.ts @@ -12,3 +12,5 @@ import { TransformUiPlugin } from './plugin'; export const plugin = () => { return new TransformUiPlugin(); }; + +export { createTransformHealthRuleType } from './alerting'; diff --git a/x-pack/plugins/transform/public/plugin.ts b/x-pack/plugins/transform/public/plugin.ts index 4231bf377faa3..d18d846ee7e07 100644 --- a/x-pack/plugins/transform/public/plugin.ts +++ b/x-pack/plugins/transform/public/plugin.ts @@ -16,7 +16,6 @@ import type { SharePluginStart } from 'src/plugins/share/public'; import { registerFeature } from './register_feature'; import type { PluginSetupContract as AlertingSetup } from '../../alerting/public'; import type { TriggersAndActionsUIPublicPluginSetup } from '../../triggers_actions_ui/public'; -import { registerAlertingRules } from './alerting'; export interface PluginsDependencies { data: DataPublicPluginStart; @@ -30,7 +29,7 @@ export interface PluginsDependencies { export class TransformUiPlugin { public setup(coreSetup: CoreSetup, pluginsSetup: PluginsDependencies): void { - const { management, home, alerting, triggersActionsUi } = pluginsSetup; + const { management, home } = pluginsSetup; // Register management section const esSection = management.sections.section.data; @@ -46,11 +45,6 @@ export class TransformUiPlugin { }, }); registerFeature(home); - - // TODO add capability for creating alerting rules for transform - if (triggersActionsUi) { - registerAlertingRules(triggersActionsUi, alerting); - } } public start() {} diff --git a/x-pack/plugins/transform/server/index.ts b/x-pack/plugins/transform/server/index.ts index 77103aa4fdac5..c1ec42114818d 100644 --- a/x-pack/plugins/transform/server/index.ts +++ b/x-pack/plugins/transform/server/index.ts @@ -10,3 +10,5 @@ import { PluginInitializerContext } from 'src/core/server'; import { TransformServerPlugin } from './plugin'; export const plugin = (ctx: PluginInitializerContext) => new TransformServerPlugin(ctx); + +export { getTransformHealthRuleType } from './lib/alerting'; diff --git a/x-pack/plugins/transform/server/lib/alerting/index.ts b/x-pack/plugins/transform/server/lib/alerting/index.ts new file mode 100644 index 0000000000000..0c693cc4bfc06 --- /dev/null +++ b/x-pack/plugins/transform/server/lib/alerting/index.ts @@ -0,0 +1,8 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { getTransformHealthRuleType } from './transform_health_rule_type'; diff --git a/x-pack/plugins/transform/server/lib/alerting/register_transform_alerting_rules.ts b/x-pack/plugins/transform/server/lib/alerting/register_transform_alerting_rules.ts new file mode 100644 index 0000000000000..7bcebdee639a5 --- /dev/null +++ b/x-pack/plugins/transform/server/lib/alerting/register_transform_alerting_rules.ts @@ -0,0 +1,18 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { Logger } from 'kibana/server'; +import type { AlertingPlugin } from '../../../../alerting/server'; +// import { registerTransformHealthRuleType } from './transform_health_rule_type'; + +export interface RegisterAlertParams { + alerting: AlertingPlugin['setup']; + logger: Logger; +} +// export function registerTransformAlertingRules(params: RegisterAlertParams) { +// registerTransformHealthRuleType(params); +// } diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/index.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/index.ts new file mode 100644 index 0000000000000..08f9fc85659fb --- /dev/null +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/index.ts @@ -0,0 +1,8 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { getTransformHealthRuleType } from './register_transform_health_rule_type'; diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts new file mode 100644 index 0000000000000..9b90a568b6d33 --- /dev/null +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts @@ -0,0 +1,78 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { i18n } from '@kbn/i18n'; +import type { + ActionGroup, + AlertInstanceContext, + AlertInstanceState, + AlertTypeState, +} from '../../../../../alerting/common'; +import { PLUGIN, TRANSFORM_RULE_TYPE } from '../../../../common/constants'; +import { transformHealthRuleParams, TransformHealthRuleParams } from './schema'; +import { AlertType } from '../../../../../alerting/server'; + +export type TransformHealthAlertContext = { + results: any[]; + message: string; +} & AlertInstanceContext; + +export const TRANSFORM_ISSUE = 'transform_issue'; + +export type TransformIssue = typeof TRANSFORM_ISSUE; + +export const TRANSFORM_ISSUE_DETECTED: ActionGroup = { + id: TRANSFORM_ISSUE, + name: i18n.translate('xpack.transform.alertingRuleTypes.transformHealth.actionGroupName', { + defaultMessage: 'Issue detected', + }), +}; + +export function getTransformHealthRuleType(): AlertType< + TransformHealthRuleParams, + never, + AlertTypeState, + AlertInstanceState, + TransformHealthAlertContext, + TransformIssue +> { + return { + id: TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH, + name: i18n.translate('xpack.transform.alertingRuleTypes.transformHealth.name', { + defaultMessage: 'Transform health', + }), + actionGroups: [TRANSFORM_ISSUE_DETECTED], + defaultActionGroupId: TRANSFORM_ISSUE, + validate: { params: transformHealthRuleParams }, + actionVariables: { + context: [ + { + name: 'results', + description: i18n.translate( + 'xpack.transform.alertTypes.transformHealth.alertContext.resultsDescription', + { + defaultMessage: 'Results of the rule execution', + } + ), + }, + { + name: 'message', + description: i18n.translate( + 'xpack.transform.alertTypes.transformHealth.alertContext.messageDescription', + { + defaultMessage: 'Alert info message', + } + ), + }, + ], + }, + producer: 'monitoring', + minimumLicenseRequired: PLUGIN.MINIMUM_LICENSE_REQUIRED, + isExportable: true, + async executor(options) {}, + }; +} diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts new file mode 100644 index 0000000000000..903da7750d2d5 --- /dev/null +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts @@ -0,0 +1,15 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { schema, TypeOf } from '@kbn/config-schema'; + +export const transformHealthRuleParams = schema.object({ + includeTransforms: schema.arrayOf(schema.string()), + excludeTransforms: schema.nullable(schema.arrayOf(schema.string(), { defaultValue: [] })), +}); + +export type TransformHealthRuleParams = TypeOf; diff --git a/x-pack/plugins/transform/server/types.ts b/x-pack/plugins/transform/server/types.ts index a6e1996a45013..53f13cc752650 100644 --- a/x-pack/plugins/transform/server/types.ts +++ b/x-pack/plugins/transform/server/types.ts @@ -9,10 +9,12 @@ import { IRouter } from 'src/core/server'; import { LicensingPluginSetup } from '../../licensing/server'; import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server'; import { License } from './services'; +import type { AlertingPlugin } from '../../alerting/server'; export interface Dependencies { licensing: LicensingPluginSetup; features: FeaturesPluginSetup; + alerting?: AlertingPlugin['setup']; } export interface RouteDependencies { From 5528e1176da0a345f7cc0a54310ad274ed74c358 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 15 Sep 2021 13:31:03 +0200 Subject: [PATCH 03/29] [ML] add UI form --- x-pack/plugins/transform/common/constants.ts | 20 ++++ .../transform/common/types/alerting.ts | 13 ++- .../plugins/transform/common/types/common.ts | 4 + .../plugins/transform/common/utils/alerts.ts | 16 +++ .../tests_selection_control.tsx | 78 +++++++++++++++ .../transform_health_rule_trigger.tsx | 97 ++++++++++++++++++- .../transform_selector_control.tsx | 82 ++++++++++++++++ .../register_transform_health_rule_type.ts | 14 ++- .../transform_health_rule_type/schema.ts | 9 ++ .../transform_health_service.ts | 62 ++++++++++++ 10 files changed, 389 insertions(+), 6 deletions(-) create mode 100644 x-pack/plugins/transform/common/utils/alerts.ts create mode 100644 x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx create mode 100644 x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_selector_control.tsx create mode 100644 x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts diff --git a/x-pack/plugins/transform/common/constants.ts b/x-pack/plugins/transform/common/constants.ts index 40742935b7474..39e37e37cfe06 100644 --- a/x-pack/plugins/transform/common/constants.ts +++ b/x-pack/plugins/transform/common/constants.ts @@ -8,6 +8,7 @@ import { i18n } from '@kbn/i18n'; import { LicenseType } from '../../licensing/common/types'; +import { TransformHealthTests } from './types/alerting'; export const DEFAULT_REFRESH_INTERVAL_MS = 30000; export const MINIMUM_REFRESH_INTERVAL_MS = 1000; @@ -109,3 +110,22 @@ export type TransformFunction = typeof TRANSFORM_FUNCTION[keyof typeof TRANSFORM export const TRANSFORM_RULE_TYPE = { TRANSFORM_HEALTH: 'transform_health', } as const; + +export const ALL_TRANSFORMS_SELECTION = '*'; + +export const TRANSFORM_HEALTH_CHECK_NAMES: Record< + TransformHealthTests, + { name: string; description: string } +> = { + notStarted: { + name: i18n.translate('xpack.transform.alertTypes.transformHealth.notStartedCheckName', { + defaultMessage: 'Transform is not started', + }), + description: i18n.translate( + 'xpack.transform.alertTypes.transformHealth.notStartedCheckDescription', + { + defaultMessage: 'Get alerted if the transform is not started or indexing any data.', + } + ), + }, +}; diff --git a/x-pack/plugins/transform/common/types/alerting.ts b/x-pack/plugins/transform/common/types/alerting.ts index 54cf3fb30402a..d7253d0ff1845 100644 --- a/x-pack/plugins/transform/common/types/alerting.ts +++ b/x-pack/plugins/transform/common/types/alerting.ts @@ -8,6 +8,15 @@ import type { AlertTypeParams } from '../../../alerting/common'; export type TransformHealthRuleParams = { - includeTransforms: string[]; - excludeTransforms?: string[]; + includeTransforms?: string[]; + excludeTransforms?: string[] | null; + testsConfig: { + notStarted: { + enabled: boolean; + } | null; + } | null; } & AlertTypeParams; + +export type TransformHealthRuleTestsConfig = TransformHealthRuleParams['testsConfig']; + +export type TransformHealthTests = keyof Exclude; diff --git a/x-pack/plugins/transform/common/types/common.ts b/x-pack/plugins/transform/common/types/common.ts index 1cbb370b0a3ab..94cb935f52634 100644 --- a/x-pack/plugins/transform/common/types/common.ts +++ b/x-pack/plugins/transform/common/types/common.ts @@ -20,3 +20,7 @@ export function dictionaryToArray(dict: Dictionary): TValue[] { export type DeepPartial = { [P in keyof T]?: DeepPartial; }; + +export function isDefined(argument: T | undefined | null): argument is T { + return argument !== undefined && argument !== null; +} diff --git a/x-pack/plugins/transform/common/utils/alerts.ts b/x-pack/plugins/transform/common/utils/alerts.ts new file mode 100644 index 0000000000000..9b3cb2757100a --- /dev/null +++ b/x-pack/plugins/transform/common/utils/alerts.ts @@ -0,0 +1,16 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { TransformHealthRuleTestsConfig } from '../types/alerting'; + +export function getResultTestConfig(config: TransformHealthRuleTestsConfig) { + return { + notStarted: { + enabled: config?.notStarted?.enabled ?? true, + }, + }; +} diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx new file mode 100644 index 0000000000000..a28fd15ca09ba --- /dev/null +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx @@ -0,0 +1,78 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React, { FC, useCallback } from 'react'; +import { EuiDescribedFormGroup, EuiForm, EuiFormRow, EuiSpacer, EuiSwitch } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n/react'; + +import { + TransformHealthRuleTestsConfig, + TransformHealthTests, +} from '../../../common/types/alerting'; +import { getResultTestConfig } from '../../../common/utils/alerts'; +import { TRANSFORM_HEALTH_CHECK_NAMES } from '../../../common/constants'; + +interface TestsSelectionControlProps { + config: TransformHealthRuleTestsConfig; + onChange: (update: TransformHealthRuleTestsConfig) => void; + errors?: string[]; +} + +export const TestsSelectionControl: FC = React.memo( + ({ config, onChange, errors }) => { + const uiConfig = getResultTestConfig(config); + + const updateCallback = useCallback( + (update: Partial>) => { + onChange({ + ...(config ?? {}), + ...update, + }); + }, + [onChange, config] + ); + + return ( + <> + + {(Object.entries(uiConfig) as Array< + [TransformHealthTests, typeof uiConfig[TransformHealthTests]] + >).map(([name, conf], i) => { + return ( + {TRANSFORM_HEALTH_CHECK_NAMES[name]?.name}} + description={TRANSFORM_HEALTH_CHECK_NAMES[name]?.description} + fullWidth + gutterSize={'s'} + > + + + } + onChange={updateCallback.bind(null, { + [name]: { + ...uiConfig[name], + enabled: !uiConfig[name].enabled, + }, + })} + checked={uiConfig[name].enabled} + /> + + + ); + })} + + + + ); + } +); diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx index 7440a819f40e2..e075171d34b72 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx @@ -5,10 +5,18 @@ * 2.0. */ -import { EuiForm } from '@elastic/eui'; -import React, { FC } from 'react'; +import { EuiForm, EuiSpacer } from '@elastic/eui'; +import React, { FC, useCallback, useEffect, useMemo, useState } from 'react'; +import { FormattedMessage } from '@kbn/i18n/react'; import type { AlertTypeParamsExpressionProps } from '../../../../triggers_actions_ui/public'; import type { TransformHealthRuleParams } from '../../../common/types/alerting'; +import { TestsSelectionControl } from './tests_selection_control'; +import { TransformSelectorControl } from './transform_selector_control'; +import { useApi } from '../../app/hooks'; +import { useToastNotifications } from '../../app/app_dependencies'; +import { GetTransformsResponseSchema } from '../../../common/api_schemas/transforms'; +import { i18n } from '../../../../../../../../../../private/var/tmp/_bazel_darnautov/1afe62330ff0d9ae1ca2013aad33fd76/execroot/kibana/bazel-out/darwin-fastbuild/bin/packages/kbn-i18n'; +import { ALL_TRANSFORMS_SELECTION } from '../../../common/constants'; export type TransformHealthRuleTriggerProps = AlertTypeParamsExpressionProps; @@ -20,6 +28,53 @@ const TransformHealthRuleTrigger: FC = ({ const formErrors = Object.values(errors).flat(); const isFormInvalid = formErrors.length > 0; + const api = useApi(); + const toast = useToastNotifications(); + const [transformOptions, setTransformOptions] = useState([]); + + const onAlertParamChange = useCallback( + (param: T) => ( + update: TransformHealthRuleParams[T] + ) => { + setAlertParams(param, update); + }, + [setAlertParams] + ); + + useEffect( + function fetchTransforms() { + let unmounted = false; + api + .getTransforms() + .then((r) => { + if (!unmounted) { + setTransformOptions((r as GetTransformsResponseSchema).transforms.map((v) => v.id)); + } + }) + .catch((e) => { + toast.addError(e, { + title: i18n.translate( + 'xpack.transform.alertingRuleTypes.transformHealth.fetchErrorMessage', + { + defaultMessage: 'Unable to fetch transforms', + } + ), + }); + }); + return () => { + unmounted = true; + }; + }, + [api, toast] + ); + + const excludeTransformOptions = useMemo(() => { + if (alertParams.includeTransforms?.some((v) => v === ALL_TRANSFORMS_SELECTION)) { + return transformOptions; + } + return null; + }, [transformOptions, alertParams.includeTransforms]); + return ( = ({ error={formErrors} isInvalid={isFormInvalid} > -
+ + } + options={transformOptions} + selectedOptions={alertParams.includeTransforms ?? []} + onChange={onAlertParamChange('includeTransforms')} + allowSelectAll + /> + + + + {!!excludeTransformOptions?.length || !!alertParams.excludeTransforms?.length ? ( + <> + + } + options={excludeTransformOptions!} + selectedOptions={alertParams.excludeTransforms ?? []} + onChange={onAlertParamChange('excludeTransforms')} + /> + + + ) : null} + + ); }; diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_selector_control.tsx b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_selector_control.tsx new file mode 100644 index 0000000000000..d9890b88c4bf7 --- /dev/null +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_selector_control.tsx @@ -0,0 +1,82 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { EuiComboBox, EuiComboBoxProps, EuiFormRow } from '@elastic/eui'; +import React, { FC, useMemo } from 'react'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { ALL_TRANSFORMS_SELECTION } from '../../../common/constants'; +import { isDefined } from '../../../common/types/common'; + +export interface TransformSelectorControlProps { + label?: string | JSX.Element; + errors?: string[]; + onChange: (transformSelection: string[]) => void; + selectedOptions: string[]; + options: string[]; + allowSelectAll?: boolean; +} + +function convertToEuiOptions(values: string[]) { + return values.map((v) => ({ value: v, label: v })); +} + +export const TransformSelectorControl: FC = ({ + label, + errors, + onChange, + selectedOptions, + options, + allowSelectAll = false, +}) => { + const onSelectionChange: EuiComboBoxProps['onChange'] = ((selectionUpdate) => { + if (!selectionUpdate?.length) { + onChange([]); + return; + } + if (selectionUpdate[selectionUpdate.length - 1].value === ALL_TRANSFORMS_SELECTION) { + onChange([ALL_TRANSFORMS_SELECTION]); + return; + } + onChange( + selectionUpdate + .slice(selectionUpdate[0].value === ALL_TRANSFORMS_SELECTION ? 1 : 0) + .map((v) => v.value) + .filter(isDefined) + ); + }) as Exclude['onChange'], undefined>; + + const selectedOptionsEui = useMemo(() => convertToEuiOptions(selectedOptions), [selectedOptions]); + const optionsEui = useMemo(() => { + return convertToEuiOptions(allowSelectAll ? [ALL_TRANSFORMS_SELECTION, ...options] : options); + }, [options, allowSelectAll]); + + return ( + + ) + } + isInvalid={!!errors?.length} + error={errors} + > + + singleSelection={false} + selectedOptions={selectedOptionsEui} + options={optionsEui} + onChange={onSelectionChange} + fullWidth + data-test-subj={'transformSelection'} + isInvalid={!!errors?.length} + /> + + ); +}; diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts index 9b90a568b6d33..704d52d1b29b2 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts @@ -15,6 +15,7 @@ import type { import { PLUGIN, TRANSFORM_RULE_TYPE } from '../../../../common/constants'; import { transformHealthRuleParams, TransformHealthRuleParams } from './schema'; import { AlertType } from '../../../../../alerting/server'; +import { transformHealthServiceProvider } from './transform_health_service'; export type TransformHealthAlertContext = { results: any[]; @@ -73,6 +74,17 @@ export function getTransformHealthRuleType(): AlertType< producer: 'monitoring', minimumLicenseRequired: PLUGIN.MINIMUM_LICENSE_REQUIRED, isExportable: true, - async executor(options) {}, + async executor(options) { + const { + services: { scopedClusterClient, alertInstanceFactory }, + params, + } = options; + + const transformHealthService = transformHealthServiceProvider( + scopedClusterClient.asInternalUser + ); + + const report = transformHealthService.getHealthChecksResults(params); + }, }; } diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts index 903da7750d2d5..5a7af83b120d6 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts @@ -10,6 +10,15 @@ import { schema, TypeOf } from '@kbn/config-schema'; export const transformHealthRuleParams = schema.object({ includeTransforms: schema.arrayOf(schema.string()), excludeTransforms: schema.nullable(schema.arrayOf(schema.string(), { defaultValue: [] })), + testsConfig: schema.nullable( + schema.object({ + notStarted: schema.nullable( + schema.object({ + enabled: schema.boolean({ defaultValue: true }), + }) + ), + }) + ), }); export type TransformHealthRuleParams = TypeOf; diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts new file mode 100644 index 0000000000000..7d95d328bb677 --- /dev/null +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts @@ -0,0 +1,62 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { ElasticsearchClient } from 'kibana/server'; +import { TransformHealthRuleParams } from './schema'; +import { ALL_TRANSFORMS_SELECTION } from '../../../../common/constants'; +import { getResultTestConfig } from '../../../../common/utils/alerts'; + +export function transformHealthServiceProvider(esClient: ElasticsearchClient) { + /** + * Resolves result transform selection. + * @param includeTransforms + * @param excludeTransforms + */ + const getResultsTransformIds = async ( + includeTransforms: string[], + excludeTransforms: string[] | null + ): Promise => { + const includeAll = includeTransforms.some((id) => id === ALL_TRANSFORMS_SELECTION); + + const transformsResponse = ( + await esClient.transform.getTransform({ + ...(includeAll ? {} : { transform_id: includeTransforms.join(',') }), + allow_no_match: true, + }) + ).body.transforms; + + let resultTransforms = transformsResponse.map((v) => v.transform_id); + + if (excludeTransforms) { + const excludeIdsSet = new Set(excludeTransforms); + resultTransforms = resultTransforms.filter((id) => excludeIdsSet.has(id)); + } + + return resultTransforms; + }; + + return { + async getNotStartedTransformsReport(transformIds: string[]) { + const { body } = await esClient.transform.getTransformStats({ + transform_id: transformIds.join(','), + }); + console.log(body, '___body___'); + }, + async getHealthChecksResults(params: TransformHealthRuleParams) { + const transformIds = await getResultsTransformIds( + params.includeTransforms, + params.excludeTransforms + ); + const testsConfig = getResultTestConfig(params.testsConfig); + if (testsConfig.notStarted.enabled) { + const result = this.getNotStartedTransformsReport(transformIds); + } + }, + }; +} + +export type TransformHealthService = ReturnType; From 4e893cd450256b9ea9b1acd507b53208c39a1137 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 15 Sep 2021 14:45:42 +0200 Subject: [PATCH 04/29] [ML] only suggest continuous transforms --- .../transform_health_rule_trigger.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx index e075171d34b72..b74a613611c8e 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx @@ -48,7 +48,9 @@ const TransformHealthRuleTrigger: FC = ({ .getTransforms() .then((r) => { if (!unmounted) { - setTransformOptions((r as GetTransformsResponseSchema).transforms.map((v) => v.id)); + setTransformOptions( + (r as GetTransformsResponseSchema).transforms.filter((v) => v.sync).map((v) => v.id) + ); } }) .catch((e) => { @@ -106,7 +108,7 @@ const TransformHealthRuleTrigger: FC = ({ defaultMessage="Exclude transforms" /> } - options={excludeTransformOptions!} + options={excludeTransformOptions ?? []} selectedOptions={alertParams.excludeTransforms ?? []} onChange={onAlertParamChange('excludeTransforms')} /> From 01d46814f2a6754f563fa0d863d8374ff3664b2d Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 15 Sep 2021 15:22:04 +0200 Subject: [PATCH 05/29] [ML] executor code for transform state check --- .../register_transform_health_rule_type.ts | 19 ++++- .../transform_health_service.ts | 78 ++++++++++++++++--- 2 files changed, 86 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts index 704d52d1b29b2..856b57a4d9ecc 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts @@ -17,8 +17,16 @@ import { transformHealthRuleParams, TransformHealthRuleParams } from './schema'; import { AlertType } from '../../../../../alerting/server'; import { transformHealthServiceProvider } from './transform_health_service'; +export interface NotStartedTransformResponse { + transform_id: string; + state: string; + node_name?: string; +} + +export type TransformHealthResult = NotStartedTransformResponse; + export type TransformHealthAlertContext = { - results: any[]; + results: TransformHealthResult[]; message: string; } & AlertInstanceContext; @@ -84,7 +92,14 @@ export function getTransformHealthRuleType(): AlertType< scopedClusterClient.asInternalUser ); - const report = transformHealthService.getHealthChecksResults(params); + const executionResult = await transformHealthService.getHealthChecksResults(params); + + if (executionResult.length > 0) { + executionResult.forEach(({ name: alertInstanceName, context }) => { + const alertInstance = alertInstanceFactory(alertInstanceName); + alertInstance.scheduleActions(TRANSFORM_ISSUE, context); + }); + } }, }; } diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts index 7d95d328bb677..f85cbdff5bd33 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts @@ -6,9 +6,22 @@ */ import { ElasticsearchClient } from 'kibana/server'; +import { i18n } from '@kbn/i18n'; import { TransformHealthRuleParams } from './schema'; -import { ALL_TRANSFORMS_SELECTION } from '../../../../common/constants'; +import { + ALL_TRANSFORMS_SELECTION, + TRANSFORM_HEALTH_CHECK_NAMES, +} from '../../../../common/constants'; import { getResultTestConfig } from '../../../../common/utils/alerts'; +import { + NotStartedTransformResponse, + TransformHealthAlertContext, +} from './register_transform_health_rule_type'; + +interface TestResult { + name: string; + context: TransformHealthAlertContext; +} export function transformHealthServiceProvider(esClient: ElasticsearchClient) { /** @@ -22,6 +35,7 @@ export function transformHealthServiceProvider(esClient: ElasticsearchClient) { ): Promise => { const includeAll = includeTransforms.some((id) => id === ALL_TRANSFORMS_SELECTION); + // Fetch transforms to make sure assigned transforms exists. const transformsResponse = ( await esClient.transform.getTransform({ ...(includeAll ? {} : { transform_id: includeTransforms.join(',') }), @@ -29,9 +43,11 @@ export function transformHealthServiceProvider(esClient: ElasticsearchClient) { }) ).body.transforms; - let resultTransforms = transformsResponse.map((v) => v.transform_id); + // Filter out for continuous transforms. + // @ts-ignore FIXME update types in the elasticsearch client + let resultTransforms = transformsResponse.filter((v) => v.sync).map((v) => v.id); - if (excludeTransforms) { + if (excludeTransforms && excludeTransforms.length > 0) { const excludeIdsSet = new Set(excludeTransforms); resultTransforms = resultTransforms.filter((id) => excludeIdsSet.has(id)); } @@ -40,21 +56,65 @@ export function transformHealthServiceProvider(esClient: ElasticsearchClient) { }; return { - async getNotStartedTransformsReport(transformIds: string[]) { - const { body } = await esClient.transform.getTransformStats({ - transform_id: transformIds.join(','), - }); - console.log(body, '___body___'); + /** + * Returns report about not started transform + * @param transformIds + */ + async getNotStartedTransformsReport( + transformIds: string[] + ): Promise { + const transformsStats = ( + await esClient.transform.getTransformStats({ + transform_id: transformIds.join(','), + }) + ).body.transforms; + + return transformsStats + .filter((t) => t.state !== 'started' && t.state !== 'indexing') + .map((t) => ({ + transform_id: t.id, + state: t.state, + node_name: t.node?.name, + })); }, + /** + * Returns results of the transform health checks + * @param params + */ async getHealthChecksResults(params: TransformHealthRuleParams) { const transformIds = await getResultsTransformIds( params.includeTransforms, params.excludeTransforms ); + const testsConfig = getResultTestConfig(params.testsConfig); + + const result: TestResult[] = []; + if (testsConfig.notStarted.enabled) { - const result = this.getNotStartedTransformsReport(transformIds); + const response = await this.getNotStartedTransformsReport(transformIds); + if (response.length > 0) { + const count = response.length; + const transformsString = response.map((t) => t.transform_id).join(', '); + + result.push({ + name: TRANSFORM_HEALTH_CHECK_NAMES.notStarted.name, + context: { + results: response, + message: i18n.translate( + 'xpack.transform.alertTypes.transformHealth.notStartedMessage', + { + defaultMessage: + '{count, plural, one {Transform} other {Transforms}} {transformsString} {count, plural, one {is} other {are}} not started.', + values: { count, transformsString }, + } + ), + }, + }); + } } + + return result; }, }; } From ae1f4b43a90f681e577f99df7f2ee75667dfcff3 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 15 Sep 2021 15:32:36 +0200 Subject: [PATCH 06/29] [ML] update type --- x-pack/plugins/transform/common/types/alerting.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/transform/common/types/alerting.ts b/x-pack/plugins/transform/common/types/alerting.ts index d7253d0ff1845..48a80a3889107 100644 --- a/x-pack/plugins/transform/common/types/alerting.ts +++ b/x-pack/plugins/transform/common/types/alerting.ts @@ -10,8 +10,8 @@ import type { AlertTypeParams } from '../../../alerting/common'; export type TransformHealthRuleParams = { includeTransforms?: string[]; excludeTransforms?: string[] | null; - testsConfig: { - notStarted: { + testsConfig?: { + notStarted?: { enabled: boolean; } | null; } | null; From 90b0057ea7a83f07f6875e031fe4ee3b63e30cc8 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 15 Sep 2021 15:53:00 +0200 Subject: [PATCH 07/29] [ML] add description --- .../transform/public/alerting/index.ts | 1 - .../alerting/register_alerting_rules.ts | 28 ------------------- .../register_transform_health_rule_type.ts | 6 +++- .../transform_health_service.ts | 24 ++++++++++++---- 4 files changed, 23 insertions(+), 36 deletions(-) delete mode 100644 x-pack/plugins/transform/public/alerting/register_alerting_rules.ts diff --git a/x-pack/plugins/transform/public/alerting/index.ts b/x-pack/plugins/transform/public/alerting/index.ts index 6b7929cdd6b22..1dcd028bf7200 100644 --- a/x-pack/plugins/transform/public/alerting/index.ts +++ b/x-pack/plugins/transform/public/alerting/index.ts @@ -5,5 +5,4 @@ * 2.0. */ -export { registerAlertingRules } from './register_alerting_rules'; export { createTransformHealthRuleType } from './transform_health_rule_type'; diff --git a/x-pack/plugins/transform/public/alerting/register_alerting_rules.ts b/x-pack/plugins/transform/public/alerting/register_alerting_rules.ts deleted file mode 100644 index bf75d0dc9cac3..0000000000000 --- a/x-pack/plugins/transform/public/alerting/register_alerting_rules.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import type { TriggersAndActionsUIPublicPluginSetup } from '../../../triggers_actions_ui/public'; -import type { PluginSetupContract as AlertingSetup } from '../../../alerting/public'; -import { registerTransformHealthRule } from './transform_health_rule_type'; -import { PLUGIN, TRANSFORM_RULE_TYPE } from '../../common/constants'; - -export function registerAlertingRules( - triggersActionsUi: TriggersAndActionsUIPublicPluginSetup, - alerting?: AlertingSetup -) { - registerTransformHealthRule(triggersActionsUi); - - if (alerting) { - registerNavigation(alerting); - } -} - -export function registerNavigation(alerting: AlertingSetup) { - alerting.registerNavigation(PLUGIN.ID, TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH, (alert) => { - return ''; - }); -} diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts index 856b57a4d9ecc..6e18f5691d792 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts @@ -17,8 +17,12 @@ import { transformHealthRuleParams, TransformHealthRuleParams } from './schema'; import { AlertType } from '../../../../../alerting/server'; import { transformHealthServiceProvider } from './transform_health_service'; -export interface NotStartedTransformResponse { +export interface BaseResponse { transform_id: string; + description?: string; +} + +export interface NotStartedTransformResponse extends BaseResponse { state: string; node_name?: string; } diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts index f85cbdff5bd33..dd7f81cc70714 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts @@ -7,6 +7,7 @@ import { ElasticsearchClient } from 'kibana/server'; import { i18n } from '@kbn/i18n'; +import type { Transform as EsTransform } from '@elastic/elasticsearch/api/types'; import { TransformHealthRuleParams } from './schema'; import { ALL_TRANSFORMS_SELECTION, @@ -23,7 +24,12 @@ interface TestResult { context: TransformHealthAlertContext; } +// @ts-ignore FIXME update types in the elasticsearch client +type Transform = EsTransform & { id: string; description?: string; sync: object }; + export function transformHealthServiceProvider(esClient: ElasticsearchClient) { + const transformsDict = new Map(); + /** * Resolves result transform selection. * @param includeTransforms @@ -41,18 +47,23 @@ export function transformHealthServiceProvider(esClient: ElasticsearchClient) { ...(includeAll ? {} : { transform_id: includeTransforms.join(',') }), allow_no_match: true, }) - ).body.transforms; + ).body.transforms as Transform[]; - // Filter out for continuous transforms. - // @ts-ignore FIXME update types in the elasticsearch client - let resultTransforms = transformsResponse.filter((v) => v.sync).map((v) => v.id); + let resultTransformIds: string[] = []; + + transformsResponse.forEach((t) => { + transformsDict.set(t.id, t); + if (t.sync) { + resultTransformIds.push(t.id); + } + }); if (excludeTransforms && excludeTransforms.length > 0) { const excludeIdsSet = new Set(excludeTransforms); - resultTransforms = resultTransforms.filter((id) => excludeIdsSet.has(id)); + resultTransformIds = resultTransformIds.filter((id) => excludeIdsSet.has(id)); } - return resultTransforms; + return resultTransformIds; }; return { @@ -73,6 +84,7 @@ export function transformHealthServiceProvider(esClient: ElasticsearchClient) { .filter((t) => t.state !== 'started' && t.state !== 'indexing') .map((t) => ({ transform_id: t.id, + description: transformsDict.get(t.id)?.description, state: t.state, node_name: t.node?.name, })); From 804e98c66fcfadcee021da2ee2df9343b1029bcd Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 15 Sep 2021 15:57:43 +0200 Subject: [PATCH 08/29] [ML] rename state prop --- .../register_transform_health_rule_type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts index 6e18f5691d792..c07a82f4fa2e0 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts @@ -23,7 +23,7 @@ export interface BaseResponse { } export interface NotStartedTransformResponse extends BaseResponse { - state: string; + transform_state: string; node_name?: string; } From fea3b9f2ea043f8788805af958625e7b155df801 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 15 Sep 2021 16:26:59 +0200 Subject: [PATCH 09/29] [ML] rename state prop --- .../transform_health_rule_type/transform_health_service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts index dd7f81cc70714..cb9bb5bc10e98 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts @@ -85,7 +85,7 @@ export function transformHealthServiceProvider(esClient: ElasticsearchClient) { .map((t) => ({ transform_id: t.id, description: transformsDict.get(t.id)?.description, - state: t.state, + transform_state: t.state, node_name: t.node?.name, })); }, From 4d38af148303063f4e0b980208658a9c6f6ea49e Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 15 Sep 2021 18:17:38 +0200 Subject: [PATCH 10/29] [ML] update test assertion --- x-pack/plugins/monitoring/server/plugin.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/plugins/monitoring/server/plugin.test.ts b/x-pack/plugins/monitoring/server/plugin.test.ts index 68453a849a15b..b67d77b9a425b 100644 --- a/x-pack/plugins/monitoring/server/plugin.test.ts +++ b/x-pack/plugins/monitoring/server/plugin.test.ts @@ -7,7 +7,6 @@ import { coreMock } from 'src/core/server/mocks'; import { MonitoringPlugin } from './plugin'; -import { AlertsFactory } from './alerts'; jest.mock('./es_client/instantiate_client', () => ({ instantiateClient: jest.fn().mockImplementation(() => ({ @@ -72,9 +71,8 @@ describe('Monitoring plugin', () => { }); it('should register all alerts', async () => { - const alerts = AlertsFactory.getAll(); const plugin = new MonitoringPlugin(initializerContext as any); await plugin.setup(coreSetup as any, setupPlugins as any); - expect(setupPlugins.alerting.registerType).toHaveBeenCalledTimes(alerts.length); + expect(setupPlugins.alerting.registerType).toHaveBeenCalledTimes(16); }); }); From e99df63afc4efee47b29632eb0716e502e7cbe3e Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Thu, 16 Sep 2021 11:02:57 +0200 Subject: [PATCH 11/29] [ML] fix import --- .../transform_health_rule_trigger.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx index b74a613611c8e..618eac7cfbacd 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx @@ -8,6 +8,7 @@ import { EuiForm, EuiSpacer } from '@elastic/eui'; import React, { FC, useCallback, useEffect, useMemo, useState } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; import type { AlertTypeParamsExpressionProps } from '../../../../triggers_actions_ui/public'; import type { TransformHealthRuleParams } from '../../../common/types/alerting'; import { TestsSelectionControl } from './tests_selection_control'; @@ -15,7 +16,6 @@ import { TransformSelectorControl } from './transform_selector_control'; import { useApi } from '../../app/hooks'; import { useToastNotifications } from '../../app/app_dependencies'; import { GetTransformsResponseSchema } from '../../../common/api_schemas/transforms'; -import { i18n } from '../../../../../../../../../../private/var/tmp/_bazel_darnautov/1afe62330ff0d9ae1ca2013aad33fd76/execroot/kibana/bazel-out/darwin-fastbuild/bin/packages/kbn-i18n'; import { ALL_TRANSFORMS_SELECTION } from '../../../common/constants'; export type TransformHealthRuleTriggerProps = AlertTypeParamsExpressionProps; From 6c27a241a1860d001eb6bcd84fec2cb8ec504b0c Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Thu, 16 Sep 2021 13:30:54 +0200 Subject: [PATCH 12/29] [ML] fix i18 ids --- .../register_transform_health_rule.ts | 2 +- .../transform_health_rule_trigger.tsx | 4 ++-- .../transform_selector_control.tsx | 15 +-------------- .../register_transform_alerting_rules.ts | 18 ------------------ 4 files changed, 4 insertions(+), 35 deletions(-) delete mode 100644 x-pack/plugins/transform/server/lib/alerting/register_transform_alerting_rules.ts diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts index dfcf3976b64bf..2fb3e0b63cc91 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts @@ -35,7 +35,7 @@ export function createTransformHealthRuleType(): AlertTypeModel = ({ } @@ -104,7 +104,7 @@ const TransformHealthRuleTrigger: FC = ({ } diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_selector_control.tsx b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_selector_control.tsx index d9890b88c4bf7..4300b75cb3fa4 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_selector_control.tsx +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_selector_control.tsx @@ -7,7 +7,6 @@ import { EuiComboBox, EuiComboBoxProps, EuiFormRow } from '@elastic/eui'; import React, { FC, useMemo } from 'react'; -import { FormattedMessage } from '@kbn/i18n/react'; import { ALL_TRANSFORMS_SELECTION } from '../../../common/constants'; import { isDefined } from '../../../common/types/common'; @@ -55,19 +54,7 @@ export const TransformSelectorControl: FC = ({ }, [options, allowSelectAll]); return ( - - ) - } - isInvalid={!!errors?.length} - error={errors} - > + singleSelection={false} selectedOptions={selectedOptionsEui} diff --git a/x-pack/plugins/transform/server/lib/alerting/register_transform_alerting_rules.ts b/x-pack/plugins/transform/server/lib/alerting/register_transform_alerting_rules.ts deleted file mode 100644 index 7bcebdee639a5..0000000000000 --- a/x-pack/plugins/transform/server/lib/alerting/register_transform_alerting_rules.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import type { Logger } from 'kibana/server'; -import type { AlertingPlugin } from '../../../../alerting/server'; -// import { registerTransformHealthRuleType } from './transform_health_rule_type'; - -export interface RegisterAlertParams { - alerting: AlertingPlugin['setup']; - logger: Logger; -} -// export function registerTransformAlertingRules(params: RegisterAlertParams) { -// registerTransformHealthRuleType(params); -// } From 25e205ddab68572209b771a93a6d4ffee602b054 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Thu, 16 Sep 2021 13:57:34 +0200 Subject: [PATCH 13/29] [ML] update description --- .../register_transform_health_rule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts index 2fb3e0b63cc91..19a820bc35fad 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts @@ -15,7 +15,7 @@ export function createTransformHealthRuleType(): AlertTypeModel Date: Thu, 16 Sep 2021 14:04:26 +0200 Subject: [PATCH 14/29] [ML] validation for Included transforms --- .../register_transform_health_rule.ts | 11 +++++++++++ .../transform_health_rule_trigger.tsx | 1 + 2 files changed, 12 insertions(+) diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts index 19a820bc35fad..16240ffb1e7c5 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts @@ -29,6 +29,17 @@ export function createTransformHealthRuleType(): AlertTypeModel, }; + if (!alertParams.includeTransforms?.length) { + validationResult.errors.includeTransforms?.push( + i18n.translate( + 'xpack.transform.alertTypes.transformHealth.includeTransforms.errorMessage', + { + defaultMessage: 'At least one transform has to be selected', + } + ) + ); + } + return validationResult; }, requiresAppContext: false, diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx index ce7432ea96562..a07bb1f0b9794 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx @@ -95,6 +95,7 @@ const TransformHealthRuleTrigger: FC = ({ selectedOptions={alertParams.includeTransforms ?? []} onChange={onAlertParamChange('includeTransforms')} allowSelectAll + errors={errors.includeTransforms as string[]} /> From 4a66cd50e3a14683934d87295255e9959d2b9f59 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Thu, 16 Sep 2021 14:12:09 +0200 Subject: [PATCH 15/29] [ML] fix exclude condtition --- .../transform_health_rule_type/transform_health_service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts index cb9bb5bc10e98..28ce12847f62d 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts @@ -60,7 +60,7 @@ export function transformHealthServiceProvider(esClient: ElasticsearchClient) { if (excludeTransforms && excludeTransforms.length > 0) { const excludeIdsSet = new Set(excludeTransforms); - resultTransformIds = resultTransformIds.filter((id) => excludeIdsSet.has(id)); + resultTransformIds = resultTransformIds.filter((id) => !excludeIdsSet.has(id)); } return resultTransformIds; From 71435068f2c35429e4022970d7401b3b7eb929b1 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Thu, 16 Sep 2021 14:29:34 +0200 Subject: [PATCH 16/29] [ML] remove transform rule from the monitoring rules --- x-pack/plugins/monitoring/common/constants.ts | 4 +--- x-pack/plugins/monitoring/server/plugin.test.ts | 4 +++- x-pack/plugins/monitoring/server/plugin.ts | 9 ++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/monitoring/common/constants.ts b/x-pack/plugins/monitoring/common/constants.ts index db4fb208f1728..3f03680e687b1 100644 --- a/x-pack/plugins/monitoring/common/constants.ts +++ b/x-pack/plugins/monitoring/common/constants.ts @@ -8,7 +8,6 @@ import { i18n } from '@kbn/i18n'; import { CommonAlertParamDetail } from './types/alerts'; import { AlertParamType } from './enums'; -import { TRANSFORM_RULE_TYPE } from '../../transform/common'; /** * Helper string to add as a tag in every logging call @@ -539,8 +538,7 @@ export const RULES = [ RULE_THREAD_POOL_WRITE_REJECTIONS, RULE_CCR_READ_EXCEPTIONS, RULE_LARGE_SHARD_SIZE, - TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH, -] as const; +]; /** * A list of all legacy rules, which means they are powered by watcher diff --git a/x-pack/plugins/monitoring/server/plugin.test.ts b/x-pack/plugins/monitoring/server/plugin.test.ts index b67d77b9a425b..68453a849a15b 100644 --- a/x-pack/plugins/monitoring/server/plugin.test.ts +++ b/x-pack/plugins/monitoring/server/plugin.test.ts @@ -7,6 +7,7 @@ import { coreMock } from 'src/core/server/mocks'; import { MonitoringPlugin } from './plugin'; +import { AlertsFactory } from './alerts'; jest.mock('./es_client/instantiate_client', () => ({ instantiateClient: jest.fn().mockImplementation(() => ({ @@ -71,8 +72,9 @@ describe('Monitoring plugin', () => { }); it('should register all alerts', async () => { + const alerts = AlertsFactory.getAll(); const plugin = new MonitoringPlugin(initializerContext as any); await plugin.setup(coreSetup as any, setupPlugins as any); - expect(setupPlugins.alerting.registerType).toHaveBeenCalledTimes(16); + expect(setupPlugins.alerting.registerType).toHaveBeenCalledTimes(alerts.length); }); }); diff --git a/x-pack/plugins/monitoring/server/plugin.ts b/x-pack/plugins/monitoring/server/plugin.ts index ae7c4b4326e6a..59065cd5a03c2 100644 --- a/x-pack/plugins/monitoring/server/plugin.ts +++ b/x-pack/plugins/monitoring/server/plugin.ts @@ -52,6 +52,7 @@ import { RequestHandlerContextMonitoringPlugin, } from './types'; import { getTransformHealthRuleType } from '../../transform/server'; +import { TRANSFORM_RULE_TYPE } from '../../transform/common'; // This is used to test the version of kibana const snapshotRegex = /-snapshot/i; @@ -269,6 +270,8 @@ export class MonitoringPlugin } registerPluginInUI(plugins: PluginsSetup) { + const alertingRules = [...RULES, TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH]; + plugins.features.registerKibanaFeature({ id: 'monitoring', name: i18n.translate('xpack.monitoring.featureRegistry.monitoringFeatureName', { @@ -278,7 +281,7 @@ export class MonitoringPlugin app: ['monitoring', 'kibana'], catalogue: ['monitoring'], privileges: null, - alerting: RULES, + alerting: alertingRules, reserved: { description: i18n.translate('xpack.monitoring.feature.reserved.description', { defaultMessage: 'To grant users access, you should also assign the monitoring_user role.', @@ -295,10 +298,10 @@ export class MonitoringPlugin }, alerting: { rule: { - all: RULES, + all: alertingRules, }, alert: { - all: RULES, + all: alertingRules, }, }, ui: [], From b7c5e396a587a9b82b3e06ca45c62472d349e1f7 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Thu, 16 Sep 2021 14:56:16 +0200 Subject: [PATCH 17/29] [ML] add line break --- .../transform_health_rule_type/register_transform_health_rule.ts | 1 + .../transform_health_rule_type/transform_health_service.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts index 16240ffb1e7c5..fcd945c7d85c5 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts @@ -57,6 +57,7 @@ export function createTransformHealthRuleType(): AlertTypeModel Date: Thu, 16 Sep 2021 16:08:03 +0200 Subject: [PATCH 18/29] [ML] disable control --- .../transform_health_rule_type/tests_selection_control.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx index a28fd15ca09ba..f7156bce5b2fe 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx @@ -52,6 +52,7 @@ export const TestsSelectionControl: FC = React.memo( > Date: Thu, 16 Sep 2021 16:11:25 +0200 Subject: [PATCH 19/29] [ML] update context description --- .../register_transform_health_rule_type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts index c07a82f4fa2e0..780f45111632e 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts @@ -68,7 +68,7 @@ export function getTransformHealthRuleType(): AlertType< description: i18n.translate( 'xpack.transform.alertTypes.transformHealth.alertContext.resultsDescription', { - defaultMessage: 'Results of the rule execution', + defaultMessage: 'Rule execution results', } ), }, From fe295c232693db5a1574229017da64674c21bebc Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Thu, 16 Sep 2021 20:14:49 +0200 Subject: [PATCH 20/29] [ML] update test assertion --- x-pack/plugins/monitoring/server/plugin.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/monitoring/server/plugin.test.ts b/x-pack/plugins/monitoring/server/plugin.test.ts index 68453a849a15b..7db9ee6bd5ede 100644 --- a/x-pack/plugins/monitoring/server/plugin.test.ts +++ b/x-pack/plugins/monitoring/server/plugin.test.ts @@ -75,6 +75,7 @@ describe('Monitoring plugin', () => { const alerts = AlertsFactory.getAll(); const plugin = new MonitoringPlugin(initializerContext as any); await plugin.setup(coreSetup as any, setupPlugins as any); - expect(setupPlugins.alerting.registerType).toHaveBeenCalledTimes(alerts.length); + // provided by the factory + transform health + expect(setupPlugins.alerting.registerType).toHaveBeenCalledTimes(alerts.length + 1); }); }); From e8ba26e648fddf988380e7f4edc958d1b4799173 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 22 Sep 2021 08:54:21 +0200 Subject: [PATCH 21/29] Update text Co-authored-by: Lisa Cawley --- x-pack/plugins/transform/common/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/transform/common/constants.ts b/x-pack/plugins/transform/common/constants.ts index 39e37e37cfe06..a02e5b6a65550 100644 --- a/x-pack/plugins/transform/common/constants.ts +++ b/x-pack/plugins/transform/common/constants.ts @@ -124,7 +124,7 @@ export const TRANSFORM_HEALTH_CHECK_NAMES: Record< description: i18n.translate( 'xpack.transform.alertTypes.transformHealth.notStartedCheckDescription', { - defaultMessage: 'Get alerted if the transform is not started or indexing any data.', + defaultMessage: 'Get alerts when the transform is not started or is not indexing data.', } ), }, From 76ef1412a7337e416ba3d483002a933082a8ccd2 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Mon, 4 Oct 2021 15:12:43 +0200 Subject: [PATCH 22/29] [ML] fix eslint --- x-pack/plugins/monitoring/public/plugin.ts | 3 ++- .../transform_health_rule_trigger.tsx | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/monitoring/public/plugin.ts b/x-pack/plugins/monitoring/public/plugin.ts index 06762104b0fb8..593954e97759e 100644 --- a/x-pack/plugins/monitoring/public/plugin.ts +++ b/x-pack/plugins/monitoring/public/plugin.ts @@ -41,7 +41,8 @@ const HASH_CHANGE = 'hashchange'; export class MonitoringPlugin implements - Plugin { + Plugin +{ constructor(private initializerContext: PluginInitializerContext) {} public async setup( diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx index a07bb1f0b9794..c3e4046a30626 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/transform_health_rule_trigger.tsx @@ -18,7 +18,8 @@ import { useToastNotifications } from '../../app/app_dependencies'; import { GetTransformsResponseSchema } from '../../../common/api_schemas/transforms'; import { ALL_TRANSFORMS_SELECTION } from '../../../common/constants'; -export type TransformHealthRuleTriggerProps = AlertTypeParamsExpressionProps; +export type TransformHealthRuleTriggerProps = + AlertTypeParamsExpressionProps; const TransformHealthRuleTrigger: FC = ({ alertParams, @@ -33,11 +34,10 @@ const TransformHealthRuleTrigger: FC = ({ const [transformOptions, setTransformOptions] = useState([]); const onAlertParamChange = useCallback( - (param: T) => ( - update: TransformHealthRuleParams[T] - ) => { - setAlertParams(param, update); - }, + (param: T) => + (update: TransformHealthRuleParams[T]) => { + setAlertParams(param, update); + }, [setAlertParams] ); From a4f2e285e866bb5a8a36dfb98864e37d6acb02d0 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Mon, 4 Oct 2021 15:13:12 +0200 Subject: [PATCH 23/29] [ML] fix eslint --- .../tests_selection_control.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx index f7156bce5b2fe..cd00b21862364 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/tests_selection_control.tsx @@ -39,9 +39,11 @@ export const TestsSelectionControl: FC = React.memo( return ( <> - {(Object.entries(uiConfig) as Array< - [TransformHealthTests, typeof uiConfig[TransformHealthTests]] - >).map(([name, conf], i) => { + {( + Object.entries(uiConfig) as Array< + [TransformHealthTests, typeof uiConfig[TransformHealthTests]] + > + ).map(([name, conf], i) => { return ( Date: Tue, 5 Oct 2021 14:37:26 +0200 Subject: [PATCH 24/29] [ML] api integration tests for transform alerting rule --- .../spaces_only/tests/alerting/index.ts | 1 + .../alerting/transform_rule_types/index.ts | 16 ++ .../transform_health/alert.ts | 206 ++++++++++++++++++ .../transform_health/index.ts | 15 ++ .../test/functional/services/transform/api.ts | 5 + 5 files changed, 243 insertions(+) create mode 100644 x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/index.ts create mode 100644 x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/transform_health/alert.ts create mode 100644 x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/transform_health/index.ts diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/index.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/index.ts index 3a4cc62c2550f..531046013263f 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/index.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/index.ts @@ -35,6 +35,7 @@ export default function alertingTests({ loadTestFile, getService }: FtrProviderC loadTestFile(require.resolve('./alerts_space1')); loadTestFile(require.resolve('./alerts_default_space')); loadTestFile(require.resolve('./builtin_alert_types')); + loadTestFile(require.resolve('./transform_rule_types')); loadTestFile(require.resolve('./mustache_templates.ts')); loadTestFile(require.resolve('./notify_when')); loadTestFile(require.resolve('./ephemeral')); diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/index.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/index.ts new file mode 100644 index 0000000000000..072e318da2df9 --- /dev/null +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/index.ts @@ -0,0 +1,16 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { FtrProviderContext } from '../../../../common/ftr_provider_context'; + +// eslint-disable-next-line import/no-default-export +export default function alertingTests({ loadTestFile }: FtrProviderContext) { + describe('transform alert rule types', function () { + this.tags('dima'); + loadTestFile(require.resolve('./transform_health')); + }); +} diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/transform_health/alert.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/transform_health/alert.ts new file mode 100644 index 0000000000000..c5fb4ec61aa4f --- /dev/null +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/transform_health/alert.ts @@ -0,0 +1,206 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; +import { + ES_TEST_INDEX_NAME, + ESTestIndexTool, + getUrlPrefix, + ObjectRemover, +} from '../../../../../common/lib'; +import { Spaces } from '../../../../scenarios'; +import { PutTransformsRequestSchema } from '../../../../../../../plugins/transform/common/api_schemas/transforms'; + +const ACTION_TYPE_ID = '.index'; +const ALERT_TYPE_ID = 'transform_health'; +const ES_TEST_INDEX_SOURCE = 'transform-alert:transform-health'; +const ES_TEST_INDEX_REFERENCE = '-na-'; +const ES_TEST_OUTPUT_INDEX_NAME = `${ES_TEST_INDEX_NAME}-ts-output`; + +const ALERT_INTERVAL_SECONDS = 3; + +interface CreateAlertParams { + name: string; + includeTransforms: string[]; + excludeTransforms?: string[] | null; + testsConfig?: { + notStarted?: { + enabled: boolean; + } | null; + } | null; +} + +export function generateDestIndex(transformId: string): string { + return `user-${transformId}`; +} + +export function generateTransformConfig(transformId: string): PutTransformsRequestSchema { + const destinationIndex = generateDestIndex(transformId); + + return { + source: { index: ['ft_farequote'] }, + pivot: { + group_by: { airline: { terms: { field: 'airline' } } }, + aggregations: { '@timestamp.value_count': { value_count: { field: '@timestamp' } } }, + }, + dest: { index: destinationIndex }, + sync: { + time: { field: '@timestamp' }, + }, + }; +} + +// eslint-disable-next-line import/no-default-export +export default function alertTests({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + const esArchiver = getService('esArchiver'); + const retry = getService('retry'); + const es = getService('es'); + const log = getService('log'); + const transform = getService('transform'); + + const esTestIndexTool = new ESTestIndexTool(es, retry); + const esTestIndexToolOutput = new ESTestIndexTool(es, retry, ES_TEST_OUTPUT_INDEX_NAME); + + describe('alert', async () => { + const objectRemover = new ObjectRemover(supertest); + let actionId: string; + const transformId = 'test_transform_01'; + const destinationIndex = generateDestIndex(transformId); + + beforeEach(async () => { + await esTestIndexTool.destroy(); + await esTestIndexTool.setup(); + + await esTestIndexToolOutput.destroy(); + await esTestIndexToolOutput.setup(); + + await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote'); + await transform.testResources.setKibanaTimeZoneToUTC(); + + actionId = await createAction(); + + await transform.api.createIndices(destinationIndex); + await createTransform(transformId); + }); + + afterEach(async () => { + await objectRemover.removeAll(); + await esTestIndexTool.destroy(); + await esTestIndexToolOutput.destroy(); + await transform.api.cleanTransformIndices(); + }); + + it('runs correctly', async () => { + await createAlert({ + name: 'Test all transforms', + includeTransforms: ['*'], + }); + + await stopTransform(transformId); + + log.debug('Checking created alert instances...'); + + const docs = await waitForDocs(1); + for (const doc of docs) { + const { name, message } = doc._source.params; + + expect(name).to.be('Test all transforms'); + expect(message).to.be('Transform test_transform_01 is not started.'); + } + }); + + async function waitForDocs(count: number): Promise { + return await esTestIndexToolOutput.waitForDocs( + ES_TEST_INDEX_SOURCE, + ES_TEST_INDEX_REFERENCE, + count + ); + } + + async function createTransform(id: string) { + const config = generateTransformConfig(id); + await transform.api.createAndRunTransform(id, config); + } + + async function createAlert(params: CreateAlertParams): Promise { + log.debug(`Creating an alerting rule "${params.name}"...`); + const action = { + id: actionId, + group: 'transform_issue', + params: { + documents: [ + { + source: ES_TEST_INDEX_SOURCE, + reference: ES_TEST_INDEX_REFERENCE, + params: { + name: '{{{alertName}}}', + message: '{{{context.message}}}', + }, + }, + ], + }, + }; + + const { status, body: createdAlert } = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send({ + name: params.name, + consumer: 'alerts', + enabled: true, + rule_type_id: ALERT_TYPE_ID, + schedule: { interval: `${ALERT_INTERVAL_SECONDS}s` }, + actions: [action], + notify_when: 'onActiveAlert', + params: { + includeTransforms: params.includeTransforms, + }, + }); + + // will print the error body, if an error occurred + // if (statusCode !== 200) console.log(createdAlert); + + expect(status).to.be(200); + + const alertId = createdAlert.id; + objectRemover.add(Spaces.space1.id, alertId, 'rule', 'alerting'); + + return alertId; + } + + async function stopTransform(id: string) { + await transform.api.stopTransform(id); + } + + async function createAction(): Promise { + log.debug('Creating an action...'); + // @ts-ignore + const { statusCode, body: createdAction } = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/api/actions/connector`) + .set('kbn-xsrf', 'foo') + .send({ + name: 'index action for transform health FT', + connector_type_id: ACTION_TYPE_ID, + config: { + index: ES_TEST_OUTPUT_INDEX_NAME, + }, + secrets: {}, + }); + + expect(statusCode).to.be(200); + + log.debug(`Action with id "${createdAction.id}" has been created.`); + + const resultId = createdAction.id; + objectRemover.add(Spaces.space1.id, resultId, 'connector', 'actions'); + + return resultId; + } + }); +} diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/transform_health/index.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/transform_health/index.ts new file mode 100644 index 0000000000000..c324745b85813 --- /dev/null +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/transform_rule_types/transform_health/index.ts @@ -0,0 +1,15 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; + +// eslint-disable-next-line import/no-default-export +export default function alertingTests({ loadTestFile }: FtrProviderContext) { + describe('transform_health', function () { + loadTestFile(require.resolve('./alert')); + }); +} diff --git a/x-pack/test/functional/services/transform/api.ts b/x-pack/test/functional/services/transform/api.ts index 484d794aac879..73dff415832f6 100644 --- a/x-pack/test/functional/services/transform/api.ts +++ b/x-pack/test/functional/services/transform/api.ts @@ -234,6 +234,11 @@ export function TransformAPIProvider({ getService }: FtrProviderContext) { await esSupertest.post(`/_transform/${transformId}/_start`).expect(200); }, + async stopTransform(transformId: string) { + log.debug(`Stopping transform '${transformId}' ...`); + await esSupertest.post(`/_transform/${transformId}/_stop`).expect(200); + }, + async createAndRunTransform(transformId: string, transformConfig: PutTransformsRequestSchema) { await this.createTransform(transformId, transformConfig); await this.startTransform(transformId); From a6d8fe63536a84424a24e8569076c0ef835dcc2b Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 6 Oct 2021 13:47:16 +0200 Subject: [PATCH 25/29] [ML] move transform alert setup, set Stack Rules as a producer --- x-pack/plugins/monitoring/kibana.json | 2 +- x-pack/plugins/monitoring/public/plugin.ts | 2 -- x-pack/plugins/monitoring/server/plugin.ts | 11 +++-------- x-pack/plugins/monitoring/tsconfig.json | 1 - x-pack/plugins/stack_alerts/server/feature.ts | 13 ++++++++----- x-pack/plugins/stack_alerts/tsconfig.json | 3 ++- x-pack/plugins/transform/public/alerting/index.ts | 2 +- .../alerting/transform_health_rule_type/index.ts | 2 +- .../register_transform_health_rule.ts | 2 +- x-pack/plugins/transform/public/index.ts | 2 +- x-pack/plugins/transform/public/plugin.ts | 7 ++++++- x-pack/plugins/transform/server/index.ts | 2 +- .../transform/server/lib/alerting/index.ts | 5 ++++- .../alerting/transform_health_rule_type/index.ts | 5 ++++- .../register_transform_health_rule_type.ts | 15 ++++++++++++++- x-pack/plugins/transform/server/plugin.ts | 7 ++++++- x-pack/plugins/transform/tsconfig.json | 1 + 17 files changed, 54 insertions(+), 28 deletions(-) diff --git a/x-pack/plugins/monitoring/kibana.json b/x-pack/plugins/monitoring/kibana.json index 20a1bc5e51b29..bf5e0ff2e16e3 100644 --- a/x-pack/plugins/monitoring/kibana.json +++ b/x-pack/plugins/monitoring/kibana.json @@ -27,5 +27,5 @@ ], "server": true, "ui": true, - "requiredBundles": ["kibanaUtils", "home", "alerting", "kibanaReact", "licenseManagement", "transform"] + "requiredBundles": ["kibanaUtils", "home", "alerting", "kibanaReact", "licenseManagement"] } diff --git a/x-pack/plugins/monitoring/public/plugin.ts b/x-pack/plugins/monitoring/public/plugin.ts index 593954e97759e..aee5072947531 100644 --- a/x-pack/plugins/monitoring/public/plugin.ts +++ b/x-pack/plugins/monitoring/public/plugin.ts @@ -203,7 +203,6 @@ export class MonitoringPlugin const { createMemoryUsageAlertType } = await import('./alerts/memory_usage_alert'); const { createCCRReadExceptionsAlertType } = await import('./alerts/ccr_read_exceptions_alert'); const { createLargeShardSizeAlertType } = await import('./alerts/large_shard_size_alert'); - const { createTransformHealthRuleType } = await import('../../transform/public'); ruleTypeRegistry.register(createCpuUsageAlertType(config)); ruleTypeRegistry.register(createDiskUsageAlertType(config)); @@ -225,7 +224,6 @@ export class MonitoringPlugin ); ruleTypeRegistry.register(createCCRReadExceptionsAlertType(config)); ruleTypeRegistry.register(createLargeShardSizeAlertType(config)); - ruleTypeRegistry.register(createTransformHealthRuleType()); const legacyAlertTypes = createLegacyAlertTypes(config); for (const legacyAlertType of legacyAlertTypes) { ruleTypeRegistry.register(legacyAlertType); diff --git a/x-pack/plugins/monitoring/server/plugin.ts b/x-pack/plugins/monitoring/server/plugin.ts index 2714905dc129f..25fffd94d86a4 100644 --- a/x-pack/plugins/monitoring/server/plugin.ts +++ b/x-pack/plugins/monitoring/server/plugin.ts @@ -51,8 +51,6 @@ import { PluginsStart, RequestHandlerContextMonitoringPlugin, } from './types'; -import { getTransformHealthRuleType } from '../../transform/server'; -import { TRANSFORM_RULE_TYPE } from '../../transform/common'; // This is used to test the version of kibana const snapshotRegex = /-snapshot/i; @@ -130,7 +128,6 @@ export class MonitoringPlugin for (const alert of alerts) { plugins.alerting?.registerType(alert.getRuleType()); } - plugins.alerting?.registerType(getTransformHealthRuleType()); const config = createConfig(this.initializerContext.config.get>()); @@ -271,8 +268,6 @@ export class MonitoringPlugin } registerPluginInUI(plugins: PluginsSetup) { - const alertingRules = [...RULES, TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH]; - plugins.features.registerKibanaFeature({ id: 'monitoring', name: i18n.translate('xpack.monitoring.featureRegistry.monitoringFeatureName', { @@ -282,7 +277,7 @@ export class MonitoringPlugin app: ['monitoring', 'kibana'], catalogue: ['monitoring'], privileges: null, - alerting: alertingRules, + alerting: RULES, reserved: { description: i18n.translate('xpack.monitoring.feature.reserved.description', { defaultMessage: 'To grant users access, you should also assign the monitoring_user role.', @@ -299,10 +294,10 @@ export class MonitoringPlugin }, alerting: { rule: { - all: alertingRules, + all: RULES, }, alert: { - all: alertingRules, + all: RULES, }, }, ui: [], diff --git a/x-pack/plugins/monitoring/tsconfig.json b/x-pack/plugins/monitoring/tsconfig.json index 4bc5e55800fcb..756b8528865ce 100644 --- a/x-pack/plugins/monitoring/tsconfig.json +++ b/x-pack/plugins/monitoring/tsconfig.json @@ -31,6 +31,5 @@ { "path": "../observability/tsconfig.json" }, { "path": "../telemetry_collection_xpack/tsconfig.json" }, { "path": "../triggers_actions_ui/tsconfig.json" }, - { "path": "../transform/tsconfig.json" }, ] } diff --git a/x-pack/plugins/stack_alerts/server/feature.ts b/x-pack/plugins/stack_alerts/server/feature.ts index 70e68c2b7ced3..39ea41374df7b 100644 --- a/x-pack/plugins/stack_alerts/server/feature.ts +++ b/x-pack/plugins/stack_alerts/server/feature.ts @@ -12,6 +12,9 @@ import { GEO_CONTAINMENT_ID as GeoContainment } from './alert_types/geo_containm import { ES_QUERY_ID as ElasticsearchQuery } from './alert_types/es_query/alert_type'; import { STACK_ALERTS_FEATURE_ID } from '../common'; import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/server'; +import { TRANSFORM_RULE_TYPE } from '../../transform/common'; + +const TransformHealth = TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH; export const BUILT_IN_ALERTS_FEATURE: KibanaFeatureConfig = { id: STACK_ALERTS_FEATURE_ID, @@ -23,7 +26,7 @@ export const BUILT_IN_ALERTS_FEATURE: KibanaFeatureConfig = { management: { insightsAndAlerting: ['triggersActions'], }, - alerting: [IndexThreshold, GeoContainment, ElasticsearchQuery], + alerting: [IndexThreshold, GeoContainment, ElasticsearchQuery, TransformHealth], privileges: { all: { app: [], @@ -33,10 +36,10 @@ export const BUILT_IN_ALERTS_FEATURE: KibanaFeatureConfig = { }, alerting: { rule: { - all: [IndexThreshold, GeoContainment, ElasticsearchQuery], + all: [IndexThreshold, GeoContainment, ElasticsearchQuery, TransformHealth], }, alert: { - all: [IndexThreshold, GeoContainment, ElasticsearchQuery], + all: [IndexThreshold, GeoContainment, ElasticsearchQuery, TransformHealth], }, }, savedObject: { @@ -54,10 +57,10 @@ export const BUILT_IN_ALERTS_FEATURE: KibanaFeatureConfig = { }, alerting: { rule: { - read: [IndexThreshold, GeoContainment, ElasticsearchQuery], + read: [IndexThreshold, GeoContainment, ElasticsearchQuery, TransformHealth], }, alert: { - read: [IndexThreshold, GeoContainment, ElasticsearchQuery], + read: [IndexThreshold, GeoContainment, ElasticsearchQuery, TransformHealth], }, }, savedObject: { diff --git a/x-pack/plugins/stack_alerts/tsconfig.json b/x-pack/plugins/stack_alerts/tsconfig.json index f3ae4509f35be..ab3864342e57d 100644 --- a/x-pack/plugins/stack_alerts/tsconfig.json +++ b/x-pack/plugins/stack_alerts/tsconfig.json @@ -19,6 +19,7 @@ { "path": "../triggers_actions_ui/tsconfig.json" }, { "path": "../../../src/plugins/kibana_react/tsconfig.json" }, { "path": "../../../src/plugins/saved_objects/tsconfig.json" }, - { "path": "../../../src/plugins/data/tsconfig.json" } + { "path": "../../../src/plugins/data/tsconfig.json" }, + { "path": "../transform/tsconfig.json" } ] } diff --git a/x-pack/plugins/transform/public/alerting/index.ts b/x-pack/plugins/transform/public/alerting/index.ts index 1dcd028bf7200..0c693cc4bfc06 100644 --- a/x-pack/plugins/transform/public/alerting/index.ts +++ b/x-pack/plugins/transform/public/alerting/index.ts @@ -5,4 +5,4 @@ * 2.0. */ -export { createTransformHealthRuleType } from './transform_health_rule_type'; +export { getTransformHealthRuleType } from './transform_health_rule_type'; diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts index a6941d088696c..87ced49577a91 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/index.ts @@ -5,4 +5,4 @@ * 2.0. */ -export { createTransformHealthRuleType } from './register_transform_health_rule'; +export { getTransformHealthRuleType } from './register_transform_health_rule'; diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts index fcd945c7d85c5..83117966f73d1 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts @@ -11,7 +11,7 @@ import { TRANSFORM_RULE_TYPE } from '../../../common'; import type { TransformHealthRuleParams } from '../../../common/types/alerting'; import type { AlertTypeModel } from '../../../../triggers_actions_ui/public'; -export function createTransformHealthRuleType(): AlertTypeModel { +export function getTransformHealthRuleType(): AlertTypeModel { return { id: TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH, description: i18n.translate('xpack.transform.alertingRuleTypes.transformHealth.description', { diff --git a/x-pack/plugins/transform/public/index.ts b/x-pack/plugins/transform/public/index.ts index d05117b7ddd72..ebe43aea75440 100644 --- a/x-pack/plugins/transform/public/index.ts +++ b/x-pack/plugins/transform/public/index.ts @@ -13,4 +13,4 @@ export const plugin = () => { return new TransformUiPlugin(); }; -export { createTransformHealthRuleType } from './alerting'; +export { getTransformHealthRuleType } from './alerting'; diff --git a/x-pack/plugins/transform/public/plugin.ts b/x-pack/plugins/transform/public/plugin.ts index d18d846ee7e07..4ed4e64070344 100644 --- a/x-pack/plugins/transform/public/plugin.ts +++ b/x-pack/plugins/transform/public/plugin.ts @@ -16,6 +16,7 @@ import type { SharePluginStart } from 'src/plugins/share/public'; import { registerFeature } from './register_feature'; import type { PluginSetupContract as AlertingSetup } from '../../alerting/public'; import type { TriggersAndActionsUIPublicPluginSetup } from '../../triggers_actions_ui/public'; +import { getTransformHealthRuleType } from './alerting'; export interface PluginsDependencies { data: DataPublicPluginStart; @@ -29,7 +30,7 @@ export interface PluginsDependencies { export class TransformUiPlugin { public setup(coreSetup: CoreSetup, pluginsSetup: PluginsDependencies): void { - const { management, home } = pluginsSetup; + const { management, home, triggersActionsUi } = pluginsSetup; // Register management section const esSection = management.sections.section.data; @@ -45,6 +46,10 @@ export class TransformUiPlugin { }, }); registerFeature(home); + + if (triggersActionsUi) { + triggersActionsUi.ruleTypeRegistry.register(getTransformHealthRuleType()); + } } public start() {} diff --git a/x-pack/plugins/transform/server/index.ts b/x-pack/plugins/transform/server/index.ts index c1ec42114818d..9bd3ffe418b1e 100644 --- a/x-pack/plugins/transform/server/index.ts +++ b/x-pack/plugins/transform/server/index.ts @@ -11,4 +11,4 @@ import { TransformServerPlugin } from './plugin'; export const plugin = (ctx: PluginInitializerContext) => new TransformServerPlugin(ctx); -export { getTransformHealthRuleType } from './lib/alerting'; +export { registerTransformHealthRuleType } from './lib/alerting'; diff --git a/x-pack/plugins/transform/server/lib/alerting/index.ts b/x-pack/plugins/transform/server/lib/alerting/index.ts index 0c693cc4bfc06..1d75af94f2a72 100644 --- a/x-pack/plugins/transform/server/lib/alerting/index.ts +++ b/x-pack/plugins/transform/server/lib/alerting/index.ts @@ -5,4 +5,7 @@ * 2.0. */ -export { getTransformHealthRuleType } from './transform_health_rule_type'; +export { + getTransformHealthRuleType, + registerTransformHealthRuleType, +} from './transform_health_rule_type'; diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/index.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/index.ts index 08f9fc85659fb..cef3d578df658 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/index.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/index.ts @@ -5,4 +5,7 @@ * 2.0. */ -export { getTransformHealthRuleType } from './register_transform_health_rule_type'; +export { + getTransformHealthRuleType, + registerTransformHealthRuleType, +} from './register_transform_health_rule_type'; diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts index 780f45111632e..15c567884d4f7 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts @@ -6,6 +6,7 @@ */ import { i18n } from '@kbn/i18n'; +import { Logger } from 'src/core/server'; import type { ActionGroup, AlertInstanceContext, @@ -16,6 +17,8 @@ import { PLUGIN, TRANSFORM_RULE_TYPE } from '../../../../common/constants'; import { transformHealthRuleParams, TransformHealthRuleParams } from './schema'; import { AlertType } from '../../../../../alerting/server'; import { transformHealthServiceProvider } from './transform_health_service'; +import type { PluginSetupContract as AlertingSetup } from '../../../../../alerting/server'; +import { STACK_ALERTS_FEATURE_ID } from '../../../../../stack_alerts/common'; export interface BaseResponse { transform_id: string; @@ -45,6 +48,16 @@ export const TRANSFORM_ISSUE_DETECTED: ActionGroup = { }), }; +interface RegisterParams { + logger: Logger; + alerting: AlertingSetup; +} + +export function registerTransformHealthRuleType(params: RegisterParams) { + const { alerting } = params; + alerting.registerType(getTransformHealthRuleType()); +} + export function getTransformHealthRuleType(): AlertType< TransformHealthRuleParams, never, @@ -83,7 +96,7 @@ export function getTransformHealthRuleType(): AlertType< }, ], }, - producer: 'monitoring', + producer: STACK_ALERTS_FEATURE_ID, minimumLicenseRequired: PLUGIN.MINIMUM_LICENSE_REQUIRED, isExportable: true, async executor(options) { diff --git a/x-pack/plugins/transform/server/plugin.ts b/x-pack/plugins/transform/server/plugin.ts index c21e131e056b8..6e542bbefc3e1 100644 --- a/x-pack/plugins/transform/server/plugin.ts +++ b/x-pack/plugins/transform/server/plugin.ts @@ -13,6 +13,7 @@ import { LicenseType } from '../../licensing/common/types'; import { Dependencies } from './types'; import { ApiRoutes } from './routes'; import { License } from './services'; +import { registerTransformHealthRuleType } from './lib/alerting'; const basicLicense: LicenseType = 'basic'; @@ -38,7 +39,7 @@ export class TransformServerPlugin implements Plugin<{}, void, any, any> { setup( { http, getStartServices, elasticsearch }: CoreSetup, - { licensing, features }: Dependencies + { licensing, features, alerting }: Dependencies ): {} { const router = http.createRouter(); @@ -75,6 +76,10 @@ export class TransformServerPlugin implements Plugin<{}, void, any, any> { license: this.license, }); + if (alerting) { + registerTransformHealthRuleType({ alerting, logger: this.logger }); + } + return {}; } diff --git a/x-pack/plugins/transform/tsconfig.json b/x-pack/plugins/transform/tsconfig.json index 99e8baf3f92fc..4f2f85f46351f 100644 --- a/x-pack/plugins/transform/tsconfig.json +++ b/x-pack/plugins/transform/tsconfig.json @@ -21,5 +21,6 @@ { "path": "../license_management/tsconfig.json" }, { "path": "../licensing/tsconfig.json" }, { "path": "../ml/tsconfig.json" }, + { "path": "../stack_alerts/tsconfig.json" } ] } From c363b2ce2e2e14c4b33ad1463bd844e837ae49a6 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 6 Oct 2021 14:09:09 +0200 Subject: [PATCH 26/29] [ML] remove stack_alerts project ref --- .../register_transform_health_rule_type.ts | 3 +-- x-pack/plugins/transform/tsconfig.json | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts index 15c567884d4f7..eb0cf011aeb52 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/register_transform_health_rule_type.ts @@ -18,7 +18,6 @@ import { transformHealthRuleParams, TransformHealthRuleParams } from './schema'; import { AlertType } from '../../../../../alerting/server'; import { transformHealthServiceProvider } from './transform_health_service'; import type { PluginSetupContract as AlertingSetup } from '../../../../../alerting/server'; -import { STACK_ALERTS_FEATURE_ID } from '../../../../../stack_alerts/common'; export interface BaseResponse { transform_id: string; @@ -96,7 +95,7 @@ export function getTransformHealthRuleType(): AlertType< }, ], }, - producer: STACK_ALERTS_FEATURE_ID, + producer: 'stackAlerts', minimumLicenseRequired: PLUGIN.MINIMUM_LICENSE_REQUIRED, isExportable: true, async executor(options) { diff --git a/x-pack/plugins/transform/tsconfig.json b/x-pack/plugins/transform/tsconfig.json index 4f2f85f46351f..99e8baf3f92fc 100644 --- a/x-pack/plugins/transform/tsconfig.json +++ b/x-pack/plugins/transform/tsconfig.json @@ -21,6 +21,5 @@ { "path": "../license_management/tsconfig.json" }, { "path": "../licensing/tsconfig.json" }, { "path": "../ml/tsconfig.json" }, - { "path": "../stack_alerts/tsconfig.json" } ] } From de0a7d908732535f098111255868ebaaa36ed638 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 6 Oct 2021 14:55:49 +0200 Subject: [PATCH 27/29] [ML] update mappings --- .../alerting/server/usage/alerts_usage_collector.ts | 5 +++-- .../telemetry_collection_xpack/schema/xpack_plugins.json | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/alerting/server/usage/alerts_usage_collector.ts b/x-pack/plugins/alerting/server/usage/alerts_usage_collector.ts index 67687045f1b50..453a29b5884e6 100644 --- a/x-pack/plugins/alerting/server/usage/alerts_usage_collector.ts +++ b/x-pack/plugins/alerting/server/usage/alerts_usage_collector.ts @@ -17,6 +17,7 @@ const byTypeSchema: MakeSchemaFrom['count_by_type'] = { // Built-in '__index-threshold': { type: 'long' }, '__es-query': { type: 'long' }, + transform_health: { type: 'long' }, // APM apm__error_rate: { type: 'long' }, // eslint-disable-line @typescript-eslint/naming-convention apm__transaction_error_rate: { type: 'long' }, // eslint-disable-line @typescript-eslint/naming-convention @@ -45,8 +46,8 @@ const byTypeSchema: MakeSchemaFrom['count_by_type'] = { // Maps '__geo-containment': { type: 'long' }, // ML - xpack_ml_anomaly_detection_alert: { type: 'long' }, - xpack_ml_anomaly_detection_jobs_health: { type: 'long' }, + xpack__ml__anomaly_detection_alert: { type: 'long' }, // eslint-disable-line @typescript-eslint/naming-convention + xpack__ml__anomaly_detection_jobs_health: { type: 'long' }, // eslint-disable-line @typescript-eslint/naming-convention }; export function createAlertsUsageCollector( diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json index 98c81a6f9c677..0c51d1371d645 100644 --- a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @@ -226,10 +226,10 @@ "__geo-containment": { "type": "long" }, - "xpack_ml_anomaly_detection_alert": { + "xpack__ml__anomaly_detection_alert": { "type": "long" }, - "xpack_ml_anomaly_detection_jobs_health": { + "xpack__ml__anomaly_detection_jobs_health": { "type": "long" } } @@ -308,10 +308,10 @@ "__geo-containment": { "type": "long" }, - "xpack_ml_anomaly_detection_alert": { + "xpack__ml__anomaly_detection_alert": { "type": "long" }, - "xpack_ml_anomaly_detection_jobs_health": { + "xpack__ml__anomaly_detection_jobs_health": { "type": "long" } } From 0d5253cddf9fe079a9468ccc6c4e84e9ffc0c76e Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 6 Oct 2021 15:06:48 +0200 Subject: [PATCH 28/29] [ML] update mappings --- .../telemetry_collection_xpack/schema/xpack_plugins.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json index 0c51d1371d645..5bb559c137390 100644 --- a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @@ -163,6 +163,9 @@ "__es-query": { "type": "long" }, + "transform_health": { + "type": "long" + }, "apm__error_rate": { "type": "long" }, @@ -245,6 +248,9 @@ "__es-query": { "type": "long" }, + "transform_health": { + "type": "long" + }, "apm__error_rate": { "type": "long" }, From 4cbd7d25c6c55e5c5ce56d6e7888f2766b4018bb Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Wed, 6 Oct 2021 15:55:39 +0200 Subject: [PATCH 29/29] [ML] update unit tests --- x-pack/plugins/monitoring/server/plugin.test.ts | 3 +-- x-pack/plugins/stack_alerts/server/feature.test.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/monitoring/server/plugin.test.ts b/x-pack/plugins/monitoring/server/plugin.test.ts index 7db9ee6bd5ede..68453a849a15b 100644 --- a/x-pack/plugins/monitoring/server/plugin.test.ts +++ b/x-pack/plugins/monitoring/server/plugin.test.ts @@ -75,7 +75,6 @@ describe('Monitoring plugin', () => { const alerts = AlertsFactory.getAll(); const plugin = new MonitoringPlugin(initializerContext as any); await plugin.setup(coreSetup as any, setupPlugins as any); - // provided by the factory + transform health - expect(setupPlugins.alerting.registerType).toHaveBeenCalledTimes(alerts.length + 1); + expect(setupPlugins.alerting.registerType).toHaveBeenCalledTimes(alerts.length); }); }); diff --git a/x-pack/plugins/stack_alerts/server/feature.test.ts b/x-pack/plugins/stack_alerts/server/feature.test.ts index 2836dd1d6d8e7..61d0914fb7df1 100644 --- a/x-pack/plugins/stack_alerts/server/feature.test.ts +++ b/x-pack/plugins/stack_alerts/server/feature.test.ts @@ -32,10 +32,15 @@ describe('Stack Alerts Feature Privileges', () => { BUILT_IN_ALERTS_FEATURE.privileges?.all?.alerting?.rule?.all ?? []; const typesInFeaturePrivilegeRead = BUILT_IN_ALERTS_FEATURE.privileges?.read?.alerting?.rule?.read ?? []; - expect(alertingSetup.registerType.mock.calls.length).toEqual(typesInFeaturePrivilege.length); - expect(alertingSetup.registerType.mock.calls.length).toEqual(typesInFeaturePrivilegeAll.length); + // transform alerting rule is initialized during the transform plugin setup expect(alertingSetup.registerType.mock.calls.length).toEqual( - typesInFeaturePrivilegeRead.length + typesInFeaturePrivilege.length - 1 + ); + expect(alertingSetup.registerType.mock.calls.length).toEqual( + typesInFeaturePrivilegeAll.length - 1 + ); + expect(alertingSetup.registerType.mock.calls.length).toEqual( + typesInFeaturePrivilegeRead.length - 1 ); alertingSetup.registerType.mock.calls.forEach((call) => {