Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Transform] Transforms health alerting rule type #112277

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b7a5e78
[ML] init public code
darnautov Sep 13, 2021
22764b1
[ML] init transform rule type from the monitoring plugin
darnautov Sep 14, 2021
5528e11
[ML] add UI form
darnautov Sep 15, 2021
4e893cd
[ML] only suggest continuous transforms
darnautov Sep 15, 2021
01d4681
[ML] executor code for transform state check
darnautov Sep 15, 2021
ae1f4b4
[ML] update type
darnautov Sep 15, 2021
90b0057
[ML] add description
darnautov Sep 15, 2021
804e98c
[ML] rename state prop
darnautov Sep 15, 2021
fea3b9f
[ML] rename state prop
darnautov Sep 15, 2021
4d38af1
[ML] update test assertion
darnautov Sep 15, 2021
e99df63
[ML] fix import
darnautov Sep 16, 2021
6c27a24
[ML] fix i18 ids
darnautov Sep 16, 2021
25e205d
[ML] update description
darnautov Sep 16, 2021
9b45e6b
[ML] validation for Included transforms
darnautov Sep 16, 2021
4a66cd5
[ML] fix exclude condtition
darnautov Sep 16, 2021
7143506
[ML] remove transform rule from the monitoring rules
darnautov Sep 16, 2021
b7c5e39
[ML] add line break
darnautov Sep 16, 2021
8777531
Merge remote-tracking branch 'upstream/master' into transform-111945-…
darnautov Sep 16, 2021
bbad483
[ML] disable control
darnautov Sep 16, 2021
2d3db4d
[ML] update context description
darnautov Sep 16, 2021
fe295c2
[ML] update test assertion
darnautov Sep 16, 2021
e8ba26e
Update text
darnautov Sep 22, 2021
2f78ca0
Merge branch 'master' into transform-111945-health-alerting-rule
kibanamachine Sep 22, 2021
5f15ad1
Merge remote-tracking branch 'upstream/master' into transform-111945-…
darnautov Sep 23, 2021
422777a
Merge remote-tracking branch 'upstream/master' into transform-111945-…
darnautov Oct 4, 2021
76ef141
[ML] fix eslint
darnautov Oct 4, 2021
a4f2e28
[ML] fix eslint
darnautov Oct 4, 2021
af04cc9
[ML] api integration tests for transform alerting rule
darnautov Oct 5, 2021
621f45a
Merge branch 'master' into transform-111945-health-alerting-rule
kibanamachine Oct 5, 2021
a6d8fe6
[ML] move transform alert setup, set Stack Rules as a producer
darnautov Oct 6, 2021
c363b2c
[ML] remove stack_alerts project ref
darnautov Oct 6, 2021
de0a7d9
[ML] update mappings
darnautov Oct 6, 2021
0d5253c
[ML] update mappings
darnautov Oct 6, 2021
4cbd7d2
[ML] update unit tests
darnautov Oct 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,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`,
Comment on lines +286 to +287
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to address this TODO is the current PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no docs page for it yet, so I'm going to add it in the follow-up PR probably as soon as it's ready

Copy link
Contributor

@szabosteve szabosteve Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darnautov This is the correct link. Docs are available at https://www.elastic.co/guide/en/elasticsearch/reference/master/transform-alerts.html

Suggested change
// TODO add valid docs URL
alertingRules: `${ELASTIC_WEBSITE_URL}guide/en/machine-learning/${DOC_LINK_VERSION}/ml-configuring-alerts.html`,
// TODO add valid docs URL
alertingRules: `${ELASTICSEARCH_DOCS}transform-alerts.html`,

},
visualize: {
guide: `${KIBANA_DOCS}dashboard.html`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const byTypeSchema: MakeSchemaFrom<AlertsUsage>['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
Expand Down Expand Up @@ -45,8 +46,8 @@ const byTypeSchema: MakeSchemaFrom<AlertsUsage>['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(
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class MonitoringPlugin
for (const alert of alerts) {
plugins.alerting?.registerType(alert.getRuleType());
}

const config = createConfig(this.initializerContext.config.get<TypeOf<typeof configSchema>>());

// Register collector objects for stats to show up in the APIs
Expand Down
11 changes: 8 additions & 3 deletions x-pack/plugins/stack_alerts/server/feature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
13 changes: 8 additions & 5 deletions x-pack/plugins/stack_alerts/server/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: [],
Expand All @@ -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: {
Expand All @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/stack_alerts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@
"__es-query": {
"type": "long"
},
"transform_health": {
"type": "long"
},
"apm__error_rate": {
"type": "long"
},
Expand Down Expand Up @@ -226,10 +229,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"
}
}
Expand All @@ -245,6 +248,9 @@
"__es-query": {
"type": "long"
},
"transform_health": {
"type": "long"
},
"apm__error_rate": {
"type": "long"
},
Expand Down Expand Up @@ -308,10 +314,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"
}
}
Expand Down
24 changes: 24 additions & 0 deletions x-pack/plugins/transform/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,3 +109,26 @@ 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;

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 alerts when the transform is not started or is not indexing data.',
}
),
},
};
8 changes: 8 additions & 0 deletions x-pack/plugins/transform/common/index.ts
Original file line number Diff line number Diff line change
@@ -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';
22 changes: 22 additions & 0 deletions x-pack/plugins/transform/common/types/alerting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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[] | null;
testsConfig?: {
notStarted?: {
enabled: boolean;
} | null;
} | null;
} & AlertTypeParams;

export type TransformHealthRuleTestsConfig = TransformHealthRuleParams['testsConfig'];

export type TransformHealthTests = keyof Exclude<TransformHealthRuleTestsConfig, null | undefined>;
4 changes: 4 additions & 0 deletions x-pack/plugins/transform/common/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ export function dictionaryToArray<TValue>(dict: Dictionary<TValue>): TValue[] {
export type DeepPartial<T> = {
[P in keyof T]?: DeepPartial<T[P]>;
};

export function isDefined<T>(argument: T | undefined | null): argument is T {
return argument !== undefined && argument !== null;
}
16 changes: 16 additions & 0 deletions x-pack/plugins/transform/common/utils/alerts.ts
Original file line number Diff line number Diff line change
@@ -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,
},
};
}
10 changes: 8 additions & 2 deletions x-pack/plugins/transform/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
"management",
"features",
"savedObjects",
"share"
"share",
"triggersActionsUi",
"fieldFormats"
],
"optionalPlugins": [
"security",
"usageCollection"
"usageCollection",
"alerting"
],
"configPath": ["xpack", "transform"],
"requiredBundles": [
Expand All @@ -24,6 +27,9 @@
"kibanaReact",
"ml"
],
"extraPublicDirs": [
"common"
],
"owner": {
"name": "Machine Learning UI",
"githubTeam": "ml-ui"
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/transform/public/alerting/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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 '@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 getTransformHealthRuleType(): AlertTypeModel<TransformHealthRuleParams> {
return {
id: TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH,
description: i18n.translate('xpack.transform.alertingRuleTypes.transformHealth.description', {
defaultMessage: 'Alert when transforms 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<string>(),
} as Record<keyof TransformHealthRuleParams, string[]>,
};

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,
defaultActionMessage: i18n.translate(
'xpack.transform.alertTypes.transformHealth.defaultActionMessage',
{
defaultMessage: `[\\{\\{rule.name\\}\\}] Transform health check result:
\\{\\{context.message\\}\\}
\\{\\{#context.results\\}\\}
Transform ID: \\{\\{transform_id\\}\\}
peteharverson marked this conversation as resolved.
Show resolved Hide resolved
\\{\\{#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\\}\\}
`,
}
),
};
}
Loading