Skip to content

Commit

Permalink
[8.x] [Response Ops][Alerting] Removing lifecycle executor from rule …
Browse files Browse the repository at this point in the history
…registry (#192576) (#198579)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Response Ops][Alerting] Removing lifecycle executor from rule
registry (#192576)](#192576)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Ying
Mao","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-31T16:30:47Z","message":"[Response
Ops][Alerting] Removing lifecycle executor from rule registry
(#192576)\n\n## Summary\r\n\r\nAll lifecycle rule types have been
migrated to use the alerting\r\nframework alerts client so the lifecycle
executor in the rule registry\r\ncan be removed since it is no longer in
use.\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"322392fb28bc2ae34ebedb8b8d04c57a5bf1ed69","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Alerting","release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","ci:project-deploy-observability","apm:review","v8.17.0"],"title":"[Response
Ops][Alerting] Removing lifecycle executor from rule
registry","number":192576,"url":"https://github.com/elastic/kibana/pull/192576","mergeCommit":{"message":"[Response
Ops][Alerting] Removing lifecycle executor from rule registry
(#192576)\n\n## Summary\r\n\r\nAll lifecycle rule types have been
migrated to use the alerting\r\nframework alerts client so the lifecycle
executor in the rule registry\r\ncan be removed since it is no longer in
use.\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"322392fb28bc2ae34ebedb8b8d04c57a5bf1ed69"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192576","number":192576,"mergeCommit":{"message":"[Response
Ops][Alerting] Removing lifecycle executor from rule registry
(#192576)\n\n## Summary\r\n\r\nAll lifecycle rule types have been
migrated to use the alerting\r\nframework alerts client so the lifecycle
executor in the rule registry\r\ncan be removed since it is no longer in
use.\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"322392fb28bc2ae34ebedb8b8d04c57a5bf1ed69"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Ying Mao <[email protected]>
  • Loading branch information
kibanamachine and ymao1 authored Oct 31, 2024
1 parent d7ce412 commit 124aff6
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 124aff6

Please sign in to comment.