Skip to content

Commit

Permalink
[ML] move transform alert setup, set Stack Rules as a producer
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Oct 6, 2021
1 parent 621f45a commit a6d8fe6
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 28 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
],
"server": true,
"ui": true,
"requiredBundles": ["kibanaUtils", "home", "alerting", "kibanaReact", "licenseManagement", "transform"]
"requiredBundles": ["kibanaUtils", "home", "alerting", "kibanaReact", "licenseManagement"]
}
2 changes: 0 additions & 2 deletions x-pack/plugins/monitoring/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand Down
11 changes: 3 additions & 8 deletions x-pack/plugins/monitoring/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<TypeOf<typeof configSchema>>());

Expand Down Expand Up @@ -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', {
Expand All @@ -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.',
Expand All @@ -299,10 +294,10 @@ export class MonitoringPlugin
},
alerting: {
rule: {
all: alertingRules,
all: RULES,
},
alert: {
all: alertingRules,
all: RULES,
},
},
ui: [],
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/monitoring/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@
{ "path": "../observability/tsconfig.json" },
{ "path": "../telemetry_collection_xpack/tsconfig.json" },
{ "path": "../triggers_actions_ui/tsconfig.json" },
{ "path": "../transform/tsconfig.json" },
]
}
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" }
]
}
2 changes: 1 addition & 1 deletion x-pack/plugins/transform/public/alerting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* 2.0.
*/

export { createTransformHealthRuleType } from './transform_health_rule_type';
export { getTransformHealthRuleType } from './transform_health_rule_type';
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* 2.0.
*/

export { createTransformHealthRuleType } from './register_transform_health_rule';
export { getTransformHealthRuleType } from './register_transform_health_rule';
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransformHealthRuleParams> {
export function getTransformHealthRuleType(): AlertTypeModel<TransformHealthRuleParams> {
return {
id: TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH,
description: i18n.translate('xpack.transform.alertingRuleTypes.transformHealth.description', {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/transform/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export const plugin = () => {
return new TransformUiPlugin();
};

export { createTransformHealthRuleType } from './alerting';
export { getTransformHealthRuleType } from './alerting';
7 changes: 6 additions & 1 deletion x-pack/plugins/transform/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +30,7 @@ export interface PluginsDependencies {

export class TransformUiPlugin {
public setup(coreSetup: CoreSetup<PluginsDependencies>, pluginsSetup: PluginsDependencies): void {
const { management, home } = pluginsSetup;
const { management, home, triggersActionsUi } = pluginsSetup;

// Register management section
const esSection = management.sections.section.data;
Expand All @@ -45,6 +46,10 @@ export class TransformUiPlugin {
},
});
registerFeature(home);

if (triggersActionsUi) {
triggersActionsUi.ruleTypeRegistry.register(getTransformHealthRuleType());
}
}

public start() {}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/transform/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
5 changes: 4 additions & 1 deletion x-pack/plugins/transform/server/lib/alerting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
* 2.0.
*/

export { getTransformHealthRuleType } from './transform_health_rule_type';
export {
getTransformHealthRuleType,
registerTransformHealthRuleType,
} from './transform_health_rule_type';
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
* 2.0.
*/

export { getTransformHealthRuleType } from './register_transform_health_rule_type';
export {
getTransformHealthRuleType,
registerTransformHealthRuleType,
} from './register_transform_health_rule_type';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import { Logger } from 'src/core/server';
import type {
ActionGroup,
AlertInstanceContext,
Expand All @@ -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;
Expand Down Expand Up @@ -45,6 +48,16 @@ export const TRANSFORM_ISSUE_DETECTED: ActionGroup<TransformIssue> = {
}),
};

interface RegisterParams {
logger: Logger;
alerting: AlertingSetup;
}

export function registerTransformHealthRuleType(params: RegisterParams) {
const { alerting } = params;
alerting.registerType(getTransformHealthRuleType());
}

export function getTransformHealthRuleType(): AlertType<
TransformHealthRuleParams,
never,
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/transform/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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();

Expand Down Expand Up @@ -75,6 +76,10 @@ export class TransformServerPlugin implements Plugin<{}, void, any, any> {
license: this.license,
});

if (alerting) {
registerTransformHealthRuleType({ alerting, logger: this.logger });
}

return {};
}

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/transform/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
{ "path": "../license_management/tsconfig.json" },
{ "path": "../licensing/tsconfig.json" },
{ "path": "../ml/tsconfig.json" },
{ "path": "../stack_alerts/tsconfig.json" }
]
}

0 comments on commit a6d8fe6

Please sign in to comment.