Skip to content

Commit

Permalink
[Response Ops][Alerting] Removing lifecycle executor from rule regist…
Browse files Browse the repository at this point in the history
…ry (elastic#192576)

## Summary

All lifecycle rule types have been migrated to use the alerting
framework alerts client so the lifecycle executor in the rule registry
can be removed since it is no longer in use.

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
2 people authored and nreese committed Nov 1, 2024
1 parent 02d4c12 commit 1192761
Show file tree
Hide file tree
Showing 25 changed files with 74 additions and 4,389 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
*/

import rison from '@kbn/rison';
import {
AlertInstanceContext as AlertContext,
AlertInstanceState as AlertState,
} from '@kbn/alerting-plugin/server';
import { RuleExecutorServicesMock, alertsMock } from '@kbn/alerting-plugin/server/mocks';
import { LifecycleAlertServices } from '@kbn/rule-registry-plugin/server';
import { ruleRegistryMocks } from '@kbn/rule-registry-plugin/server/mocks';
import { createLifecycleRuleExecutorMock } from '@kbn/rule-registry-plugin/server/utils/create_lifecycle_rule_executor_mock';
import { COMPARATORS } from '@kbn/alerting-comparators';
import { Aggregators, InventoryMetricConditions } from '../../../../common/alerting/metrics';
import type { LogMeta, Logger } from '@kbn/logging';
Expand Down Expand Up @@ -150,9 +143,7 @@ const mockLibs = {
infraPluginMock.createStartContract(),
],
configuration: createMockStaticConfiguration({}),
metricsRules: {
createLifecycleRuleExecutor: createLifecycleRuleExecutorMock,
},
metricsRules: {},
basePath: {
publicBaseUrl: 'http://localhost:5601',
prepend: (path: string) => path,
Expand All @@ -165,14 +156,10 @@ const mockLibs = {
logger,
} as unknown as InfraBackendLibs;
const alerts = new Map<string, AlertTestInstance>();
let services: RuleExecutorServicesMock & LifecycleAlertServices<AlertState, AlertContext, string>;
let services: RuleExecutorServicesMock;

const setup = () => {
const alertsServices = alertsMock.createRuleExecutorServices();
services = {
...alertsServices,
...ruleRegistryMocks.createLifecycleAlertServices(alertsServices),
};
services = alertsMock.createRuleExecutorServices();

services.alertsClient.report.mockImplementation((params: any) => {
alerts.set(params.id, { actionGroup: params.actionGroup, context: [], payload: [] });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { CoreSetup, Logger } from '@kbn/core/server';
import { createLifecycleExecutor } from '@kbn/rule-registry-plugin/server';
import { InfraFeatureId } from '../../../common/constants';
import { createRuleDataClient } from './rule_data_client';
import {
Expand Down Expand Up @@ -36,12 +35,7 @@ export class RulesService {
ruleDataService: setupDeps.ruleRegistry.ruleDataService,
});

const createLifecycleRuleExecutor = createLifecycleExecutor(this.logger, ruleDataClient);

return {
createLifecycleRuleExecutor,
ruleDataClient,
};
return { ruleDataClient };
}

public start(_startDeps: RulesServiceStartDeps): RulesServiceStart {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
*/

import { PluginSetupContract as AlertingPluginSetup } from '@kbn/alerting-plugin/server';
import {
createLifecycleExecutor,
IRuleDataClient,
RuleRegistryPluginSetupContract,
} from '@kbn/rule-registry-plugin/server';

type LifecycleRuleExecutorCreator = ReturnType<typeof createLifecycleExecutor>;
import { IRuleDataClient, RuleRegistryPluginSetupContract } from '@kbn/rule-registry-plugin/server';
export interface RulesServiceSetupDeps {
alerting: AlertingPluginSetup;
ruleRegistry: RuleRegistryPluginSetupContract;
Expand All @@ -22,7 +16,6 @@ export interface RulesServiceSetupDeps {
export interface RulesServiceStartDeps {}

export interface RulesServiceSetup {
createLifecycleRuleExecutor: LifecycleRuleExecutorCreator;
ruleDataClient: IRuleDataClient;
}

Expand Down
7 changes: 0 additions & 7 deletions x-pack/plugins/rule_registry/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ export * from './rule_data_plugin_service';
export * from './rule_data_client';
export * from './alert_data_client/audit_events';

export { createLifecycleRuleTypeFactory } from './utils/create_lifecycle_rule_type_factory';
export type {
LifecycleRuleExecutor,
LifecycleAlertService,
LifecycleAlertServices,
} from './utils/create_lifecycle_executor';
export { createLifecycleExecutor } from './utils/create_lifecycle_executor';
export { createPersistenceRuleTypeWrapper } from './utils/create_persistence_rule_type_wrapper';
export * from './utils/persistence_types';
export type { AlertsClient } from './alert_data_client/alerts_client';
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/rule_registry/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import {
ruleDataServiceMock,
RuleDataServiceMock,
} from './rule_data_plugin_service/rule_data_plugin_service.mock';
import { createLifecycleAlertServicesMock } from './utils/lifecycle_alert_services.mock';

export const ruleRegistryMocks = {
createLifecycleAlertServices: createLifecycleAlertServicesMock,
createRuleDataService: ruleDataServiceMock.create,
createRuleDataClient: createRuleDataClientMock,
createAlertsClientMock: alertsClientMock,
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/rule_registry/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import type {
PluginSetup as DataPluginSetup,
} from '@kbn/data-plugin/server';

import { createLifecycleRuleTypeFactory } from './utils/create_lifecycle_rule_type_factory';
import type { RuleRegistryPluginConfig } from './config';
import { type IRuleDataService, RuleDataService, Dataset } from './rule_data_plugin_service';
import { AlertsClientFactory } from './alert_data_client/alerts_client_factory';
Expand All @@ -52,7 +51,6 @@ export interface RuleRegistryPluginStartDependencies {

export interface RuleRegistryPluginSetupContract {
ruleDataService: IRuleDataService;
createLifecycleRuleTypeFactory: typeof createLifecycleRuleTypeFactory;
dataset: typeof Dataset;
}

Expand Down Expand Up @@ -153,7 +151,6 @@ export class RuleRegistryPlugin

return {
ruleDataService: this.ruleDataService,
createLifecycleRuleTypeFactory,
dataset: Dataset,
};
}
Expand Down
Loading

0 comments on commit 1192761

Please sign in to comment.