diff --git a/api_docs/alerting.json b/api_docs/alerting.json index 7c860a5c19e3..421482988910 100644 --- a/api_docs/alerting.json +++ b/api_docs/alerting.json @@ -701,7 +701,7 @@ "description": [], "signature": [ "() => Set<", - "RegistryAlertType", + "RegistryRuleType", ">" ], "source": { @@ -1330,7 +1330,7 @@ "description": [], "signature": [ "() => Set<", - "RegistryAlertType", + "RegistryRuleType", ">" ], "source": { diff --git a/api_docs/triggers_actions_ui.json b/api_docs/triggers_actions_ui.json index bccb50d96759..828a4e6c10d3 100644 --- a/api_docs/triggers_actions_ui.json +++ b/api_docs/triggers_actions_ui.json @@ -2187,10 +2187,10 @@ }, { "parentPluginId": "triggersActionsUi", - "id": "def-public.TriggersAndActionsUiServices.alertTypeRegistry", + "id": "def-public.TriggersAndActionsUiServices.ruleTypeRegistry", "type": "Object", "tags": [], - "label": "alertTypeRegistry", + "label": "ruleTypeRegistry", "description": [], "signature": [ "{ get: (id: string) => ", @@ -2535,10 +2535,10 @@ }, { "parentPluginId": "triggersActionsUi", - "id": "def-public.AlertTypeRegistryContract", + "id": "def-public.RuleTypeRegistryContract", "type": "Type", "tags": [], - "label": "AlertTypeRegistryContract", + "label": "RuleTypeRegistryContract", "description": [], "signature": [ "{ get: (id: string) => ", @@ -3623,10 +3623,10 @@ }, { "parentPluginId": "triggersActionsUi", - "id": "def-public.TriggersAndActionsUIPublicPluginSetup.alertTypeRegistry", + "id": "def-public.TriggersAndActionsUIPublicPluginSetup.ruleTypeRegistry", "type": "Object", "tags": [], - "label": "alertTypeRegistry", + "label": "ruleTypeRegistry", "description": [], "signature": [ "TypeRegistry", @@ -3684,10 +3684,10 @@ }, { "parentPluginId": "triggersActionsUi", - "id": "def-public.TriggersAndActionsUIPublicPluginStart.alertTypeRegistry", + "id": "def-public.TriggersAndActionsUIPublicPluginStart.ruleTypeRegistry", "type": "Object", "tags": [], - "label": "alertTypeRegistry", + "label": "ruleTypeRegistry", "description": [], "signature": [ "TypeRegistry", diff --git a/x-pack/examples/alerting_example/public/plugin.tsx b/x-pack/examples/alerting_example/public/plugin.tsx index 6ec6f043d0e0..242fd6e1fd2f 100644 --- a/x-pack/examples/alerting_example/public/plugin.tsx +++ b/x-pack/examples/alerting_example/public/plugin.tsx @@ -55,8 +55,8 @@ export class AlertingExamplePlugin implements Plugin = { - alertTypeRegistry: alertTypeRegistryMock.create(), + ruleTypeRegistry: ruleTypeRegistryMock.create(), getSpace: jest.fn(), features, }; @@ -69,7 +69,7 @@ test('creates an alerting authorization client with proper constructor arguments expect(AlertingAuthorization).toHaveBeenCalledWith({ request, authorization: securityPluginStart.authz, - alertTypeRegistry: alertingAuthorizationClientFactoryParams.alertTypeRegistry, + ruleTypeRegistry: alertingAuthorizationClientFactoryParams.ruleTypeRegistry, features: alertingAuthorizationClientFactoryParams.features, auditLogger: expect.any(AlertingAuthorizationAuditLogger), getSpace: expect.any(Function), @@ -96,7 +96,7 @@ test('creates an alerting authorization client with proper constructor arguments expect(AlertingAuthorization).toHaveBeenCalledWith({ request, authorization: securityPluginStart.authz, - alertTypeRegistry: alertingAuthorizationClientFactoryParams.alertTypeRegistry, + ruleTypeRegistry: alertingAuthorizationClientFactoryParams.ruleTypeRegistry, features: alertingAuthorizationClientFactoryParams.features, auditLogger: expect.any(AlertingAuthorizationAuditLogger), getSpace: expect.any(Function), @@ -118,7 +118,7 @@ test('creates an alerting authorization client with proper constructor arguments const { AlertingAuthorization } = jest.requireMock('./authorization/alerting_authorization'); expect(AlertingAuthorization).toHaveBeenCalledWith({ request, - alertTypeRegistry: alertingAuthorizationClientFactoryParams.alertTypeRegistry, + ruleTypeRegistry: alertingAuthorizationClientFactoryParams.ruleTypeRegistry, features: alertingAuthorizationClientFactoryParams.features, auditLogger: expect.any(AlertingAuthorizationAuditLogger), getSpace: expect.any(Function), diff --git a/x-pack/plugins/alerting/server/alerting_authorization_client_factory.ts b/x-pack/plugins/alerting/server/alerting_authorization_client_factory.ts index ea882b07f1e9..88a539723ca6 100644 --- a/x-pack/plugins/alerting/server/alerting_authorization_client_factory.ts +++ b/x-pack/plugins/alerting/server/alerting_authorization_client_factory.ts @@ -7,7 +7,7 @@ import { KibanaRequest } from 'src/core/server'; import { ALERTS_FEATURE_ID } from '../common'; -import { AlertTypeRegistry } from './types'; +import { RuleTypeRegistry } from './types'; import { SecurityPluginSetup, SecurityPluginStart } from '../../security/server'; import { PluginStartContract as FeaturesPluginStart } from '../../features/server'; import { AlertingAuthorization } from './authorization/alerting_authorization'; @@ -15,7 +15,7 @@ import { AlertingAuthorizationAuditLogger } from './authorization/audit_logger'; import { Space } from '../../spaces/server'; export interface AlertingAuthorizationClientFactoryOpts { - alertTypeRegistry: AlertTypeRegistry; + ruleTypeRegistry: RuleTypeRegistry; securityPluginSetup?: SecurityPluginSetup; securityPluginStart?: SecurityPluginStart; getSpace: (request: KibanaRequest) => Promise; @@ -24,7 +24,7 @@ export interface AlertingAuthorizationClientFactoryOpts { export class AlertingAuthorizationClientFactory { private isInitialized = false; - private alertTypeRegistry!: AlertTypeRegistry; + private ruleTypeRegistry!: RuleTypeRegistry; private securityPluginStart?: SecurityPluginStart; private securityPluginSetup?: SecurityPluginSetup; private features!: FeaturesPluginStart; @@ -36,7 +36,7 @@ export class AlertingAuthorizationClientFactory { } this.isInitialized = true; this.getSpace = options.getSpace; - this.alertTypeRegistry = options.alertTypeRegistry; + this.ruleTypeRegistry = options.ruleTypeRegistry; this.securityPluginSetup = options.securityPluginSetup; this.securityPluginStart = options.securityPluginStart; this.features = options.features; @@ -48,7 +48,7 @@ export class AlertingAuthorizationClientFactory { authorization: securityPluginStart?.authz, request, getSpace: this.getSpace, - alertTypeRegistry: this.alertTypeRegistry, + ruleTypeRegistry: this.ruleTypeRegistry, features: features!, auditLogger: new AlertingAuthorizationAuditLogger( securityPluginSetup?.audit.getLogger(ALERTS_FEATURE_ID) diff --git a/x-pack/plugins/alerting/server/authorization/alerting_authorization.test.ts b/x-pack/plugins/alerting/server/authorization/alerting_authorization.test.ts index 4b1fc7f1a7cc..3ebf261b80b1 100644 --- a/x-pack/plugins/alerting/server/authorization/alerting_authorization.test.ts +++ b/x-pack/plugins/alerting/server/authorization/alerting_authorization.test.ts @@ -6,7 +6,7 @@ */ import { KibanaRequest } from 'kibana/server'; -import { alertTypeRegistryMock } from '../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../rule_type_registry.mock'; import { securityMock } from '../../../../plugins/security/server/mocks'; import { PluginStartContract as FeaturesStartContract, @@ -23,11 +23,11 @@ import { alertingAuthorizationAuditLoggerMock } from './audit_logger.mock'; import { AlertingAuthorizationAuditLogger, AuthorizationResult } from './audit_logger'; import uuid from 'uuid'; import { RecoveredActionGroup } from '../../common'; -import { RegistryAlertType } from '../alert_type_registry'; +import { RegistryRuleType } from '../rule_type_registry'; import { esKuery } from '../../../../../src/plugins/data/server'; import { AlertingAuthorizationFilterType } from './alerting_authorization_kuery'; -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const features: jest.Mocked = featuresPluginMock.createStart(); const request = {} as KibanaRequest; @@ -197,7 +197,7 @@ beforeEach(() => { auditLogger.logUnscopedAuthorizationFailure.mockImplementation( (username, operation) => `Unauthorized ${username}/${operation}` ); - alertTypeRegistry.get.mockImplementation((id) => ({ + ruleTypeRegistry.get.mockImplementation((id) => ({ id, name: 'My Alert Type', actionGroups: [{ id: 'default', name: 'Default' }], @@ -229,7 +229,7 @@ describe('AlertingAuthorization', () => { new AlertingAuthorization({ request, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -244,7 +244,7 @@ describe('AlertingAuthorization', () => { test('is a no-op when there is no authorization api', async () => { const alertAuthorization = new AlertingAuthorization({ request, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -258,7 +258,7 @@ describe('AlertingAuthorization', () => { entity: AlertingAuthorizationEntity.Rule, }); - expect(alertTypeRegistry.get).toHaveBeenCalledTimes(0); + expect(ruleTypeRegistry.get).toHaveBeenCalledTimes(0); }); test('is a no-op when the security license is disabled', async () => { @@ -266,7 +266,7 @@ describe('AlertingAuthorization', () => { authorization.mode.useRbacForRequest.mockReturnValue(false); const alertAuthorization = new AlertingAuthorization({ request, - alertTypeRegistry, + ruleTypeRegistry, authorization, features, auditLogger, @@ -281,7 +281,7 @@ describe('AlertingAuthorization', () => { entity: AlertingAuthorizationEntity.Rule, }); - expect(alertTypeRegistry.get).toHaveBeenCalledTimes(0); + expect(ruleTypeRegistry.get).toHaveBeenCalledTimes(0); }); test('ensures the user has privileges to execute rules for the specified rule type and operation without consumer when producer and consumer are the same', async () => { @@ -293,7 +293,7 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -313,7 +313,7 @@ describe('AlertingAuthorization', () => { entity: AlertingAuthorizationEntity.Rule, }); - expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType'); + expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType'); expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2); expect(authorization.actions.alerting.get).toHaveBeenCalledWith( @@ -349,7 +349,7 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -369,7 +369,7 @@ describe('AlertingAuthorization', () => { entity: AlertingAuthorizationEntity.Alert, }); - expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType'); + expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType'); expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2); expect(authorization.actions.alerting.get).toHaveBeenCalledWith( @@ -405,7 +405,7 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -425,7 +425,7 @@ describe('AlertingAuthorization', () => { entity: AlertingAuthorizationEntity.Rule, }); - expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType'); + expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType'); expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2); expect(authorization.actions.alerting.get).toHaveBeenCalledWith( @@ -467,7 +467,7 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -487,7 +487,7 @@ describe('AlertingAuthorization', () => { entity: AlertingAuthorizationEntity.Alert, }); - expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType'); + expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType'); expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2); expect(authorization.actions.alerting.get).toHaveBeenCalledWith( @@ -535,7 +535,7 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -549,7 +549,7 @@ describe('AlertingAuthorization', () => { entity: AlertingAuthorizationEntity.Rule, }); - expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType'); + expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType'); expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2); expect(authorization.actions.alerting.get).toHaveBeenCalledWith( @@ -600,7 +600,7 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -614,7 +614,7 @@ describe('AlertingAuthorization', () => { entity: AlertingAuthorizationEntity.Alert, }); - expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType'); + expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType'); expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2); expect(authorization.actions.alerting.get).toHaveBeenCalledWith( @@ -659,7 +659,7 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -717,7 +717,7 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -779,7 +779,7 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -837,7 +837,7 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -888,7 +888,7 @@ describe('AlertingAuthorization', () => { }); describe('getFindAuthorizationFilter', () => { - const myOtherAppAlertType: RegistryAlertType = { + const myOtherAppAlertType: RegistryRuleType = { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', @@ -900,7 +900,7 @@ describe('AlertingAuthorization', () => { producer: 'alerts', enabledInLicense: true, }; - const myAppAlertType: RegistryAlertType = { + const myAppAlertType: RegistryRuleType = { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', @@ -912,7 +912,7 @@ describe('AlertingAuthorization', () => { producer: 'myApp', enabledInLicense: true, }; - const mySecondAppAlertType: RegistryAlertType = { + const mySecondAppAlertType: RegistryRuleType = { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', @@ -928,7 +928,7 @@ describe('AlertingAuthorization', () => { test('omits filter when there is no authorization api', async () => { const alertAuthorization = new AlertingAuthorization({ request, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -950,7 +950,7 @@ describe('AlertingAuthorization', () => { test('ensureRuleTypeIsAuthorized is no-op when there is no authorization api', async () => { const alertAuthorization = new AlertingAuthorization({ request, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, @@ -984,13 +984,13 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds, }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); expect( ( await alertAuthorization.getFindAuthorizationFilter(AlertingAuthorizationEntity.Rule, { @@ -1046,13 +1046,13 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds, }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); const { ensureRuleTypeIsAuthorized } = await alertAuthorization.getFindAuthorizationFilter( AlertingAuthorizationEntity.Alert, { @@ -1119,13 +1119,13 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds, }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); const { ensureRuleTypeIsAuthorized } = await alertAuthorization.getFindAuthorizationFilter( AlertingAuthorizationEntity.Rule, { @@ -1193,13 +1193,13 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds, }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); const { ensureRuleTypeIsAuthorized, logSuccessfulAuthorization, @@ -1241,7 +1241,7 @@ describe('AlertingAuthorization', () => { }); describe('filterByRuleTypeAuthorization', () => { - const myOtherAppAlertType: RegistryAlertType = { + const myOtherAppAlertType: RegistryRuleType = { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', @@ -1253,7 +1253,7 @@ describe('AlertingAuthorization', () => { producer: 'myOtherApp', enabledInLicense: true, }; - const myAppAlertType: RegistryAlertType = { + const myAppAlertType: RegistryRuleType = { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', @@ -1270,13 +1270,13 @@ describe('AlertingAuthorization', () => { test('augments a list of types with all features when there is no authorization api', async () => { const alertAuthorization = new AlertingAuthorization({ request, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds, }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); await expect( alertAuthorization.filterByRuleTypeAuthorization( @@ -1351,13 +1351,13 @@ describe('AlertingAuthorization', () => { test('augments a list of types with all features and exempt consumer ids when there is no authorization api', async () => { const alertAuthorization = new AlertingAuthorization({ request, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds: ['exemptConsumerA', 'exemptConsumerB'], }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); await expect( alertAuthorization.filterByRuleTypeAuthorization( @@ -1484,13 +1484,13 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds, }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); await expect( alertAuthorization.filterByRuleTypeAuthorization( @@ -1589,13 +1589,13 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds: ['exemptConsumerA'], }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); await expect( alertAuthorization.filterByRuleTypeAuthorization( @@ -1685,13 +1685,13 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds: ['exemptConsumerA'], }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); await expect( alertAuthorization.filterByRuleTypeAuthorization( @@ -1790,13 +1790,13 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds, }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); await expect( alertAuthorization.filterByRuleTypeAuthorization( @@ -1899,13 +1899,13 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds, }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); await expect( alertAuthorization.filterByRuleTypeAuthorization( @@ -1946,7 +1946,7 @@ describe('AlertingAuthorization', () => { }); describe('getAugmentedRuleTypesWithAuthorization', () => { - const myOtherAppAlertType: RegistryAlertType = { + const myOtherAppAlertType: RegistryRuleType = { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', @@ -1958,7 +1958,7 @@ describe('AlertingAuthorization', () => { enabledInLicense: true, isExportable: true, }; - const myAppAlertType: RegistryAlertType = { + const myAppAlertType: RegistryRuleType = { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', @@ -1970,7 +1970,7 @@ describe('AlertingAuthorization', () => { enabledInLicense: true, isExportable: true, }; - const mySecondAppAlertType: RegistryAlertType = { + const mySecondAppAlertType: RegistryRuleType = { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', @@ -2005,13 +2005,13 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds, }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); await expect( alertAuthorization.getAugmentedRuleTypesWithAuthorization( @@ -2079,13 +2079,13 @@ describe('AlertingAuthorization', () => { const alertAuthorization = new AlertingAuthorization({ request, authorization, - alertTypeRegistry, + ruleTypeRegistry, features, auditLogger, getSpace, exemptConsumerIds, }); - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); await expect( alertAuthorization.getAugmentedRuleTypesWithAuthorization( diff --git a/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts b/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts index b3cd47d47dbc..a06bdce5a33b 100644 --- a/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts +++ b/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts @@ -9,9 +9,9 @@ import Boom from '@hapi/boom'; import { map, mapValues, fromPairs, has } from 'lodash'; import { KibanaRequest } from 'src/core/server'; import { JsonObject } from '@kbn/common-utils'; -import { AlertTypeRegistry } from '../types'; +import { RuleTypeRegistry } from '../types'; import { SecurityPluginSetup } from '../../../security/server'; -import { RegistryAlertType } from '../alert_type_registry'; +import { RegistryRuleType } from '../rule_type_registry'; import { PluginStartContract as FeaturesPluginStart } from '../../../features/server'; import { AlertingAuthorizationAuditLogger, ScopeType } from './audit_logger'; import { Space } from '../../../spaces/server'; @@ -58,13 +58,13 @@ interface HasPrivileges { all: boolean; } type AuthorizedConsumers = Record; -export interface RegistryAlertTypeWithAuth extends RegistryAlertType { +export interface RegistryAlertTypeWithAuth extends RegistryRuleType { authorizedConsumers: AuthorizedConsumers; } type IsAuthorizedAtProducerLevel = boolean; export interface ConstructorOptions { - alertTypeRegistry: AlertTypeRegistry; + ruleTypeRegistry: RuleTypeRegistry; request: KibanaRequest; features: FeaturesPluginStart; getSpace: (request: KibanaRequest) => Promise; @@ -74,7 +74,7 @@ export interface ConstructorOptions { } export class AlertingAuthorization { - private readonly alertTypeRegistry: AlertTypeRegistry; + private readonly ruleTypeRegistry: RuleTypeRegistry; private readonly request: KibanaRequest; private readonly authorization?: SecurityPluginSetup['authz']; private readonly auditLogger: AlertingAuthorizationAuditLogger; @@ -84,7 +84,7 @@ export class AlertingAuthorization { private readonly spaceId: Promise; constructor({ - alertTypeRegistry, + ruleTypeRegistry, request, authorization, features, @@ -94,7 +94,7 @@ export class AlertingAuthorization { }: ConstructorOptions) { this.request = request; this.authorization = authorization; - this.alertTypeRegistry = alertTypeRegistry; + this.ruleTypeRegistry = ruleTypeRegistry; this.auditLogger = auditLogger; // List of consumer ids that are exempt from privilege check. This should be used sparingly. @@ -159,7 +159,7 @@ export class AlertingAuthorization { authorizedRuleTypes: Set; }> { return this.augmentRuleTypesWithAuthorization( - this.alertTypeRegistry.list(), + this.ruleTypeRegistry.list(), operations, authorizationEntity, new Set(featureIds) @@ -171,7 +171,7 @@ export class AlertingAuthorization { const isAvailableConsumer = has(await this.allPossibleConsumers, consumer); if (authorization && this.shouldCheckAuthorization()) { - const ruleType = this.alertTypeRegistry.get(ruleTypeId); + const ruleType = this.ruleTypeRegistry.get(ruleTypeId); const requiredPrivilegesByScope = { consumer: authorization.actions.alerting.get(ruleTypeId, consumer, entity, operation), producer: authorization.actions.alerting.get( @@ -281,7 +281,7 @@ export class AlertingAuthorization { }> { if (this.authorization && this.shouldCheckAuthorization()) { const { username, authorizedRuleTypes } = await this.augmentRuleTypesWithAuthorization( - this.alertTypeRegistry.list(), + this.ruleTypeRegistry.list(), [ReadOperations.Find], authorizationEntity ); @@ -352,7 +352,7 @@ export class AlertingAuthorization { } public async filterByRuleTypeAuthorization( - ruleTypes: Set, + ruleTypes: Set, operations: Array, authorizationEntity: AlertingAuthorizationEntity ): Promise> { @@ -365,7 +365,7 @@ export class AlertingAuthorization { } private async augmentRuleTypesWithAuthorization( - ruleTypes: Set, + ruleTypes: Set, operations: Array, authorizationEntity: AlertingAuthorizationEntity, featuresIds?: Set @@ -457,7 +457,7 @@ export class AlertingAuthorization { } private augmentWithAuthorizedConsumers( - ruleTypes: Set, + ruleTypes: Set, authorizedConsumers: AuthorizedConsumers ): Set { return new Set( diff --git a/x-pack/plugins/alerting/server/plugin.ts b/x-pack/plugins/alerting/server/plugin.ts index 1407f622fabe..0b5fb54f1757 100644 --- a/x-pack/plugins/alerting/server/plugin.ts +++ b/x-pack/plugins/alerting/server/plugin.ts @@ -18,7 +18,7 @@ import { import { TaskManagerSetupContract, TaskManagerStartContract } from '../../task_manager/server'; import { SpacesPluginStart } from '../../spaces/server'; import { RulesClient } from './rules_client'; -import { AlertTypeRegistry } from './alert_type_registry'; +import { RuleTypeRegistry } from './rule_type_registry'; import { TaskRunnerFactory } from './task_runner'; import { RulesClientFactory } from './rules_client_factory'; import { ILicenseState, LicenseState } from './lib/license_state'; @@ -107,7 +107,7 @@ export interface PluginSetupContract { } export interface PluginStartContract { - listTypes: AlertTypeRegistry['list']; + listTypes: RuleTypeRegistry['list']; getRulesClientWithRequest(request: KibanaRequest): PublicMethodsOf; getAlertingAuthorizationWithRequest( request: KibanaRequest @@ -139,7 +139,7 @@ export interface AlertingPluginsStart { export class AlertingPlugin { private readonly config: Promise; private readonly logger: Logger; - private alertTypeRegistry?: AlertTypeRegistry; + private ruleTypeRegistry?: RuleTypeRegistry; private readonly taskRunnerFactory: TaskRunnerFactory; private licenseState: ILicenseState | null = null; private isESOCanEncrypt?: boolean; @@ -197,13 +197,13 @@ export class AlertingPlugin { this.eventLogService = plugins.eventLog; plugins.eventLog.registerProviderActions(EVENT_LOG_PROVIDER, Object.values(EVENT_LOG_ACTIONS)); - const alertTypeRegistry = new AlertTypeRegistry({ + const ruleTypeRegistry = new RuleTypeRegistry({ taskManager: plugins.taskManager, taskRunnerFactory: this.taskRunnerFactory, licenseState: this.licenseState, licensing: plugins.licensing, }); - this.alertTypeRegistry = alertTypeRegistry; + this.ruleTypeRegistry = ruleTypeRegistry; const usageCollection = plugins.usageCollection; if (usageCollection) { @@ -224,7 +224,7 @@ export class AlertingPlugin { setupSavedObjects( core.savedObjects, plugins.encryptedSavedObjects, - this.alertTypeRegistry, + this.ruleTypeRegistry, this.logger ); @@ -299,7 +299,7 @@ export class AlertingPlugin { if (!(alertType.minimumLicenseRequired in LICENSE_TYPE)) { throw new Error(`"${alertType.minimumLicenseRequired}" is not a valid license type`); } - alertTypeRegistry.register(alertType); + ruleTypeRegistry.register(alertType); }, }; } @@ -309,7 +309,7 @@ export class AlertingPlugin { isESOCanEncrypt, logger, taskRunnerFactory, - alertTypeRegistry, + ruleTypeRegistry, rulesClientFactory, alertingAuthorizationClientFactory, security, @@ -329,7 +329,7 @@ export class AlertingPlugin { }; alertingAuthorizationClientFactory.initialize({ - alertTypeRegistry: alertTypeRegistry!, + ruleTypeRegistry: ruleTypeRegistry!, securityPluginSetup: security, securityPluginStart: plugins.security, async getSpace(request: KibanaRequest) { @@ -339,7 +339,7 @@ export class AlertingPlugin { }); rulesClientFactory.initialize({ - alertTypeRegistry: alertTypeRegistry!, + ruleTypeRegistry: ruleTypeRegistry!, logger, taskManager: plugins.taskManager, securityPluginSetup: security, @@ -378,7 +378,7 @@ export class AlertingPlugin { basePathService: core.http.basePath, eventLogger: this.eventLogger!, internalSavedObjectsRepository: core.savedObjects.createInternalRepository(['alert']), - alertTypeRegistry: this.alertTypeRegistry!, + ruleTypeRegistry: this.ruleTypeRegistry!, kibanaBaseUrl: this.kibanaBaseUrl, supportsEphemeralTasks: plugins.taskManager.supportsEphemeralTasks(), maxEphemeralActionsPerAlert: this.config.then((config) => config.maxEphemeralActionsPerAlert), @@ -398,7 +398,7 @@ export class AlertingPlugin { scheduleApiKeyInvalidatorTask(this.telemetryLogger, this.config, plugins.taskManager); return { - listTypes: alertTypeRegistry!.list.bind(this.alertTypeRegistry!), + listTypes: ruleTypeRegistry!.list.bind(this.ruleTypeRegistry!), getAlertingAuthorizationWithRequest, getRulesClientWithRequest, getFrameworkHealth: async () => @@ -409,14 +409,14 @@ export class AlertingPlugin { private createRouteHandlerContext = ( core: CoreSetup ): IContextProvider => { - const { alertTypeRegistry, rulesClientFactory } = this; + const { ruleTypeRegistry, rulesClientFactory } = this; return async function alertsRouteHandlerContext(context, request) { const [{ savedObjects }] = await core.getStartServices(); return { getRulesClient: () => { return rulesClientFactory!.create(request, savedObjects); }, - listTypes: alertTypeRegistry!.list.bind(alertTypeRegistry!), + listTypes: ruleTypeRegistry!.list.bind(ruleTypeRegistry!), getFrameworkHealth: async () => await getHealth(savedObjects.createInternalRepository(['alert'])), areApiKeysEnabled: async () => { diff --git a/x-pack/plugins/alerting/server/alert_type_registry.mock.ts b/x-pack/plugins/alerting/server/rule_type_registry.mock.ts similarity index 63% rename from x-pack/plugins/alerting/server/alert_type_registry.mock.ts rename to x-pack/plugins/alerting/server/rule_type_registry.mock.ts index 8da04f93c4df..0af9d4b2d234 100644 --- a/x-pack/plugins/alerting/server/alert_type_registry.mock.ts +++ b/x-pack/plugins/alerting/server/rule_type_registry.mock.ts @@ -6,21 +6,21 @@ */ import type { PublicMethodsOf } from '@kbn/utility-types'; -import { AlertTypeRegistry } from './alert_type_registry'; +import { RuleTypeRegistry } from './rule_type_registry'; -type Schema = PublicMethodsOf; +type Schema = PublicMethodsOf; -const createAlertTypeRegistryMock = () => { +const createRuleTypeRegistryMock = () => { const mocked: jest.Mocked = { has: jest.fn(), register: jest.fn(), get: jest.fn(), list: jest.fn(), - ensureAlertTypeEnabled: jest.fn(), + ensureRuleTypeEnabled: jest.fn(), }; return mocked; }; -export const alertTypeRegistryMock = { - create: createAlertTypeRegistryMock, +export const ruleTypeRegistryMock = { + create: createRuleTypeRegistryMock, }; diff --git a/x-pack/plugins/alerting/server/alert_type_registry.test.ts b/x-pack/plugins/alerting/server/rule_type_registry.test.ts similarity index 85% rename from x-pack/plugins/alerting/server/alert_type_registry.test.ts rename to x-pack/plugins/alerting/server/rule_type_registry.test.ts index 835c98b9e03c..5b80fb301963 100644 --- a/x-pack/plugins/alerting/server/alert_type_registry.test.ts +++ b/x-pack/plugins/alerting/server/rule_type_registry.test.ts @@ -6,21 +6,21 @@ */ import { TaskRunnerFactory } from './task_runner'; -import { AlertTypeRegistry, ConstructorOptions } from './alert_type_registry'; +import { RuleTypeRegistry, ConstructorOptions } from './rule_type_registry'; import { ActionGroup, AlertType } from './types'; import { taskManagerMock } from '../../task_manager/server/mocks'; import { ILicenseState } from './lib/license_state'; import { licenseStateMock } from './lib/license_state.mock'; import { licensingMock } from '../../licensing/server/mocks'; let mockedLicenseState: jest.Mocked; -let alertTypeRegistryParams: ConstructorOptions; +let ruleTypeRegistryParams: ConstructorOptions; const taskManager = taskManagerMock.createSetup(); beforeEach(() => { jest.resetAllMocks(); mockedLicenseState = licenseStateMock.create(); - alertTypeRegistryParams = { + ruleTypeRegistryParams = { taskManager, taskRunnerFactory: new TaskRunnerFactory(), licenseState: mockedLicenseState, @@ -29,13 +29,13 @@ beforeEach(() => { }); describe('has()', () => { - test('returns false for unregistered alert types', () => { - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + test('returns false for unregistered rule types', () => { + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); expect(registry.has('foo')).toEqual(false); }); - test('returns true for registered alert types', () => { - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + test('returns true for registered rule types', () => { + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register({ id: 'foo', name: 'Foo', @@ -72,7 +72,7 @@ describe('register()', () => { executor: jest.fn(), producer: 'alerts', }; - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); const invalidCharacters = [' ', ':', '*', '*', '/']; for (const char of invalidCharacters) { @@ -105,14 +105,14 @@ describe('register()', () => { executor: jest.fn(), producer: 'alerts', }; - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); expect(() => registry.register(alertType)).toThrowError( new Error(`expected value of type [string] but got [number]`) ); }); - test('throws if AlertType action groups contains reserved group id', () => { + test('throws if RuleType action groups contains reserved group id', () => { const alertType: AlertType = { id: 'test', name: 'Test', @@ -136,11 +136,11 @@ describe('register()', () => { executor: jest.fn(), producer: 'alerts', }; - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); expect(() => registry.register(alertType)).toThrowError( new Error( - `Alert type [id="${alertType.id}"] cannot be registered. Action groups [recovered] are reserved by the framework.` + `Rule type [id="${alertType.id}"] cannot be registered. Action groups [recovered] are reserved by the framework.` ) ); }); @@ -165,7 +165,7 @@ describe('register()', () => { minimumLicenseRequired: 'basic', isExportable: true, }; - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register(alertType); expect(registry.get('test').actionGroups).toMatchInlineSnapshot(` Array [ @@ -213,11 +213,11 @@ describe('register()', () => { executor: jest.fn(), producer: 'alerts', }; - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); expect(() => registry.register(alertType)).toThrowError( new Error( - `Alert type [id="${alertType.id}"] cannot be registered. Action group [backToAwesome] cannot be used as both a recovery and an active action group.` + `Rule type [id="${alertType.id}"] cannot be registered. Action group [backToAwesome] cannot be used as both a recovery and an active action group.` ) ); }); @@ -238,7 +238,7 @@ describe('register()', () => { executor: jest.fn(), producer: 'alerts', }; - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register(alertType); expect(taskManager.registerTaskDefinitions).toHaveBeenCalledTimes(1); expect(taskManager.registerTaskDefinitions.mock.calls[0]).toMatchInlineSnapshot(` @@ -253,7 +253,7 @@ describe('register()', () => { `); }); - test('shallow clones the given alert type', () => { + test('shallow clones the given rule type', () => { const alertType: AlertType = { id: 'test', name: 'Test', @@ -269,14 +269,14 @@ describe('register()', () => { executor: jest.fn(), producer: 'alerts', }; - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register(alertType); alertType.name = 'Changed'; expect(registry.get('test').name).toEqual('Test'); }); test('should throw an error if type is already registered', () => { - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register({ id: 'test', name: 'Test', @@ -308,13 +308,13 @@ describe('register()', () => { executor: jest.fn(), producer: 'alerts', }) - ).toThrowErrorMatchingInlineSnapshot(`"Alert type \\"test\\" is already registered."`); + ).toThrowErrorMatchingInlineSnapshot(`"Rule type \\"test\\" is already registered."`); }); }); describe('get()', () => { test('should return registered type', () => { - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register({ id: 'test', name: 'Test', @@ -364,22 +364,22 @@ describe('get()', () => { }); test(`should throw an error if type isn't registered`, () => { - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); expect(() => registry.get('test')).toThrowErrorMatchingInlineSnapshot( - `"Alert type \\"test\\" is not registered."` + `"Rule type \\"test\\" is not registered."` ); }); }); describe('list()', () => { test('should return empty when nothing is registered', () => { - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); const result = registry.list(); expect(result).toMatchInlineSnapshot(`Set {}`); }); test('should return registered types', () => { - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register({ id: 'test', name: 'Test', @@ -431,7 +431,7 @@ describe('list()', () => { }); test('should return action variables state and empty context', () => { - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register(alertTypeWithVariables('x', '', 's')); const alertType = registry.get('x'); expect(alertType.actionVariables).toBeTruthy(); @@ -448,7 +448,7 @@ describe('list()', () => { }); test('should return action variables context and empty state', () => { - const registry = new AlertTypeRegistry(alertTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register(alertTypeWithVariables('x', 'c', '')); const alertType = registry.get('x'); expect(alertType.actionVariables).toBeTruthy(); @@ -465,12 +465,12 @@ describe('list()', () => { }); }); -describe('ensureAlertTypeEnabled', () => { - let alertTypeRegistry: AlertTypeRegistry; +describe('ensureRuleTypeEnabled', () => { + let ruleTypeRegistry: RuleTypeRegistry; beforeEach(() => { - alertTypeRegistry = new AlertTypeRegistry(alertTypeRegistryParams); - alertTypeRegistry.register({ + ruleTypeRegistry = new RuleTypeRegistry(ruleTypeRegistryParams); + ruleTypeRegistry.register({ id: 'test', name: 'Test', actionGroups: [ @@ -489,7 +489,7 @@ describe('ensureAlertTypeEnabled', () => { }); test('should call ensureLicenseForAlertType on the license state', async () => { - alertTypeRegistry.ensureAlertTypeEnabled('test'); + ruleTypeRegistry.ensureRuleTypeEnabled('test'); expect(mockedLicenseState.ensureLicenseForAlertType).toHaveBeenCalled(); }); @@ -497,9 +497,9 @@ describe('ensureAlertTypeEnabled', () => { mockedLicenseState.ensureLicenseForAlertType.mockImplementation(() => { throw new Error('Fail'); }); - expect(() => - alertTypeRegistry.ensureAlertTypeEnabled('test') - ).toThrowErrorMatchingInlineSnapshot(`"Fail"`); + expect(() => ruleTypeRegistry.ensureRuleTypeEnabled('test')).toThrowErrorMatchingInlineSnapshot( + `"Fail"` + ); }); }); diff --git a/x-pack/plugins/alerting/server/alert_type_registry.ts b/x-pack/plugins/alerting/server/rule_type_registry.ts similarity index 89% rename from x-pack/plugins/alerting/server/alert_type_registry.ts rename to x-pack/plugins/alerting/server/rule_type_registry.ts index f77dd3f7e46e..a76181680874 100644 --- a/x-pack/plugins/alerting/server/alert_type_registry.ts +++ b/x-pack/plugins/alerting/server/rule_type_registry.ts @@ -36,7 +36,7 @@ export interface ConstructorOptions { licensing: LicensingPluginSetup; } -export interface RegistryAlertType +export interface RegistryRuleType extends Pick< UntypedNormalizedAlertType, | 'name' @@ -119,9 +119,9 @@ export type UntypedNormalizedAlertType = NormalizedAlertType< string >; -export class AlertTypeRegistry { +export class RuleTypeRegistry { private readonly taskManager: TaskManagerSetupContract; - private readonly alertTypes: Map = new Map(); + private readonly ruleTypes: Map = new Map(); private readonly taskRunnerFactory: TaskRunnerFactory; private readonly licenseState: ILicenseState; private readonly licensing: LicensingPluginSetup; @@ -134,10 +134,10 @@ export class AlertTypeRegistry { } public has(id: string) { - return this.alertTypes.has(id); + return this.ruleTypes.has(id); } - public ensureAlertTypeEnabled(id: string) { + public ensureRuleTypeEnabled(id: string) { this.licenseState.ensureLicenseForAlertType(this.get(id)); } @@ -162,8 +162,8 @@ export class AlertTypeRegistry { ) { if (this.has(alertType.id)) { throw new Error( - i18n.translate('xpack.alerting.alertTypeRegistry.register.duplicateAlertTypeError', { - defaultMessage: 'Alert type "{id}" is already registered.', + i18n.translate('xpack.alerting.ruleTypeRegistry.register.duplicateAlertTypeError', { + defaultMessage: 'Rule type "{id}" is already registered.', values: { id: alertType.id, }, @@ -182,7 +182,7 @@ export class AlertTypeRegistry { RecoveryActionGroupId >(alertType); - this.alertTypes.set( + this.ruleTypes.set( alertIdSchema.validate(alertType.id), /** stripping the typing is required in order to store the AlertTypes in a Map */ (normalizedAlertType as unknown) as UntypedNormalizedAlertType @@ -232,8 +232,8 @@ export class AlertTypeRegistry { > { if (!this.has(id)) { throw Boom.badRequest( - i18n.translate('xpack.alerting.alertTypeRegistry.get.missingAlertTypeError', { - defaultMessage: 'Alert type "{id}" is not registered.', + i18n.translate('xpack.alerting.ruleTypeRegistry.get.missingAlertTypeError', { + defaultMessage: 'Rule type "{id}" is not registered.', values: { id, }, @@ -245,7 +245,7 @@ export class AlertTypeRegistry { * This means that returning a typed AlertType in `get` is an inherently * unsafe operation. Down casting to `unknown` is the only way to achieve this. */ - return (this.alertTypes.get(id)! as unknown) as NormalizedAlertType< + return (this.ruleTypes.get(id)! as unknown) as NormalizedAlertType< Params, ExtractedParams, State, @@ -256,9 +256,9 @@ export class AlertTypeRegistry { >; } - public list(): Set { + public list(): Set { return new Set( - Array.from(this.alertTypes).map( + Array.from(this.ruleTypes).map( ([ id, { @@ -338,10 +338,10 @@ function augmentActionGroupsWithReserved< if (recoveryActionGroup && activeActionGroups.has(recoveryActionGroup.id)) { throw new Error( i18n.translate( - 'xpack.alerting.alertTypeRegistry.register.customRecoveryActionGroupUsageError', + 'xpack.alerting.ruleTypeRegistry.register.customRecoveryActionGroupUsageError', { defaultMessage: - 'Alert type [id="{id}"] cannot be registered. Action group [{actionGroup}] cannot be used as both a recovery and an active action group.', + 'Rule type [id="{id}"] cannot be registered. Action group [{actionGroup}] cannot be used as both a recovery and an active action group.', values: { actionGroup: recoveryActionGroup.id, id, @@ -351,9 +351,9 @@ function augmentActionGroupsWithReserved< ); } else if (intersectingReservedActionGroups.length > 0) { throw new Error( - i18n.translate('xpack.alerting.alertTypeRegistry.register.reservedActionGroupUsageError', { + i18n.translate('xpack.alerting.ruleTypeRegistry.register.reservedActionGroupUsageError', { defaultMessage: - 'Alert type [id="{id}"] cannot be registered. Action groups [{actionGroups}] are reserved by the framework.', + 'Rule type [id="{id}"] cannot be registered. Action groups [{actionGroups}] are reserved by the framework.', values: { actionGroups: intersectingReservedActionGroups.join(', '), id, diff --git a/x-pack/plugins/alerting/server/rules_client/rules_client.ts b/x-pack/plugins/alerting/server/rules_client/rules_client.ts index 11db0fd8ec6c..8ded7174f4aa 100644 --- a/x-pack/plugins/alerting/server/rules_client/rules_client.ts +++ b/x-pack/plugins/alerting/server/rules_client/rules_client.ts @@ -24,7 +24,7 @@ import { Alert, PartialAlert, RawAlert, - AlertTypeRegistry, + RuleTypeRegistry, AlertAction, IntervalSchedule, SanitizedAlert, @@ -46,7 +46,7 @@ import { import { EncryptedSavedObjectsClient } from '../../../encrypted_saved_objects/server'; import { TaskManagerStartContract } from '../../../task_manager/server'; import { taskInstanceToAlertTaskInstance } from '../task_runner/alert_task_instance'; -import { RegistryAlertType, UntypedNormalizedAlertType } from '../alert_type_registry'; +import { RegistryRuleType, UntypedNormalizedAlertType } from '../rule_type_registry'; import { AlertingAuthorization, WriteOperations, @@ -69,7 +69,7 @@ import { KueryNode, nodeBuilder } from '../../../../../src/plugins/data/common'; import { mapSortField } from './lib'; import { getAlertExecutionStatusPending } from '../lib/alert_execution_status'; -export interface RegistryAlertTypeWithAuth extends RegistryAlertType { +export interface RegistryAlertTypeWithAuth extends RegistryRuleType { authorizedConsumers: string[]; } type NormalizedAlertAction = Omit; @@ -86,7 +86,7 @@ export interface ConstructorOptions { unsecuredSavedObjectsClient: SavedObjectsClientContract; authorization: AlertingAuthorization; actionsAuthorization: ActionsAuthorization; - alertTypeRegistry: AlertTypeRegistry; + ruleTypeRegistry: RuleTypeRegistry; encryptedSavedObjectsClient: EncryptedSavedObjectsClient; spaceId?: string; namespace?: string; @@ -199,7 +199,7 @@ export class RulesClient { private readonly taskManager: TaskManagerStartContract; private readonly unsecuredSavedObjectsClient: SavedObjectsClientContract; private readonly authorization: AlertingAuthorization; - private readonly alertTypeRegistry: AlertTypeRegistry; + private readonly ruleTypeRegistry: RuleTypeRegistry; private readonly createAPIKey: (name: string) => Promise; private readonly getActionsClient: () => Promise; private readonly actionsAuthorization: ActionsAuthorization; @@ -209,7 +209,7 @@ export class RulesClient { private readonly auditLogger?: AuditLogger; constructor({ - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization, taskManager, @@ -230,7 +230,7 @@ export class RulesClient { this.spaceId = spaceId; this.namespace = namespace; this.taskManager = taskManager; - this.alertTypeRegistry = alertTypeRegistry; + this.ruleTypeRegistry = ruleTypeRegistry; this.unsecuredSavedObjectsClient = unsecuredSavedObjectsClient; this.authorization = authorization; this.createAPIKey = createAPIKey; @@ -266,31 +266,31 @@ export class RulesClient { throw error; } - this.alertTypeRegistry.ensureAlertTypeEnabled(data.alertTypeId); + this.ruleTypeRegistry.ensureRuleTypeEnabled(data.alertTypeId); // Throws an error if alert type isn't registered - const alertType = this.alertTypeRegistry.get(data.alertTypeId); + const ruleType = this.ruleTypeRegistry.get(data.alertTypeId); const validatedAlertTypeParams = validateAlertTypeParams( data.params, - alertType.validate?.params + ruleType.validate?.params ); const username = await this.getUserName(); let createdAPIKey = null; try { createdAPIKey = data.enabled - ? await this.createAPIKey(this.generateAPIKeyName(alertType.id, data.name)) + ? await this.createAPIKey(this.generateAPIKeyName(ruleType.id, data.name)) : null; } catch (error) { throw Boom.badRequest(`Error creating rule: could not create API key - ${error.message}`); } - await this.validateActions(alertType, data.actions); + await this.validateActions(ruleType, data.actions); // Extract saved object references for this rule const { references, params: updatedParams, actions } = await this.extractReferences( - alertType, + ruleType, data.actions, validatedAlertTypeParams ); @@ -731,7 +731,7 @@ export class RulesClient { }) ); - this.alertTypeRegistry.ensureAlertTypeEnabled(alertSavedObject.attributes.alertTypeId); + this.ruleTypeRegistry.ensureRuleTypeEnabled(alertSavedObject.attributes.alertTypeId); const updateResult = await this.updateAlert({ id, data }, alertSavedObject); @@ -771,18 +771,18 @@ export class RulesClient { { id, data }: UpdateOptions, { attributes, version }: SavedObject ): Promise> { - const alertType = this.alertTypeRegistry.get(attributes.alertTypeId); + const ruleType = this.ruleTypeRegistry.get(attributes.alertTypeId); // Validate const validatedAlertTypeParams = validateAlertTypeParams( data.params, - alertType.validate?.params + ruleType.validate?.params ); - await this.validateActions(alertType, data.actions); + await this.validateActions(ruleType, data.actions); // Extract saved object references for this rule const { references, params: updatedParams, actions } = await this.extractReferences( - alertType, + ruleType, data.actions, validatedAlertTypeParams ); @@ -792,7 +792,7 @@ export class RulesClient { let createdAPIKey = null; try { createdAPIKey = attributes.enabled - ? await this.createAPIKey(this.generateAPIKeyName(alertType.id, data.name)) + ? await this.createAPIKey(this.generateAPIKeyName(ruleType.id, data.name)) : null; } catch (error) { throw Boom.badRequest(`Error updating rule: could not create API key - ${error.message}`); @@ -835,7 +835,7 @@ export class RulesClient { return this.getPartialAlertFromRaw( id, - alertType, + ruleType, updatedObject.attributes, updatedObject.references ); @@ -938,7 +938,7 @@ export class RulesClient { }) ); - this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId); + this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId); try { await this.unsecuredSavedObjectsClient.update('alert', id, updateAttributes, { version }); @@ -1024,7 +1024,7 @@ export class RulesClient { }) ); - this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId); + this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId); if (attributes.enabled === false) { const username = await this.getUserName(); @@ -1138,7 +1138,7 @@ export class RulesClient { }) ); - this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId); + this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId); if (attributes.enabled === true) { await this.unsecuredSavedObjectsClient.update( @@ -1215,7 +1215,7 @@ export class RulesClient { }) ); - this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId); + this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId); const updateAttributes = this.updateMeta({ muteAll: true, @@ -1277,7 +1277,7 @@ export class RulesClient { }) ); - this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId); + this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId); const updateAttributes = this.updateMeta({ muteAll: false, @@ -1339,7 +1339,7 @@ export class RulesClient { }) ); - this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId); + this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId); const mutedInstanceIds = attributes.mutedInstanceIds || []; if (!attributes.muteAll && !mutedInstanceIds.includes(alertInstanceId)) { @@ -1406,7 +1406,7 @@ export class RulesClient { }) ); - this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId); + this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId); const mutedInstanceIds = attributes.mutedInstanceIds || []; if (!attributes.muteAll && mutedInstanceIds.includes(alertInstanceId)) { @@ -1425,7 +1425,7 @@ export class RulesClient { public async listAlertTypes() { return await this.authorization.filterByRuleTypeAuthorization( - this.alertTypeRegistry.list(), + this.ruleTypeRegistry.list(), [ReadOperations.Get, WriteOperations.Create], AlertingAuthorizationEntity.Rule ); @@ -1471,7 +1471,7 @@ export class RulesClient { rawAlert: RawAlert, references: SavedObjectReference[] | undefined ): Alert { - const ruleType = this.alertTypeRegistry.get(ruleTypeId); + const ruleType = this.ruleTypeRegistry.get(ruleTypeId); // In order to support the partial update API of Saved Objects we have to support // partial updates of an Alert, but when we receive an actual RawAlert, it is safe // to cast the result to an Alert diff --git a/x-pack/plugins/alerting/server/rules_client/tests/aggregate.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/aggregate.test.ts index 2e6944a8bb4f..a336b961ace0 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/aggregate.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/aggregate.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -17,10 +17,10 @@ import { ActionsAuthorization } from '../../../../actions/server'; import { getBeforeSetup, setGlobalDate } from './lib'; import { AlertExecutionStatusValues } from '../../types'; import { RecoveredActionGroup } from '../../../common'; -import { RegistryAlertType } from '../../alert_type_registry'; +import { RegistryRuleType } from '../../rule_type_registry'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); @@ -30,7 +30,7 @@ const actionsAuthorization = actionsAuthorizationMock.create(); const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -46,13 +46,13 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); }); setGlobalDate(); describe('aggregate()', () => { - const listedTypes = new Set([ + const listedTypes = new Set([ { actionGroups: [], actionVariables: undefined, @@ -102,7 +102,7 @@ describe('aggregate()', () => { page: 1, saved_objects: [], }); - alertTypeRegistry.list.mockReturnValue(listedTypes); + ruleTypeRegistry.list.mockReturnValue(listedTypes); authorization.filterByRuleTypeAuthorization.mockResolvedValue( new Set([ { diff --git a/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts index 1a5032e14214..944dcc29ff93 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts @@ -9,7 +9,7 @@ import { schema } from '@kbn/config-schema'; import { RulesClient, ConstructorOptions, CreateOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -28,7 +28,7 @@ jest.mock('../../../../../../src/core/server/saved_objects/service/lib/utils', ( })); const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -38,7 +38,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -55,7 +55,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); @@ -823,7 +823,7 @@ describe('create()', () => { bar: true, parameterThatIsSavedObjectId: '9', }); - alertTypeRegistry.get.mockImplementation(() => ({ + ruleTypeRegistry.get.mockImplementation(() => ({ id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], @@ -1000,7 +1000,7 @@ describe('create()', () => { bar: true, parameterThatIsSavedObjectId: '8', }); - alertTypeRegistry.get.mockImplementation(() => ({ + ruleTypeRegistry.get.mockImplementation(() => ({ id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], @@ -1629,7 +1629,7 @@ describe('create()', () => { test('should validate params', async () => { const data = getMockData(); - alertTypeRegistry.get.mockReturnValue({ + ruleTypeRegistry.get.mockReturnValue({ id: '123', name: 'Test', actionGroups: [ @@ -1784,7 +1784,7 @@ describe('create()', () => { test('throws an error if alert type not registerd', async () => { const data = getMockData(); - alertTypeRegistry.get.mockImplementation(() => { + ruleTypeRegistry.get.mockImplementation(() => { throw new Error('Invalid type'); }); await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot( @@ -2032,7 +2032,7 @@ describe('create()', () => { test('throws error when ensureActionTypeEnabled throws', async () => { const data = getMockData(); - alertTypeRegistry.ensureAlertTypeEnabled.mockImplementation(() => { + ruleTypeRegistry.ensureRuleTypeEnabled.mockImplementation(() => { throw new Error('Fail'); }); await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(`"Fail"`); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/delete.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/delete.test.ts index 50a3cbf632a0..681af1415f34 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/delete.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/delete.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -19,7 +19,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock'; import { getBeforeSetup } from './lib'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -29,7 +29,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -46,7 +46,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/disable.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/disable.test.ts index 2cae59184932..3cfc649cfcc3 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/disable.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/disable.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -20,7 +20,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock'; import { getBeforeSetup, setGlobalDate } from './lib'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -30,7 +30,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -47,7 +47,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/enable.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/enable.test.ts index 4692abbae521..ca3773c4d51e 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/enable.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/enable.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -21,7 +21,7 @@ import { InvalidatePendingApiKey } from '../../types'; import { getBeforeSetup, setGlobalDate } from './lib'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -31,7 +31,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -48,7 +48,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/find.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/find.test.ts index c2abfa9b3657..b839fdad3e6c 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/find.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/find.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { nodeTypes } from '@kbn/es-query'; import { esKuery } from '../../../../../../src/plugins/data/server'; @@ -20,10 +20,10 @@ import { httpServerMock } from '../../../../../../src/core/server/mocks'; import { auditServiceMock } from '../../../../security/server/audit/index.mock'; import { getBeforeSetup, setGlobalDate } from './lib'; import { RecoveredActionGroup } from '../../../common'; -import { RegistryAlertType } from '../../alert_type_registry'; +import { RegistryRuleType } from '../../rule_type_registry'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -33,7 +33,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -49,7 +49,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); @@ -60,7 +60,7 @@ jest.mock('../lib/map_sort_field', () => ({ })); describe('find()', () => { - const listedTypes = new Set([ + const listedTypes = new Set([ { actionGroups: [], recoveryActionGroup: RecoveredActionGroup, @@ -117,7 +117,7 @@ describe('find()', () => { }, ], }); - alertTypeRegistry.list.mockReturnValue(listedTypes); + ruleTypeRegistry.list.mockReturnValue(listedTypes); authorization.filterByRuleTypeAuthorization.mockResolvedValue( new Set([ { @@ -201,7 +201,7 @@ describe('find()', () => { bar: true, parameterThatIsSavedObjectId: '9', }); - alertTypeRegistry.list.mockReturnValue( + ruleTypeRegistry.list.mockReturnValue( new Set([ ...listedTypes, { @@ -218,7 +218,7 @@ describe('find()', () => { }, ]) ); - alertTypeRegistry.get.mockImplementationOnce(() => ({ + ruleTypeRegistry.get.mockImplementationOnce(() => ({ id: 'myType', name: 'myType', actionGroups: [{ id: 'default', name: 'Default' }], @@ -229,7 +229,7 @@ describe('find()', () => { async executor() {}, producer: 'myApp', })); - alertTypeRegistry.get.mockImplementationOnce(() => ({ + ruleTypeRegistry.get.mockImplementationOnce(() => ({ id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], @@ -396,7 +396,7 @@ describe('find()', () => { const injectReferencesFn = jest.fn().mockImplementation(() => { throw new Error('something went wrong!'); }); - alertTypeRegistry.list.mockReturnValue( + ruleTypeRegistry.list.mockReturnValue( new Set([ ...listedTypes, { @@ -413,7 +413,7 @@ describe('find()', () => { }, ]) ); - alertTypeRegistry.get.mockImplementationOnce(() => ({ + ruleTypeRegistry.get.mockImplementationOnce(() => ({ id: 'myType', name: 'myType', actionGroups: [{ id: 'default', name: 'Default' }], @@ -424,7 +424,7 @@ describe('find()', () => { async executor() {}, producer: 'myApp', })); - alertTypeRegistry.get.mockImplementationOnce(() => ({ + ruleTypeRegistry.get.mockImplementationOnce(() => ({ id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], diff --git a/x-pack/plugins/alerting/server/rules_client/tests/get.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/get.test.ts index 22e8631f6f18..c25dcfdebeea 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/get.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/get.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -20,7 +20,7 @@ import { getBeforeSetup, setGlobalDate } from './lib'; import { RecoveredActionGroup } from '../../../common'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -30,7 +30,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -46,7 +46,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); @@ -124,7 +124,7 @@ describe('get()', () => { bar: true, parameterThatIsSavedObjectId: '9', }); - alertTypeRegistry.get.mockImplementation(() => ({ + ruleTypeRegistry.get.mockImplementation(() => ({ id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], @@ -244,7 +244,7 @@ describe('get()', () => { const injectReferencesFn = jest.fn().mockImplementation(() => { throw new Error('something went wrong!'); }); - alertTypeRegistry.get.mockImplementation(() => ({ + ruleTypeRegistry.get.mockImplementation(() => ({ id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], diff --git a/x-pack/plugins/alerting/server/rules_client/tests/get_alert_instance_summary.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/get_alert_instance_summary.test.ts index 85a59e35b64d..d946c354872a 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/get_alert_instance_summary.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/get_alert_instance_summary.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -22,7 +22,7 @@ import { RawAlert } from '../../types'; import { getBeforeSetup, mockedDateString, setGlobalDate } from './lib'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const eventLogClient = eventLogClientMock.create(); @@ -33,7 +33,7 @@ const actionsAuthorization = actionsAuthorizationMock.create(); const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -49,7 +49,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry, eventLogClient); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry, eventLogClient); }); setGlobalDate(); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/get_alert_state.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/get_alert_state.test.ts index e8074692d202..8f1d11576576 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/get_alert_state.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/get_alert_state.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { TaskStatus } from '../../../../task_manager/server'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; @@ -18,7 +18,7 @@ import { ActionsAuthorization } from '../../../../actions/server'; import { getBeforeSetup } from './lib'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); @@ -28,7 +28,7 @@ const actionsAuthorization = actionsAuthorizationMock.create(); const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -44,7 +44,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); }); describe('getAlertState()', () => { diff --git a/x-pack/plugins/alerting/server/rules_client/tests/lib.ts b/x-pack/plugins/alerting/server/rules_client/tests/lib.ts index 5bd256dcc3c4..c45faf770ac6 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/lib.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/lib.ts @@ -10,7 +10,7 @@ import { IEventLogClient } from '../../../../event_log/server'; import { actionsClientMock } from '../../../../actions/server/mocks'; import { ConstructorOptions } from '../rules_client'; import { eventLogClientMock } from '../../../../event_log/server/mocks'; -import { AlertTypeRegistry } from '../../alert_type_registry'; +import { RuleTypeRegistry } from '../../rule_type_registry'; import { RecoveredActionGroup } from '../../../common'; export const mockedDateString = '2019-02-12T21:01:22.479Z'; @@ -44,7 +44,7 @@ export function setGlobalDate() { export function getBeforeSetup( rulesClientParams: jest.Mocked, taskManager: ReturnType, - alertTypeRegistry: jest.Mocked>, + ruleTypeRegistry: jest.Mocked>, eventLogClient?: jest.Mocked ) { jest.resetAllMocks(); @@ -81,7 +81,7 @@ export function getBeforeSetup( ]); rulesClientParams.getActionsClient.mockResolvedValue(actionsClient); - alertTypeRegistry.get.mockImplementation(() => ({ + ruleTypeRegistry.get.mockImplementation(() => ({ id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], diff --git a/x-pack/plugins/alerting/server/rules_client/tests/list_alert_types.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/list_alert_types.test.ts index 2ea00f0bd6c2..19296f25a9a6 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/list_alert_types.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/list_alert_types.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -19,10 +19,10 @@ import { import { ActionsAuthorization } from '../../../../actions/server'; import { getBeforeSetup } from './lib'; import { RecoveredActionGroup } from '../../../common'; -import { RegistryAlertType } from '../../alert_type_registry'; +import { RegistryRuleType } from '../../rule_type_registry'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); @@ -32,7 +32,7 @@ const actionsAuthorization = actionsAuthorizationMock.create(); const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -48,12 +48,12 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); }); describe('listAlertTypes', () => { let rulesClient: RulesClient; - const alertingAlertType: RegistryAlertType = { + const alertingAlertType: RegistryRuleType = { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', @@ -65,7 +65,7 @@ describe('listAlertTypes', () => { producer: 'alerts', enabledInLicense: true, }; - const myAppAlertType: RegistryAlertType = { + const myAppAlertType: RegistryRuleType = { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', @@ -90,7 +90,7 @@ describe('listAlertTypes', () => { }); test('should return a list of AlertTypes that exist in the registry', async () => { - alertTypeRegistry.list.mockReturnValue(setOfAlertTypes); + ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes); authorization.filterByRuleTypeAuthorization.mockResolvedValue( new Set([ { ...myAppAlertType, authorizedConsumers }, @@ -106,7 +106,7 @@ describe('listAlertTypes', () => { }); describe('authorization', () => { - const listedTypes = new Set([ + const listedTypes = new Set([ { actionGroups: [], actionVariables: undefined, @@ -132,7 +132,7 @@ describe('listAlertTypes', () => { }, ]); beforeEach(() => { - alertTypeRegistry.list.mockReturnValue(listedTypes); + ruleTypeRegistry.list.mockReturnValue(listedTypes); }); test('should return a list of AlertTypes that exist in the registry only if the user is authorised to get them', async () => { diff --git a/x-pack/plugins/alerting/server/rules_client/tests/mute_all.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/mute_all.test.ts index ed315dfff40c..bea4c33659a1 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/mute_all.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/mute_all.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -19,7 +19,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock'; import { getBeforeSetup, setGlobalDate } from './lib'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -29,7 +29,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -45,7 +45,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/mute_instance.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/mute_instance.test.ts index 8f4c3ea5d68b..40baa663438e 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/mute_instance.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/mute_instance.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -19,7 +19,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock'; import { getBeforeSetup, setGlobalDate } from './lib'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -29,7 +29,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -45,7 +45,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/unmute_all.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/unmute_all.test.ts index 732cf0083fd1..b863d87f28d6 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/unmute_all.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/unmute_all.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -19,7 +19,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock'; import { getBeforeSetup, setGlobalDate } from './lib'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -29,7 +29,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -45,7 +45,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/unmute_instance.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/unmute_instance.test.ts index e94007171e07..6a1cca4a3821 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/unmute_instance.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/unmute_instance.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -19,7 +19,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock'; import { getBeforeSetup, setGlobalDate } from './lib'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -29,7 +29,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -45,7 +45,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/update.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/update.test.ts index 8880b4e2cd0c..ceeaf0e183fb 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/update.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/update.test.ts @@ -10,7 +10,7 @@ import { schema } from '@kbn/config-schema'; import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { IntervalSchedule, InvalidatePendingApiKey } from '../../types'; import { RecoveredActionGroup } from '../../../common'; @@ -31,7 +31,7 @@ jest.mock('../../../../../../src/core/server/saved_objects/service/lib/utils', ( })); const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -41,7 +41,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -58,7 +58,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); @@ -127,7 +127,7 @@ describe('update()', () => { rulesClientParams.getActionsClient.mockResolvedValue(actionsClient); unsecuredSavedObjectsClient.get.mockResolvedValue(existingAlert); encryptedSavedObjects.getDecryptedAsInternalUser.mockResolvedValue(existingDecryptedAlert); - alertTypeRegistry.get.mockReturnValue({ + ruleTypeRegistry.get.mockReturnValue({ id: 'myType', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], @@ -429,7 +429,7 @@ describe('update()', () => { bar: true, parameterThatIsSavedObjectId: '9', }); - alertTypeRegistry.get.mockImplementation(() => ({ + ruleTypeRegistry.get.mockImplementation(() => ({ id: 'myType', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], @@ -940,7 +940,7 @@ describe('update()', () => { }); it('should validate params', async () => { - alertTypeRegistry.get.mockReturnValueOnce({ + ruleTypeRegistry.get.mockReturnValueOnce({ id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], @@ -1264,7 +1264,7 @@ describe('update()', () => { updatedSchedule: IntervalSchedule ) { // mock return values from deps - alertTypeRegistry.get.mockReturnValueOnce({ + ruleTypeRegistry.get.mockReturnValueOnce({ id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], diff --git a/x-pack/plugins/alerting/server/rules_client/tests/update_api_key.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/update_api_key.test.ts index 6c9015814f9b..8c99cea9e12c 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/update_api_key.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/update_api_key.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks'; import { taskManagerMock } from '../../../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks'; import { actionsAuthorizationMock } from '../../../../actions/server/mocks'; @@ -20,7 +20,7 @@ import { InvalidatePendingApiKey } from '../../types'; import { getBeforeSetup, setGlobalDate } from './lib'; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); const authorization = alertingAuthorizationMock.create(); @@ -30,7 +30,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba const kibanaVersion = 'v7.10.0'; const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -47,7 +47,7 @@ const rulesClientParams: jest.Mocked = { }; beforeEach(() => { - getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry); + getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry); (auditLogger.log as jest.Mock).mockClear(); }); diff --git a/x-pack/plugins/alerting/server/rules_client_conflict_retries.test.ts b/x-pack/plugins/alerting/server/rules_client_conflict_retries.test.ts index 6c82fa679810..f4ac4084dc6f 100644 --- a/x-pack/plugins/alerting/server/rules_client_conflict_retries.test.ts +++ b/x-pack/plugins/alerting/server/rules_client_conflict_retries.test.ts @@ -10,7 +10,7 @@ import { cloneDeep } from 'lodash'; import { RulesClient, ConstructorOptions } from './rules_client'; import { savedObjectsClientMock, loggingSystemMock } from '../../../../src/core/server/mocks'; import { taskManagerMock } from '../../task_manager/server/mocks'; -import { alertTypeRegistryMock } from './alert_type_registry.mock'; +import { ruleTypeRegistryMock } from './rule_type_registry.mock'; import { alertingAuthorizationMock } from './authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '../../encrypted_saved_objects/server/mocks'; import { actionsClientMock, actionsAuthorizationMock } from '../../actions/server/mocks'; @@ -28,7 +28,7 @@ const MockAlertId = 'alert-id'; const ConflictAfterRetries = RetryForConflictsAttempts + 1; const taskManager = taskManagerMock.createStart(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); const encryptedSavedObjects = encryptedSavedObjectsMock.createClient(); @@ -39,7 +39,7 @@ const kibanaVersion = 'v7.10.0'; const logger = loggingSystemMock.create().get(); const rulesClientParams: jest.Mocked = { taskManager, - alertTypeRegistry, + ruleTypeRegistry, unsecuredSavedObjectsClient, authorization: (authorization as unknown) as AlertingAuthorization, actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization, @@ -327,7 +327,7 @@ beforeEach(() => { actionsClient.getBulk.mockResolvedValue([]); rulesClientParams.getActionsClient.mockResolvedValue(actionsClient); - alertTypeRegistry.get.mockImplementation((id) => ({ + ruleTypeRegistry.get.mockImplementation((id) => ({ id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], @@ -339,7 +339,7 @@ beforeEach(() => { producer: 'alerts', })); - alertTypeRegistry.get.mockReturnValue({ + ruleTypeRegistry.get.mockReturnValue({ id: 'myType', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], diff --git a/x-pack/plugins/alerting/server/rules_client_factory.test.ts b/x-pack/plugins/alerting/server/rules_client_factory.test.ts index 17f26929c4a9..df59205cf10b 100644 --- a/x-pack/plugins/alerting/server/rules_client_factory.test.ts +++ b/x-pack/plugins/alerting/server/rules_client_factory.test.ts @@ -7,7 +7,7 @@ import { Request } from '@hapi/hapi'; import { RulesClientFactory, RulesClientFactoryOpts } from './rules_client_factory'; -import { alertTypeRegistryMock } from './alert_type_registry.mock'; +import { ruleTypeRegistryMock } from './rule_type_registry.mock'; import { taskManagerMock } from '../../task_manager/server/mocks'; import { KibanaRequest } from '../../../../src/core/server'; import { @@ -44,7 +44,7 @@ const alertingAuthorizationClientFactory = alertingAuthorizationClientFactoryMoc const rulesClientFactoryParams: jest.Mocked = { logger: loggingSystemMock.create().get(), taskManager: taskManagerMock.createStart(), - alertTypeRegistry: alertTypeRegistryMock.create(), + ruleTypeRegistry: ruleTypeRegistryMock.create(), getSpaceId: jest.fn(), spaceIdToNamespace: jest.fn(), encryptedSavedObjectsClient: encryptedSavedObjectsMock.createClient(), @@ -119,7 +119,7 @@ test('creates an alerts client with proper constructor arguments when security i actionsAuthorization, logger: rulesClientFactoryParams.logger, taskManager: rulesClientFactoryParams.taskManager, - alertTypeRegistry: rulesClientFactoryParams.alertTypeRegistry, + ruleTypeRegistry: rulesClientFactoryParams.ruleTypeRegistry, spaceId: 'default', namespace: 'default', getUserName: expect.any(Function), @@ -158,7 +158,7 @@ test('creates an alerts client with proper constructor arguments', async () => { actionsAuthorization, logger: rulesClientFactoryParams.logger, taskManager: rulesClientFactoryParams.taskManager, - alertTypeRegistry: rulesClientFactoryParams.alertTypeRegistry, + ruleTypeRegistry: rulesClientFactoryParams.ruleTypeRegistry, spaceId: 'default', namespace: 'default', getUserName: expect.any(Function), diff --git a/x-pack/plugins/alerting/server/rules_client_factory.ts b/x-pack/plugins/alerting/server/rules_client_factory.ts index 3c6800fc5bd7..336c8e6de20e 100644 --- a/x-pack/plugins/alerting/server/rules_client_factory.ts +++ b/x-pack/plugins/alerting/server/rules_client_factory.ts @@ -13,7 +13,7 @@ import { } from 'src/core/server'; import { PluginStartContract as ActionsPluginStartContract } from '../../actions/server'; import { RulesClient } from './rules_client'; -import { AlertTypeRegistry, SpaceIdToNamespaceFunction } from './types'; +import { RuleTypeRegistry, SpaceIdToNamespaceFunction } from './types'; import { SecurityPluginSetup, SecurityPluginStart } from '../../security/server'; import { EncryptedSavedObjectsClient } from '../../encrypted_saved_objects/server'; import { TaskManagerStartContract } from '../../task_manager/server'; @@ -23,7 +23,7 @@ import { ALERTS_FEATURE_ID } from '../common'; export interface RulesClientFactoryOpts { logger: Logger; taskManager: TaskManagerStartContract; - alertTypeRegistry: AlertTypeRegistry; + ruleTypeRegistry: RuleTypeRegistry; securityPluginSetup?: SecurityPluginSetup; securityPluginStart?: SecurityPluginStart; getSpaceId: (request: KibanaRequest) => string | undefined; @@ -39,7 +39,7 @@ export class RulesClientFactory { private isInitialized = false; private logger!: Logger; private taskManager!: TaskManagerStartContract; - private alertTypeRegistry!: AlertTypeRegistry; + private ruleTypeRegistry!: RuleTypeRegistry; private securityPluginSetup?: SecurityPluginSetup; private securityPluginStart?: SecurityPluginStart; private getSpaceId!: (request: KibanaRequest) => string | undefined; @@ -58,7 +58,7 @@ export class RulesClientFactory { this.logger = options.logger; this.getSpaceId = options.getSpaceId; this.taskManager = options.taskManager; - this.alertTypeRegistry = options.alertTypeRegistry; + this.ruleTypeRegistry = options.ruleTypeRegistry; this.securityPluginSetup = options.securityPluginSetup; this.securityPluginStart = options.securityPluginStart; this.spaceIdToNamespace = options.spaceIdToNamespace; @@ -82,7 +82,7 @@ export class RulesClientFactory { kibanaVersion: this.kibanaVersion, logger: this.logger, taskManager: this.taskManager, - alertTypeRegistry: this.alertTypeRegistry, + ruleTypeRegistry: this.ruleTypeRegistry, unsecuredSavedObjectsClient: savedObjects.getScopedClient(request, { excludedWrappers: ['security'], includedHiddenTypes: ['alert', 'api_key_pending_invalidation'], diff --git a/x-pack/plugins/alerting/server/saved_objects/index.ts b/x-pack/plugins/alerting/server/saved_objects/index.ts index 88ee3179ab3d..cadbc01e8e00 100644 --- a/x-pack/plugins/alerting/server/saved_objects/index.ts +++ b/x-pack/plugins/alerting/server/saved_objects/index.ts @@ -19,7 +19,7 @@ import { transformRulesForExport } from './transform_rule_for_export'; import { RawAlert } from '../types'; import { getImportWarnings } from './get_import_warnings'; import { isRuleExportable } from './is_rule_exportable'; -import { AlertTypeRegistry } from '../alert_type_registry'; +import { RuleTypeRegistry } from '../rule_type_registry'; export { partiallyUpdateAlert } from './partially_update_alert'; @@ -47,7 +47,7 @@ export type AlertAttributesExcludedFromAADType = export function setupSavedObjects( savedObjects: SavedObjectsServiceSetup, encryptedSavedObjects: EncryptedSavedObjectsPluginSetup, - ruleTypeRegistry: AlertTypeRegistry, + ruleTypeRegistry: RuleTypeRegistry, logger: Logger ) { savedObjects.registerType({ diff --git a/x-pack/plugins/alerting/server/saved_objects/is_rule_exportable.test.ts b/x-pack/plugins/alerting/server/saved_objects/is_rule_exportable.test.ts index cc2dfbd3e2d2..8a22ded2886f 100644 --- a/x-pack/plugins/alerting/server/saved_objects/is_rule_exportable.test.ts +++ b/x-pack/plugins/alerting/server/saved_objects/is_rule_exportable.test.ts @@ -7,7 +7,7 @@ import { MockedLogger, loggerMock } from '@kbn/logging/target/mocks'; import { TaskRunnerFactory } from '../task_runner'; -import { AlertTypeRegistry, ConstructorOptions } from '../alert_type_registry'; +import { RuleTypeRegistry, ConstructorOptions } from '../rule_type_registry'; import { taskManagerMock } from '../../../task_manager/server/mocks'; import { ILicenseState } from '../lib/license_state'; import { licenseStateMock } from '../lib/license_state.mock'; @@ -33,7 +33,7 @@ beforeEach(() => { describe('isRuleExportable', () => { it('should return true if rule type isExportable is true', () => { - const registry = new AlertTypeRegistry(ruleTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register({ id: 'foo', name: 'Foo', @@ -89,7 +89,7 @@ describe('isRuleExportable', () => { }); it('should return false and log warning if rule type isExportable is false', () => { - const registry = new AlertTypeRegistry(ruleTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register({ id: 'foo', name: 'Foo', @@ -148,7 +148,7 @@ describe('isRuleExportable', () => { }); it('should return false and log warning if rule type is not registered', () => { - const registry = new AlertTypeRegistry(ruleTypeRegistryParams); + const registry = new RuleTypeRegistry(ruleTypeRegistryParams); registry.register({ id: 'foo', name: 'Foo', diff --git a/x-pack/plugins/alerting/server/saved_objects/is_rule_exportable.ts b/x-pack/plugins/alerting/server/saved_objects/is_rule_exportable.ts index 38290e5f465c..9c4e4f2b4d40 100644 --- a/x-pack/plugins/alerting/server/saved_objects/is_rule_exportable.ts +++ b/x-pack/plugins/alerting/server/saved_objects/is_rule_exportable.ts @@ -7,11 +7,11 @@ import { Logger, SavedObject } from 'kibana/server'; import { RawAlert } from '../types'; -import { AlertTypeRegistry } from '../alert_type_registry'; +import { RuleTypeRegistry } from '../rule_type_registry'; export function isRuleExportable( rule: SavedObject, - ruleTypeRegistry: AlertTypeRegistry, + ruleTypeRegistry: RuleTypeRegistry, logger: Logger ): boolean { const ruleSO = rule as SavedObject; diff --git a/x-pack/plugins/alerting/server/task_runner/create_execution_handler.test.ts b/x-pack/plugins/alerting/server/task_runner/create_execution_handler.test.ts index a40f7dc2abc7..e3946599aed8 100644 --- a/x-pack/plugins/alerting/server/task_runner/create_execution_handler.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/create_execution_handler.test.ts @@ -16,7 +16,7 @@ import { eventLoggerMock } from '../../../event_log/server/event_logger.mock'; import { KibanaRequest } from 'kibana/server'; import { asSavedObjectExecutionSource } from '../../../actions/server'; import { InjectActionParamsOpts } from './inject_action_params'; -import { NormalizedAlertType } from '../alert_type_registry'; +import { NormalizedAlertType } from '../rule_type_registry'; import { AlertTypeParams, AlertTypeState, diff --git a/x-pack/plugins/alerting/server/task_runner/create_execution_handler.ts b/x-pack/plugins/alerting/server/task_runner/create_execution_handler.ts index 808e9f5de8f4..51301a80b166 100644 --- a/x-pack/plugins/alerting/server/task_runner/create_execution_handler.ts +++ b/x-pack/plugins/alerting/server/task_runner/create_execution_handler.ts @@ -21,7 +21,7 @@ import { AlertInstanceContext, RawAlert, } from '../types'; -import { NormalizedAlertType } from '../alert_type_registry'; +import { NormalizedAlertType } from '../rule_type_registry'; import { isEphemeralTaskRejectedDueToCapacityError } from '../../../task_manager/server'; export interface CreateExecutionHandlerOptions< diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts index 2afdb54ad8a3..4d876a1d6ecb 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts @@ -36,8 +36,8 @@ import { IEventLogger } from '../../../event_log/server'; import { SavedObjectsErrorHelpers } from '../../../../../src/core/server'; import { Alert, RecoveredActionGroup } from '../../common'; import { omit } from 'lodash'; -import { UntypedNormalizedAlertType } from '../alert_type_registry'; -import { alertTypeRegistryMock } from '../alert_type_registry.mock'; +import { UntypedNormalizedAlertType } from '../rule_type_registry'; +import { ruleTypeRegistryMock } from '../rule_type_registry.mock'; import { ExecuteOptions } from '../../../actions/server/create_execute_function'; const alertType: jest.Mocked = { @@ -84,7 +84,7 @@ describe('Task Runner', () => { const services = alertsMock.createAlertServices(); const actionsClient = actionsClientMock.create(); const rulesClient = rulesClientMock.create(); - const alertTypeRegistry = alertTypeRegistryMock.create(); + const ruleTypeRegistry = ruleTypeRegistryMock.create(); type TaskRunnerFactoryInitializerParamsType = jest.Mocked & { actionsPlugin: jest.Mocked; @@ -101,7 +101,7 @@ describe('Task Runner', () => { basePathService: httpServiceMock.createBasePath(), eventLogger: eventLoggerMock.create(), internalSavedObjectsRepository: savedObjectsRepositoryMock.create(), - alertTypeRegistry, + ruleTypeRegistry, kibanaBaseUrl: 'https://localhost:5601', supportsEphemeralTasks: false, maxEphemeralActionsPerAlert: new Promise((resolve) => resolve(10)), @@ -184,7 +184,7 @@ describe('Task Runner', () => { taskRunnerFactoryInitializerParams.actionsPlugin.renderActionParameterTemplates.mockImplementation( (actionTypeId, actionId, params) => params ); - alertTypeRegistry.get.mockReturnValue(alertType); + ruleTypeRegistry.get.mockReturnValue(alertType); }); test('successfully executes the task', async () => { @@ -2623,7 +2623,7 @@ describe('Task Runner', () => { }); test('recovers gracefully when the Alert Task Runner throws an exception when license is higher than supported', async () => { - alertTypeRegistry.ensureAlertTypeEnabled.mockImplementation(() => { + ruleTypeRegistry.ensureRuleTypeEnabled.mockImplementation(() => { throw new Error('OMG'); }); diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner.ts b/x-pack/plugins/alerting/server/task_runner/task_runner.ts index c804c9035af7..63748eafe037 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.ts @@ -32,7 +32,7 @@ import { SanitizedAlert, AlertExecutionStatus, AlertExecutionStatusErrorReasons, - AlertTypeRegistry, + RuleTypeRegistry, } from '../types'; import { promiseResult, map, Resultable, asOk, asErr, resolveErr } from '../lib/result_type'; import { taskInstanceToAlertTaskInstance } from './alert_task_instance'; @@ -49,7 +49,7 @@ import { AlertInstanceContext, WithoutReservedActionGroups, } from '../../common'; -import { NormalizedAlertType } from '../alert_type_registry'; +import { NormalizedAlertType } from '../rule_type_registry'; import { getEsErrorMessage } from '../lib/errors'; const FALLBACK_RETRY_INTERVAL = '5m'; @@ -89,7 +89,7 @@ export class TaskRunner< ActionGroupIds, RecoveryActionGroupId >; - private readonly alertTypeRegistry: AlertTypeRegistry; + private readonly ruleTypeRegistry: RuleTypeRegistry; constructor( alertType: NormalizedAlertType< @@ -108,7 +108,7 @@ export class TaskRunner< this.logger = context.logger; this.alertType = alertType; this.taskInstance = taskInstanceToAlertTaskInstance(taskInstance); - this.alertTypeRegistry = context.alertTypeRegistry; + this.ruleTypeRegistry = context.ruleTypeRegistry; } async getApiKeyForAlertPermissions(alertId: string, spaceId: string) { @@ -245,7 +245,7 @@ export class TaskRunner< state: { alertInstances: alertRawInstances = {}, alertTypeState = {}, previousStartedAt }, } = this.taskInstance; const namespace = this.context.spaceIdToNamespace(spaceId); - const alertType = this.alertTypeRegistry.get(alertTypeId); + const alertType = this.ruleTypeRegistry.get(alertTypeId); const alertInstances = mapValues< Record, @@ -474,7 +474,7 @@ export class TaskRunner< } try { - this.alertTypeRegistry.ensureAlertTypeEnabled(alert.alertTypeId); + this.ruleTypeRegistry.ensureRuleTypeEnabled(alert.alertTypeId); } catch (err) { throw new ErrorWithReason(AlertExecutionStatusErrorReasons.License, err); } diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts index 011407fc94de..61aa168acf61 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts @@ -17,8 +17,8 @@ import { import { actionsMock } from '../../../actions/server/mocks'; import { alertsMock, rulesClientMock } from '../mocks'; import { eventLoggerMock } from '../../../event_log/server/event_logger.mock'; -import { UntypedNormalizedAlertType } from '../alert_type_registry'; -import { alertTypeRegistryMock } from '../alert_type_registry.mock'; +import { UntypedNormalizedAlertType } from '../rule_type_registry'; +import { ruleTypeRegistryMock } from '../rule_type_registry.mock'; const alertType: UntypedNormalizedAlertType = { id: 'test', @@ -77,7 +77,7 @@ describe('Task Runner Factory', () => { basePathService: httpServiceMock.createBasePath(), eventLogger: eventLoggerMock.create(), internalSavedObjectsRepository: savedObjectsRepositoryMock.create(), - alertTypeRegistry: alertTypeRegistryMock.create(), + ruleTypeRegistry: ruleTypeRegistryMock.create(), kibanaBaseUrl: 'https://localhost:5601', supportsEphemeralTasks: true, maxEphemeralActionsPerAlert: new Promise((resolve) => resolve(10)), diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.ts b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.ts index 72c0ef9618f6..4d9c7b37ed64 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.ts @@ -17,7 +17,7 @@ import { EncryptedSavedObjectsClient } from '../../../encrypted_saved_objects/se import { PluginStartContract as ActionsPluginStartContract } from '../../../actions/server'; import { AlertTypeParams, - AlertTypeRegistry, + RuleTypeRegistry, GetServicesFunction, SpaceIdToNamespaceFunction, AlertTypeState, @@ -27,7 +27,7 @@ import { import { TaskRunner } from './task_runner'; import { IEventLogger } from '../../../event_log/server'; import { RulesClient } from '../rules_client'; -import { NormalizedAlertType } from '../alert_type_registry'; +import { NormalizedAlertType } from '../rule_type_registry'; export interface TaskRunnerContext { logger: Logger; @@ -39,7 +39,7 @@ export interface TaskRunnerContext { spaceIdToNamespace: SpaceIdToNamespaceFunction; basePathService: IBasePath; internalSavedObjectsRepository: ISavedObjectsRepository; - alertTypeRegistry: AlertTypeRegistry; + ruleTypeRegistry: RuleTypeRegistry; kibanaBaseUrl: string | undefined; supportsEphemeralTasks: boolean; maxEphemeralActionsPerAlert: Promise; diff --git a/x-pack/plugins/alerting/server/types.ts b/x-pack/plugins/alerting/server/types.ts index 1ac1ede2591b..8b8fce7a1bf6 100644 --- a/x-pack/plugins/alerting/server/types.ts +++ b/x-pack/plugins/alerting/server/types.ts @@ -8,7 +8,7 @@ import type { IRouter, RequestHandlerContext, SavedObjectReference } from 'src/core/server'; import type { PublicMethodsOf } from '@kbn/utility-types'; import { PublicAlertInstance } from './alert_instance'; -import { AlertTypeRegistry as OrigAlertTypeRegistry } from './alert_type_registry'; +import { RuleTypeRegistry as OrigruleTypeRegistry } from './rule_type_registry'; import { PluginSetupContract, PluginStartContract } from './plugin'; import { RulesClient } from './rules_client'; export * from '../common'; @@ -45,7 +45,7 @@ export type SpaceIdToNamespaceFunction = (spaceId?: string) => string | undefine */ export interface AlertingApiRequestHandlerContext { getRulesClient: () => RulesClient; - listTypes: AlertTypeRegistry['list']; + listTypes: RuleTypeRegistry['list']; getFrameworkHealth: () => Promise; areApiKeysEnabled: () => Promise; } @@ -252,4 +252,4 @@ export interface InvalidatePendingApiKey { createdAt: string; } -export type AlertTypeRegistry = PublicMethodsOf; +export type RuleTypeRegistry = PublicMethodsOf; diff --git a/x-pack/plugins/apm/public/application/application.test.tsx b/x-pack/plugins/apm/public/application/application.test.tsx index 78cdb2fb3c97..cbc72f918877 100644 --- a/x-pack/plugins/apm/public/application/application.test.tsx +++ b/x-pack/plugins/apm/public/application/application.test.tsx @@ -49,7 +49,7 @@ describe('renderApp', () => { const plugins = { licensing: { license$: new Observable() }, - triggersActionsUi: { actionTypeRegistry: {}, alertTypeRegistry: {} }, + triggersActionsUi: { actionTypeRegistry: {}, ruleTypeRegistry: {} }, data: { query: { timefilter: { @@ -80,7 +80,7 @@ describe('renderApp', () => { }, triggersActionsUi: { actionTypeRegistry: {}, - alertTypeRegistry: {}, + ruleTypeRegistry: {}, getAddAlertFlyout: jest.fn(), getEditAlertFlyout: jest.fn(), }, diff --git a/x-pack/plugins/infra/public/plugin.ts b/x-pack/plugins/infra/public/plugin.ts index 0eaeea60c63b..3c22c1ad7a76 100644 --- a/x-pack/plugins/infra/public/plugin.ts +++ b/x-pack/plugins/infra/public/plugin.ts @@ -41,8 +41,8 @@ export class Plugin implements InfraClientPluginClass { pluginsSetup.observability.observabilityRuleTypeRegistry.register( createLogThresholdAlertType() ); + pluginsSetup.triggersActionsUi.ruleTypeRegistry.register(createMetricThresholdAlertType()); - pluginsSetup.triggersActionsUi.alertTypeRegistry.register(createMetricThresholdAlertType()); pluginsSetup.observability.dashboard.register({ appName: 'infra_logs', hasData: getLogsHasDataFetcher(core.getStartServices), diff --git a/x-pack/plugins/ml/public/alerting/jobs_health_rule/register_jobs_health_alerting_rule.ts b/x-pack/plugins/ml/public/alerting/jobs_health_rule/register_jobs_health_alerting_rule.ts index a0ca9621f5a5..dc4b10102e4f 100644 --- a/x-pack/plugins/ml/public/alerting/jobs_health_rule/register_jobs_health_alerting_rule.ts +++ b/x-pack/plugins/ml/public/alerting/jobs_health_rule/register_jobs_health_alerting_rule.ts @@ -17,7 +17,7 @@ export function registerJobsHealthAlertingRule( triggersActionsUi: TriggersAndActionsUIPublicPluginSetup, alerting?: AlertingSetup ) { - triggersActionsUi.alertTypeRegistry.register({ + triggersActionsUi.ruleTypeRegistry.register({ id: ML_ALERT_TYPES.AD_JOBS_HEALTH, description: i18n.translate('xpack.ml.alertTypes.jobsHealthAlertingRule.description', { defaultMessage: 'Alert when anomaly detection jobs experience operational issues.', diff --git a/x-pack/plugins/ml/public/alerting/register_ml_alerts.ts b/x-pack/plugins/ml/public/alerting/register_ml_alerts.ts index 99ba61f3d915..b3ceb20e67ef 100644 --- a/x-pack/plugins/ml/public/alerting/register_ml_alerts.ts +++ b/x-pack/plugins/ml/public/alerting/register_ml_alerts.ts @@ -20,7 +20,7 @@ export function registerMlAlerts( triggersActionsUi: TriggersAndActionsUIPublicPluginSetup, alerting?: AlertingSetup ) { - triggersActionsUi.alertTypeRegistry.register({ + triggersActionsUi.ruleTypeRegistry.register({ id: ML_ALERT_TYPES.ANOMALY_DETECTION, description: i18n.translate('xpack.ml.alertTypes.anomalyDetection.description', { defaultMessage: 'Alert when anomaly detection jobs results match the condition.', diff --git a/x-pack/plugins/monitoring/public/alerts/alert_form.test.tsx b/x-pack/plugins/monitoring/public/alerts/alert_form.test.tsx index 3eda13f5bcb3..a300d9a3772b 100644 --- a/x-pack/plugins/monitoring/public/alerts/alert_form.test.tsx +++ b/x-pack/plugins/monitoring/public/alerts/alert_form.test.tsx @@ -15,7 +15,7 @@ import { ReactWrapper, mount } from 'enzyme'; import { act } from 'react-dom/test-utils'; import { coreMock } from 'src/core/public/mocks'; import { actionTypeRegistryMock } from '../../../triggers_actions_ui/public/application/action_type_registry.mock'; -import { alertTypeRegistryMock } from '../../../triggers_actions_ui/public/application/alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../../triggers_actions_ui/public/application/rule_type_registry.mock'; import { ValidationResult, Alert, @@ -47,7 +47,7 @@ jest.mock('../../../triggers_actions_ui/public/application/lib/alert_api', () => const initLegacyShims = () => { const triggersActionsUi = { actionTypeRegistry: actionTypeRegistryMock.create(), - alertTypeRegistry: alertTypeRegistryMock.create(), + ruleTypeRegistry: ruleTypeRegistryMock.create(), }; const data = { query: { timefilter: { timefilter: {} } } } as any; const ngInjector = {} as angular.auto.IInjectorService; @@ -66,7 +66,7 @@ const initLegacyShims = () => { const ALERTS_FEATURE_ID = 'alerts'; const validationMethod = (): ValidationResult => ({ errors: {} }); const actionTypeRegistry = actionTypeRegistryMock.create(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); describe('alert_form', () => { beforeEach(() => { @@ -109,9 +109,9 @@ describe('alert_form', () => { let wrapper: ReactWrapper; beforeEach(async () => { - alertTypeRegistry.list.mockReturnValue([alertType]); - alertTypeRegistry.get.mockReturnValue(alertType); - alertTypeRegistry.has.mockReturnValue(true); + ruleTypeRegistry.list.mockReturnValue([alertType]); + ruleTypeRegistry.get.mockReturnValue(alertType); + ruleTypeRegistry.has.mockReturnValue(true); actionTypeRegistry.list.mockReturnValue([actionType]); actionTypeRegistry.has.mockReturnValue(true); actionTypeRegistry.get.mockReturnValue(actionType); @@ -142,7 +142,7 @@ describe('alert_form', () => { errors={{ name: [], interval: [] }} operation="create" actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} + ruleTypeRegistry={ruleTypeRegistry} /> diff --git a/x-pack/plugins/monitoring/public/legacy_shims.ts b/x-pack/plugins/monitoring/public/legacy_shims.ts index a723eea8b6d6..1d897b710d7f 100644 --- a/x-pack/plugins/monitoring/public/legacy_shims.ts +++ b/x-pack/plugins/monitoring/public/legacy_shims.ts @@ -52,7 +52,7 @@ export interface IShims { docTitle: CoreStart['chrome']['docTitle']; timefilter: MonitoringStartPluginDependencies['data']['query']['timefilter']['timefilter']; actionTypeRegistry: TypeRegistry; - alertTypeRegistry: TypeRegistry; + ruleTypeRegistry: TypeRegistry; uiSettings: IUiSettingsClient; http: HttpSetup; kfetch: ( @@ -119,7 +119,7 @@ export class Legacy { docTitle: core.chrome.docTitle, timefilter: data.query.timefilter.timefilter, actionTypeRegistry: triggersActionsUi?.actionTypeRegistry, - alertTypeRegistry: triggersActionsUi?.alertTypeRegistry, + ruleTypeRegistry: triggersActionsUi?.ruleTypeRegistry, uiSettings: core.uiSettings, http: core.http, kfetch: async ( diff --git a/x-pack/plugins/monitoring/public/plugin.ts b/x-pack/plugins/monitoring/public/plugin.ts index 9f84165a27ba..f1a9c2708d5d 100644 --- a/x-pack/plugins/monitoring/public/plugin.ts +++ b/x-pack/plugins/monitoring/public/plugin.ts @@ -171,29 +171,29 @@ export class MonitoringPlugin private registerAlerts(plugins: MonitoringSetupPluginDependencies) { const { - triggersActionsUi: { alertTypeRegistry }, + triggersActionsUi: { ruleTypeRegistry }, } = plugins; - alertTypeRegistry.register(createCpuUsageAlertType()); - alertTypeRegistry.register(createDiskUsageAlertType()); - alertTypeRegistry.register(createMemoryUsageAlertType()); - alertTypeRegistry.register(createMissingMonitoringDataAlertType()); - alertTypeRegistry.register( + ruleTypeRegistry.register(createCpuUsageAlertType()); + ruleTypeRegistry.register(createDiskUsageAlertType()); + ruleTypeRegistry.register(createMemoryUsageAlertType()); + ruleTypeRegistry.register(createMissingMonitoringDataAlertType()); + ruleTypeRegistry.register( createThreadPoolRejectionsAlertType( ALERT_THREAD_POOL_SEARCH_REJECTIONS, ALERT_DETAILS[ALERT_THREAD_POOL_SEARCH_REJECTIONS] ) ); - alertTypeRegistry.register( + ruleTypeRegistry.register( createThreadPoolRejectionsAlertType( ALERT_THREAD_POOL_WRITE_REJECTIONS, ALERT_DETAILS[ALERT_THREAD_POOL_WRITE_REJECTIONS] ) ); - alertTypeRegistry.register(createCCRReadExceptionsAlertType()); - alertTypeRegistry.register(createLargeShardSizeAlertType()); + ruleTypeRegistry.register(createCCRReadExceptionsAlertType()); + ruleTypeRegistry.register(createLargeShardSizeAlertType()); const legacyAlertTypes = createLegacyAlertTypes(); for (const legacyAlertType of legacyAlertTypes) { - alertTypeRegistry.register(legacyAlertType); + ruleTypeRegistry.register(legacyAlertType); } } } diff --git a/x-pack/plugins/observability/public/plugin.ts b/x-pack/plugins/observability/public/plugin.ts index f2ff2a01ebed..334733e36349 100644 --- a/x-pack/plugins/observability/public/plugin.ts +++ b/x-pack/plugins/observability/public/plugin.ts @@ -111,7 +111,7 @@ export class Plugin createCallObservabilityApi(coreSetup.http); const observabilityRuleTypeRegistry = createObservabilityRuleTypeRegistry( - pluginsSetup.triggersActionsUi.alertTypeRegistry + pluginsSetup.triggersActionsUi.ruleTypeRegistry ); const mount = async (params: AppMountParameters) => { diff --git a/x-pack/plugins/observability/public/rules/create_observability_rule_type_registry.ts b/x-pack/plugins/observability/public/rules/create_observability_rule_type_registry.ts index d6f8c0835988..7dd3b3fb3911 100644 --- a/x-pack/plugins/observability/public/rules/create_observability_rule_type_registry.ts +++ b/x-pack/plugins/observability/public/rules/create_observability_rule_type_registry.ts @@ -8,7 +8,7 @@ import { AlertTypeModel, AlertTypeParams, - AlertTypeRegistryContract, + RuleTypeRegistryContract, } from '../../../triggers_actions_ui/public'; import { ParsedTechnicalFields } from '../../../rule_registry/common/parse_technical_fields'; import { AsDuration, AsPercent } from '../../common/utils/formatters'; @@ -23,14 +23,14 @@ export interface ObservabilityRuleTypeModel = []; return { register: (type: ObservabilityRuleTypeModel) => { const { format, ...rest } = type; formatters.push({ typeId: type.id, fn: format }); - alertTypeRegistry.register(rest); + ruleTypeRegistry.register(rest); }, getFormatter: (typeId: string) => { return formatters.find((formatter) => formatter.typeId === typeId)?.fn; diff --git a/x-pack/plugins/stack_alerts/public/alert_types/index.ts b/x-pack/plugins/stack_alerts/public/alert_types/index.ts index d6f9f97939b7..d2f0f1860417 100644 --- a/x-pack/plugins/stack_alerts/public/alert_types/index.ts +++ b/x-pack/plugins/stack_alerts/public/alert_types/index.ts @@ -12,13 +12,13 @@ import { Config } from '../../common'; import { TriggersAndActionsUIPublicPluginSetup } from '../../../triggers_actions_ui/public'; export function registerAlertTypes({ - alertTypeRegistry, + ruleTypeRegistry, config, }: { - alertTypeRegistry: TriggersAndActionsUIPublicPluginSetup['alertTypeRegistry']; + ruleTypeRegistry: TriggersAndActionsUIPublicPluginSetup['ruleTypeRegistry']; config: Config; }) { - alertTypeRegistry.register(getGeoContainmentAlertType()); - alertTypeRegistry.register(getThresholdAlertType()); - alertTypeRegistry.register(getEsQueryAlertType()); + ruleTypeRegistry.register(getGeoContainmentAlertType()); + ruleTypeRegistry.register(getThresholdAlertType()); + ruleTypeRegistry.register(getEsQueryAlertType()); } diff --git a/x-pack/plugins/stack_alerts/public/plugin.tsx b/x-pack/plugins/stack_alerts/public/plugin.tsx index 290e45ddc138..f636139571ca 100644 --- a/x-pack/plugins/stack_alerts/public/plugin.tsx +++ b/x-pack/plugins/stack_alerts/public/plugin.tsx @@ -26,7 +26,7 @@ export class StackAlertsPublicPlugin implements Plugin(), }); } diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 4044d5c10f86..e6eb6a56b569 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -5415,9 +5415,9 @@ "xpack.alerting.alertNavigationRegistry.get.missingNavigationError": "「{consumer}」内のアラートタイプ「{alertType}」のナビゲーションは登録されていません。", "xpack.alerting.alertNavigationRegistry.register.duplicateDefaultError": "「{consumer}」内のデフォルトナビゲーションはすでに登録されています。", "xpack.alerting.alertNavigationRegistry.register.duplicateNavigationError": "「{consumer}」内のアラートタイプ「{alertType}」のナビゲーションはすでに登録されています。", - "xpack.alerting.alertTypeRegistry.get.missingAlertTypeError": "アラートタイプ「{id}」は登録されていません。", - "xpack.alerting.alertTypeRegistry.register.customRecoveryActionGroupUsageError": "アラートタイプ [id=\"{id}\"] を登録できません。アクショングループ [{actionGroup}] は、復元とアクティブなアクショングループの両方として使用できません。", - "xpack.alerting.alertTypeRegistry.register.duplicateAlertTypeError": "アラートタイプ\"{id}\"はすでに登録されています。", + "xpack.alerting.ruleTypeRegistry.get.missingAlertTypeError": "アラートタイプ「{id}」は登録されていません。", + "xpack.alerting.ruleTypeRegistry.register.customRecoveryActionGroupUsageError": "アラートタイプ [id=\"{id}\"] を登録できません。アクショングループ [{actionGroup}] は、復元とアクティブなアクショングループの両方として使用できません。", + "xpack.alerting.ruleTypeRegistry.register.duplicateAlertTypeError": "アラートタイプ\"{id}\"はすでに登録されています。", "xpack.alerting.api.error.disabledApiKeys": "アラートは API キーに依存しますがキーが無効になっているようです", "xpack.alerting.appName": "アラート", "xpack.alerting.builtinActionGroups.recovered": "回復済み", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index cc6393b64030..164c81c36b42 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -5445,10 +5445,10 @@ "xpack.alerting.alertNavigationRegistry.get.missingNavigationError": "在“{consumer}”内针对告警类型“{alertType}”的导航未注册。", "xpack.alerting.alertNavigationRegistry.register.duplicateDefaultError": "“{consumer}”内的默认导航已注册。", "xpack.alerting.alertNavigationRegistry.register.duplicateNavigationError": "在“{consumer}”内针对告警类型“{alertType}”的导航已注册。", - "xpack.alerting.alertTypeRegistry.get.missingAlertTypeError": "未注册告警类型“{id}”。", - "xpack.alerting.alertTypeRegistry.register.customRecoveryActionGroupUsageError": "无法注册告警类型 [id=\"{id}\"]。操作组 [{actionGroup}] 无法同时用作恢复和活动操作组。", - "xpack.alerting.alertTypeRegistry.register.duplicateAlertTypeError": "已注册告警类型“{id}”。", - "xpack.alerting.alertTypeRegistry.register.reservedActionGroupUsageError": "无法注册告警类型 [id=\"{id}\"]。操作组 [{actionGroups}] 由框架保留。", + "xpack.alerting.ruleTypeRegistry.get.missingAlertTypeError": "未注册告警类型“{id}”。", + "xpack.alerting.ruleTypeRegistry.register.customRecoveryActionGroupUsageError": "无法注册告警类型 [id=\"{id}\"]。操作组 [{actionGroup}] 无法同时用作恢复和活动操作组。", + "xpack.alerting.ruleTypeRegistry.register.duplicateAlertTypeError": "已注册告警类型“{id}”。", + "xpack.alerting.ruleTypeRegistry.register.reservedActionGroupUsageError": "无法注册告警类型 [id=\"{id}\"]。操作组 [{actionGroups}] 由框架保留。", "xpack.alerting.api.error.disabledApiKeys": "Alerting 依赖的 API 密钥似乎已禁用", "xpack.alerting.appName": "Alerting", "xpack.alerting.builtinActionGroups.recovered": "已恢复", diff --git a/x-pack/plugins/triggers_actions_ui/README.md b/x-pack/plugins/triggers_actions_ui/README.md index cd83be0138fa..999d62db304f 100644 --- a/x-pack/plugins/triggers_actions_ui/README.md +++ b/x-pack/plugins/triggers_actions_ui/README.md @@ -289,7 +289,7 @@ function getSomeNewAlertType() { return { ... } as AlertTypeModel; } -triggersActionsUi.alertTypeRegistry.register(getSomeNewAlertType()); +triggersActionsUi.ruleTypeRegistry.register(getSomeNewAlertType()); ``` ## Create and register new alert type UI example @@ -409,7 +409,7 @@ import { getAlertType as getExampledAlertType } from './example'; ... ... -alertTypeRegistry.register(getExampledAlertType()); +ruleTypeRegistry.register(getExampledAlertType()); ``` After these four steps, the new `Example Alert Type` is available in UI of Create flyout: @@ -1472,7 +1472,7 @@ interface ActionAccordionFormProps { |---|---| |onSave|Optional function, which will be executed if alert was saved sucsessfuly.| |http|HttpSetup needed for executing API calls.| -|alertTypeRegistry|Registry for alert types.| +|ruleTypeRegistry|Registry for alert types.| |actionTypeRegistry|Registry for action types.| |uiSettings|Optional property, which is needed to display visualization of alert type expression. Will be changed after visualization refactoring.| |docLinks|Documentation Links, needed to link to the documentation from informational callouts.| diff --git a/x-pack/plugins/triggers_actions_ui/public/application/app.tsx b/x-pack/plugins/triggers_actions_ui/public/application/app.tsx index 5acb99c684a9..9786f5dcb949 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/app.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/app.tsx @@ -13,7 +13,7 @@ import { I18nProvider } from '@kbn/i18n/react'; import useObservable from 'react-use/lib/useObservable'; import { KibanaFeature } from '../../../features/common'; import { Section, routeToRuleDetails, legacyRouteToRuleDetails } from './constants'; -import { ActionTypeRegistryContract, AlertTypeRegistryContract } from '../types'; +import { ActionTypeRegistryContract, RuleTypeRegistryContract } from '../types'; import { ChartsPluginStart } from '../../../../../src/plugins/charts/public'; import { DataPublicPluginStart } from '../../../../../src/plugins/data/public'; import { PluginStartContract as AlertingStart } from '../../../alerting/public'; @@ -39,7 +39,7 @@ export interface TriggersAndActionsUiServices extends CoreStart { storage?: Storage; setBreadcrumbs: (crumbs: ChromeBreadcrumb[]) => void; actionTypeRegistry: ActionTypeRegistryContract; - alertTypeRegistry: AlertTypeRegistryContract; + ruleTypeRegistry: RuleTypeRegistryContract; history: ScopedHistory; kibanaFeatures: KibanaFeature[]; element: HTMLElement; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/alert_type_registry.mock.ts b/x-pack/plugins/triggers_actions_ui/public/application/rule_type_registry.mock.ts similarity index 61% rename from x-pack/plugins/triggers_actions_ui/public/application/alert_type_registry.mock.ts rename to x-pack/plugins/triggers_actions_ui/public/application/rule_type_registry.mock.ts index 5a07977dbef6..4bab4fb2d34b 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/alert_type_registry.mock.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/rule_type_registry.mock.ts @@ -5,10 +5,10 @@ * 2.0. */ -import { AlertTypeRegistryContract } from '../types'; +import { RuleTypeRegistryContract } from '../types'; -const createAlertTypeRegistryMock = () => { - const mocked: jest.Mocked = { +const createruleTypeRegistryMock = () => { + const mocked: jest.Mocked = { has: jest.fn(), register: jest.fn(), get: jest.fn(), @@ -17,6 +17,6 @@ const createAlertTypeRegistryMock = () => { return mocked; }; -export const alertTypeRegistryMock = { - create: createAlertTypeRegistryMock, +export const ruleTypeRegistryMock = { + create: createruleTypeRegistryMock, }; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx index 8d66bcf9bd29..5d4237e2176a 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx @@ -26,7 +26,7 @@ import { ALERTS_FEATURE_ID, } from '../../../../../../alerting/common'; import { useKibana } from '../../../../common/lib/kibana'; -import { alertTypeRegistryMock } from '../../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../../rule_type_registry.mock'; jest.mock('../../../../common/lib/kibana'); @@ -45,7 +45,7 @@ jest.mock('../../../lib/capabilities', () => ({ hasExecuteActionsCapability: jest.fn(() => true), })); const useKibanaMock = useKibana as jest.Mocked; -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const mockAlertApis = { muteAlert: jest.fn(), @@ -739,7 +739,7 @@ describe('edit button', () => { minimumLicenseRequired: 'basic', }, ]; - alertTypeRegistry.has.mockReturnValue(true); + ruleTypeRegistry.has.mockReturnValue(true); const alertTypeR: AlertTypeModel = { id: 'my-alert-type', iconClass: 'test', @@ -751,8 +751,8 @@ describe('edit button', () => { alertParamsExpression: jest.fn(), requiresAppContext: false, }; - alertTypeRegistry.get.mockReturnValue(alertTypeR); - useKibanaMock().services.alertTypeRegistry = alertTypeRegistry; + ruleTypeRegistry.get.mockReturnValue(alertTypeR); + useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry; it('should render an edit button when alert and actions are editable', () => { const alert = mockAlert({ diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx index 20692c45c086..1328ba6479f6 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx @@ -60,7 +60,7 @@ export const AlertDetails: React.FunctionComponent = ({ const history = useHistory(); const { application: { capabilities }, - alertTypeRegistry, + ruleTypeRegistry, actionTypeRegistry, setBreadcrumbs, chrome, @@ -92,8 +92,8 @@ export const AlertDetails: React.FunctionComponent = ({ // can the user save the alert canSaveAlert && // is this alert type editable from within Alerts Management - (alertTypeRegistry.has(alert.alertTypeId) - ? !alertTypeRegistry.get(alert.alertTypeId).requiresAppContext + (ruleTypeRegistry.has(alert.alertTypeId) + ? !ruleTypeRegistry.get(alert.alertTypeId).requiresAppContext : false); const alertActions = alert.actions; @@ -138,7 +138,7 @@ export const AlertDetails: React.FunctionComponent = ({ setEditFlyoutVisibility(false); }} actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} + ruleTypeRegistry={ruleTypeRegistry} onSave={setAlert} /> )} diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx index b40b7cbc1a38..514594ffb855 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx @@ -23,7 +23,7 @@ import { GenericValidationResult, ValidationResult, } from '../../../types'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { ReactWrapper } from 'enzyme'; import { ALERTS_FEATURE_ID } from '../../../../../alerting/common'; import { useKibana } from '../../../common/lib/kibana'; @@ -44,7 +44,7 @@ jest.mock('../../../common/lib/health_api', () => ({ })); const actionTypeRegistry = actionTypeRegistryMock.create(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const useKibanaMock = useKibana as jest.Mocked; const delay = (wait: number = 1000) => @@ -146,9 +146,9 @@ describe('alert_add', () => { }); actionTypeRegistry.get.mockReturnValueOnce(actionTypeModel); actionTypeRegistry.has.mockReturnValue(true); - alertTypeRegistry.list.mockReturnValue([alertType]); - alertTypeRegistry.get.mockReturnValue(alertType); - alertTypeRegistry.has.mockReturnValue(true); + ruleTypeRegistry.list.mockReturnValue([alertType]); + ruleTypeRegistry.get.mockReturnValue(alertType); + ruleTypeRegistry.has.mockReturnValue(true); actionTypeRegistry.list.mockReturnValue([actionTypeModel]); actionTypeRegistry.has.mockReturnValue(true); @@ -161,7 +161,7 @@ describe('alert_add', () => { return new Promise(() => {}); }} actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} + ruleTypeRegistry={ruleTypeRegistry} metadata={{ test: 'some value', fields: ['test'] }} /> ); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.tsx index 26f11fa3326a..5e4ca42523b3 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.tsx @@ -33,7 +33,7 @@ import { getAlertWithInvalidatedFields } from '../../lib/value_validators'; const AlertAdd = ({ consumer, - alertTypeRegistry, + ruleTypeRegistry, actionTypeRegistry, onClose, canChangeTrigger, @@ -137,7 +137,7 @@ const AlertAdd = ({ } }; - const alertType = alert.alertTypeId ? alertTypeRegistry.get(alert.alertTypeId) : null; + const alertType = alert.alertTypeId ? ruleTypeRegistry.get(alert.alertTypeId) : null; const { alertBaseErrors, alertErrors, alertParamsErrors } = getAlertErrors( alert as Alert, alertType @@ -202,7 +202,7 @@ const AlertAdd = ({ } )} actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} + ruleTypeRegistry={ruleTypeRegistry} metadata={metadata} /> diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.test.tsx index 4894cf165e27..1aea6c68acbf 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.test.tsx @@ -16,14 +16,14 @@ import { ConnectorValidationResult, GenericValidationResult, } from '../../../types'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { ReactWrapper } from 'enzyme'; import AlertEdit from './alert_edit'; import { useKibana } from '../../../common/lib/kibana'; import { ALERTS_FEATURE_ID } from '../../../../../alerting/common'; jest.mock('../../../common/lib/kibana'); const actionTypeRegistry = actionTypeRegistryMock.create(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const useKibanaMock = useKibana as jest.Mocked; jest.mock('../../lib/alert_api', () => ({ @@ -157,9 +157,9 @@ describe('alert_edit', () => { }; actionTypeRegistry.get.mockReturnValueOnce(actionTypeModel); actionTypeRegistry.has.mockReturnValue(true); - alertTypeRegistry.list.mockReturnValue([alertType]); - alertTypeRegistry.get.mockReturnValue(alertType); - alertTypeRegistry.has.mockReturnValue(true); + ruleTypeRegistry.list.mockReturnValue([alertType]); + ruleTypeRegistry.get.mockReturnValue(alertType); + ruleTypeRegistry.has.mockReturnValue(true); actionTypeRegistry.list.mockReturnValue([actionTypeModel]); actionTypeRegistry.has.mockReturnValue(true); @@ -171,7 +171,7 @@ describe('alert_edit', () => { return new Promise(() => {}); }} actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} + ruleTypeRegistry={ruleTypeRegistry} /> ); // Wait for active space to resolve before requesting the component to update diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.tsx index ad727566957d..101abfa071ed 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_edit.tsx @@ -40,7 +40,7 @@ export const AlertEdit = ({ onClose, reloadAlerts, onSave, - alertTypeRegistry, + ruleTypeRegistry, actionTypeRegistry, metadata, }: AlertEditProps) => { @@ -65,7 +65,7 @@ export const AlertEdit = ({ dispatch({ command: { type: 'setAlert' }, payload: { key: 'alert', value } }); }; - const alertType = alertTypeRegistry.get(alert.alertTypeId); + const alertType = ruleTypeRegistry.get(alert.alertTypeId); useEffect(() => { (async () => { @@ -168,7 +168,7 @@ export const AlertEdit = ({ dispatch={dispatch} errors={alertErrors} actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} + ruleTypeRegistry={ruleTypeRegistry} canChangeTrigger={false} setHasActionsDisabled={setHasActionsDisabled} setHasActionsWithBrokenConnector={setHasActionsWithBrokenConnector} diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx index 1bfb897c7399..e8353ee7f9bc 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx @@ -10,7 +10,7 @@ import { mountWithIntl, nextTick } from '@kbn/test/jest'; import { ReactWrapper } from 'enzyme'; import { act } from 'react-dom/test-utils'; import { actionTypeRegistryMock } from '../../action_type_registry.mock'; -import { alertTypeRegistryMock } from '../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { ValidationResult, Alert, @@ -24,7 +24,7 @@ import { ALERTS_FEATURE_ID, RecoveredActionGroup } from '../../../../../alerting import { useKibana } from '../../../common/lib/kibana'; const actionTypeRegistry = actionTypeRegistryMock.create(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); jest.mock('../../lib/alert_api', () => ({ loadAlertTypes: jest.fn(), })); @@ -159,12 +159,12 @@ describe('alert_form', () => { delete: true, }, }; - alertTypeRegistry.list.mockReturnValue([ + ruleTypeRegistry.list.mockReturnValue([ alertType, alertTypeNonEditable, disabledByLicenseAlertType, ]); - alertTypeRegistry.has.mockReturnValue(true); + ruleTypeRegistry.has.mockReturnValue(true); actionTypeRegistry.list.mockReturnValue([actionType]); actionTypeRegistry.has.mockReturnValue(true); actionTypeRegistry.get.mockReturnValue(actionType); @@ -189,7 +189,7 @@ describe('alert_form', () => { errors={{ name: [], interval: [], alertTypeId: [] }} operation="create" actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} + ruleTypeRegistry={ruleTypeRegistry} /> ); @@ -313,7 +313,7 @@ describe('alert_form', () => { delete: true, }, }; - alertTypeRegistry.list.mockReturnValue([ + ruleTypeRegistry.list.mockReturnValue([ { id: 'same-consumer-producer-alert-type', iconClass: 'test', @@ -337,7 +337,7 @@ describe('alert_form', () => { requiresAppContext: false, }, ]); - alertTypeRegistry.has.mockReturnValue(true); + ruleTypeRegistry.has.mockReturnValue(true); actionTypeRegistry.get.mockReturnValue(actionType); const initialAlert = ({ @@ -361,7 +361,7 @@ describe('alert_form', () => { errors={{ name: [], interval: [], alertTypeId: [] }} operation="create" actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} + ruleTypeRegistry={ruleTypeRegistry} /> ); @@ -394,9 +394,9 @@ describe('alert_form', () => { let wrapper: ReactWrapper; async function setup() { - alertTypeRegistry.list.mockReturnValue([alertType]); - alertTypeRegistry.get.mockReturnValue(alertType); - alertTypeRegistry.has.mockReturnValue(true); + ruleTypeRegistry.list.mockReturnValue([alertType]); + ruleTypeRegistry.get.mockReturnValue(alertType); + ruleTypeRegistry.has.mockReturnValue(true); actionTypeRegistry.list.mockReturnValue([actionType]); actionTypeRegistry.has.mockReturnValue(true); actionTypeRegistry.get.mockReturnValue(actionType); @@ -423,7 +423,7 @@ describe('alert_form', () => { errors={{ name: [], interval: [], alertTypeId: [] }} operation="create" actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} + ruleTypeRegistry={ruleTypeRegistry} /> ); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.tsx index 16878abc362d..cb245b5757ea 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.tsx @@ -51,7 +51,7 @@ import { AlertTypeIndex, AlertType, ValidationResult, - AlertTypeRegistryContract, + RuleTypeRegistryContract, ActionTypeRegistryContract, } from '../../../types'; import { getTimeOptions } from '../../../common/lib/get_time_options'; @@ -176,7 +176,7 @@ interface AlertFormProps> { alert: InitialAlert; dispatch: React.Dispatch; errors: IErrorObject; - alertTypeRegistry: AlertTypeRegistryContract; + ruleTypeRegistry: RuleTypeRegistryContract; actionTypeRegistry: ActionTypeRegistryContract; operation: string; canChangeTrigger?: boolean; // to hide Change trigger button @@ -193,7 +193,7 @@ export const AlertForm = ({ setHasActionsDisabled, setHasActionsWithBrokenConnector, operation, - alertTypeRegistry, + ruleTypeRegistry, actionTypeRegistry, metadata, }: AlertFormProps) => { @@ -285,11 +285,11 @@ export const AlertForm = ({ }, []); useEffect(() => { - setAlertTypeModel(alert.alertTypeId ? alertTypeRegistry.get(alert.alertTypeId) : null); + setAlertTypeModel(alert.alertTypeId ? ruleTypeRegistry.get(alert.alertTypeId) : null); if (alert.alertTypeId && alertTypesIndex && alertTypesIndex.has(alert.alertTypeId)) { setDefaultActionGroupId(alertTypesIndex.get(alert.alertTypeId)!.defaultActionGroupId); } - }, [alert, alert.alertTypeId, alertTypesIndex, alertTypeRegistry]); + }, [alert, alert.alertTypeId, alertTypesIndex, ruleTypeRegistry]); const setAlertProperty = useCallback( (key: Key, value: Alert[Key] | null) => { @@ -344,21 +344,21 @@ export const AlertForm = ({ ) ); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [alertTypeRegistry, availableAlertTypes, searchText, JSON.stringify(solutionsFilter)]); + }, [ruleTypeRegistry, availableAlertTypes, searchText, JSON.stringify(solutionsFilter)]); const getAvailableAlertTypes = (alertTypesResult: AlertType[]) => - alertTypeRegistry + ruleTypeRegistry .list() .reduce( ( arr: Array<{ alertType: AlertType; alertTypeModel: AlertTypeModel }>, - alertTypeRegistryItem: AlertTypeModel + ruleTypeRegistryItem: AlertTypeModel ) => { - const alertType = alertTypesResult.find((item) => alertTypeRegistryItem.id === item.id); + const alertType = alertTypesResult.find((item) => ruleTypeRegistryItem.id === item.id); if (alertType) { arr.push({ alertType, - alertTypeModel: alertTypeRegistryItem, + alertTypeModel: ruleTypeRegistryItem, }); } return arr; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx index 4be29e6d04f3..5a8a9000ea5b 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx @@ -11,7 +11,7 @@ import { mountWithIntl, nextTick } from '@kbn/test/jest'; import { ReactWrapper } from 'enzyme'; import { act } from 'react-dom/test-utils'; import { actionTypeRegistryMock } from '../../../action_type_registry.mock'; -import { alertTypeRegistryMock } from '../../../alert_type_registry.mock'; +import { ruleTypeRegistryMock } from '../../../rule_type_registry.mock'; import { AlertsList } from './alerts_list'; import { ValidationResult } from '../../../../types'; import { @@ -47,7 +47,7 @@ jest.mock('react-router-dom', () => ({ const { loadAlerts, loadAlertTypes } = jest.requireMock('../../../lib/alert_api'); const { loadActionTypes, loadAllActions } = jest.requireMock('../../../lib/action_connector_api'); const actionTypeRegistry = actionTypeRegistryMock.create(); -const alertTypeRegistry = alertTypeRegistryMock.create(); +const ruleTypeRegistry = ruleTypeRegistryMock.create(); const alertType = { id: 'test_alert_type', @@ -74,7 +74,7 @@ const alertTypeFromApi = { [ALERTS_FEATURE_ID]: { read: true, all: true }, }, }; -alertTypeRegistry.list.mockReturnValue([alertType]); +ruleTypeRegistry.list.mockReturnValue([alertType]); actionTypeRegistry.list.mockReturnValue([]); const useKibanaMock = useKibana as jest.Mocked; @@ -101,7 +101,7 @@ describe('alerts_list component empty', () => { loadAllActions.mockResolvedValue([]); // eslint-disable-next-line react-hooks/rules-of-hooks - useKibanaMock().services.alertTypeRegistry = alertTypeRegistry; + useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry; // eslint-disable-next-line react-hooks/rules-of-hooks useKibanaMock().services.actionTypeRegistry = actionTypeRegistry; @@ -284,9 +284,9 @@ describe('alerts_list component with items', () => { loadAlertTypes.mockResolvedValue([alertTypeFromApi]); loadAllActions.mockResolvedValue([]); - alertTypeRegistry.has.mockReturnValue(true); + ruleTypeRegistry.has.mockReturnValue(true); // eslint-disable-next-line react-hooks/rules-of-hooks - useKibanaMock().services.alertTypeRegistry = alertTypeRegistry; + useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry; // eslint-disable-next-line react-hooks/rules-of-hooks useKibanaMock().services.actionTypeRegistry = actionTypeRegistry; @@ -435,7 +435,7 @@ describe('alerts_list component empty with show only capability', () => { ]); loadAllActions.mockResolvedValue([]); // eslint-disable-next-line react-hooks/rules-of-hooks - useKibanaMock().services.alertTypeRegistry = alertTypeRegistry; + useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry; // eslint-disable-next-line react-hooks/rules-of-hooks useKibanaMock().services.actionTypeRegistry = actionTypeRegistry; @@ -522,9 +522,9 @@ describe('alerts_list with show only capability', () => { loadAlertTypes.mockResolvedValue([alertTypeFromApi]); loadAllActions.mockResolvedValue([]); - alertTypeRegistry.has.mockReturnValue(false); + ruleTypeRegistry.has.mockReturnValue(false); // eslint-disable-next-line react-hooks/rules-of-hooks - useKibanaMock().services.alertTypeRegistry = alertTypeRegistry; + useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry; // eslint-disable-next-line react-hooks/rules-of-hooks useKibanaMock().services.actionTypeRegistry = actionTypeRegistry; @@ -629,9 +629,9 @@ describe('alerts_list with disabled itmes', () => { ]); loadAllActions.mockResolvedValue([]); - alertTypeRegistry.has.mockReturnValue(false); + ruleTypeRegistry.has.mockReturnValue(false); // eslint-disable-next-line react-hooks/rules-of-hooks - useKibanaMock().services.alertTypeRegistry = alertTypeRegistry; + useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry; // eslint-disable-next-line react-hooks/rules-of-hooks useKibanaMock().services.actionTypeRegistry = actionTypeRegistry; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx index adf1a27d1ad6..3625dc07a118 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.tsx @@ -89,7 +89,7 @@ export const AlertsList: React.FunctionComponent = () => { http, notifications: { toasts }, application: { capabilities }, - alertTypeRegistry, + ruleTypeRegistry, actionTypeRegistry, kibanaFeatures, } = useKibana().services; @@ -889,7 +889,7 @@ export const AlertsList: React.FunctionComponent = () => { setAlertFlyoutVisibility(false); }} actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} + ruleTypeRegistry={ruleTypeRegistry} onSave={loadAlertsData} /> )} @@ -900,7 +900,7 @@ export const AlertsList: React.FunctionComponent = () => { setEditFlyoutVisibility(false); }} actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} + ruleTypeRegistry={ruleTypeRegistry} onSave={loadAlertsData} /> )} diff --git a/x-pack/plugins/triggers_actions_ui/public/application/type_registry.test.ts b/x-pack/plugins/triggers_actions_ui/public/application/type_registry.test.ts index ee561a65069e..f39bbc1d998a 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/type_registry.test.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/type_registry.test.ts @@ -57,16 +57,16 @@ beforeEach(() => jest.resetAllMocks()); describe('register()', () => { test('able to register alert types', () => { - const alertTypeRegistry = new TypeRegistry(); - alertTypeRegistry.register(getTestAlertType()); - expect(alertTypeRegistry.has('test-alet-type')).toEqual(true); + const ruleTypeRegistry = new TypeRegistry(); + ruleTypeRegistry.register(getTestAlertType()); + expect(ruleTypeRegistry.has('test-alet-type')).toEqual(true); }); test('throws error if alert type already registered', () => { - const alertTypeRegistry = new TypeRegistry(); - alertTypeRegistry.register(getTestAlertType('my-test-alert-type-1')); + const ruleTypeRegistry = new TypeRegistry(); + ruleTypeRegistry.register(getTestAlertType('my-test-alert-type-1')); expect(() => - alertTypeRegistry.register(getTestAlertType('my-test-alert-type-1')) + ruleTypeRegistry.register(getTestAlertType('my-test-alert-type-1')) ).toThrowErrorMatchingInlineSnapshot( `"Object type \\"my-test-alert-type-1\\" is already registered."` ); @@ -128,13 +128,13 @@ describe('list()', () => { describe('has()', () => { test('returns false for unregistered alert types', () => { - const alertTypeRegistry = new TypeRegistry(); - expect(alertTypeRegistry.has('my-alert-type')).toEqual(false); + const ruleTypeRegistry = new TypeRegistry(); + expect(ruleTypeRegistry.has('my-alert-type')).toEqual(false); }); test('returns true after registering an alert type', () => { - const alertTypeRegistry = new TypeRegistry(); - alertTypeRegistry.register(getTestAlertType()); - expect(alertTypeRegistry.has('test-alet-type')); + const ruleTypeRegistry = new TypeRegistry(); + ruleTypeRegistry.register(getTestAlertType()); + expect(ruleTypeRegistry.has('test-alet-type')); }); }); diff --git a/x-pack/plugins/triggers_actions_ui/public/common/lib/kibana/kibana_react.mock.ts b/x-pack/plugins/triggers_actions_ui/public/common/lib/kibana/kibana_react.mock.ts index d20eb6a5cfe3..a1a0184198df 100644 --- a/x-pack/plugins/triggers_actions_ui/public/common/lib/kibana/kibana_react.mock.ts +++ b/x-pack/plugins/triggers_actions_ui/public/common/lib/kibana/kibana_react.mock.ts @@ -12,18 +12,18 @@ import { dataPluginMock } from '../../../../../../../src/plugins/data/public/moc import { coreMock, scopedHistoryMock } from '../../../../../../../src/core/public/mocks'; import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; import { TriggersAndActionsUiServices } from '../../../application/app'; -import { AlertTypeRegistryContract, ActionTypeRegistryContract } from '../../../types'; +import { RuleTypeRegistryContract, ActionTypeRegistryContract } from '../../../types'; export const createStartServicesMock = (): TriggersAndActionsUiServices => { const core = coreMock.createStart(); return { ...core, - alertTypeRegistry: { + ruleTypeRegistry: { has: jest.fn(), register: jest.fn(), get: jest.fn(), list: jest.fn(), - } as AlertTypeRegistryContract, + } as RuleTypeRegistryContract, dataPlugin: jest.fn(), navigateToApp: jest.fn(), alerting: { diff --git a/x-pack/plugins/triggers_actions_ui/public/index.ts b/x-pack/plugins/triggers_actions_ui/public/index.ts index 134627929e4a..eedc5566ba1d 100644 --- a/x-pack/plugins/triggers_actions_ui/public/index.ts +++ b/x-pack/plugins/triggers_actions_ui/public/index.ts @@ -13,7 +13,7 @@ export type { AlertTypeModel, ActionType, ActionTypeRegistryContract, - AlertTypeRegistryContract, + RuleTypeRegistryContract, AlertTypeParamsExpressionProps, ValidationResult, ActionVariables, diff --git a/x-pack/plugins/triggers_actions_ui/public/mocks.ts b/x-pack/plugins/triggers_actions_ui/public/mocks.ts index dfc1cc88e15b..5da6d2ddbe8b 100644 --- a/x-pack/plugins/triggers_actions_ui/public/mocks.ts +++ b/x-pack/plugins/triggers_actions_ui/public/mocks.ts @@ -24,10 +24,10 @@ import { function createStartMock(): TriggersAndActionsUIPublicPluginStart { const actionTypeRegistry = new TypeRegistry(); - const alertTypeRegistry = new TypeRegistry(); + const ruleTypeRegistry = new TypeRegistry(); return { actionTypeRegistry, - alertTypeRegistry, + ruleTypeRegistry, getAddConnectorFlyout: (props: Omit) => { return getAddConnectorFlyoutLazy({ ...props, actionTypeRegistry }); }, @@ -37,20 +37,20 @@ function createStartMock(): TriggersAndActionsUIPublicPluginStart { actionTypeRegistry, }); }, - getAddAlertFlyout: (props: Omit) => { + getAddAlertFlyout: (props: Omit) => { return getAddAlertFlyoutLazy({ ...props, actionTypeRegistry, - alertTypeRegistry, + ruleTypeRegistry, }); }, getEditAlertFlyout: ( - props: Omit + props: Omit ) => { return getEditAlertFlyoutLazy({ ...props, actionTypeRegistry, - alertTypeRegistry, + ruleTypeRegistry, }); }, }; diff --git a/x-pack/plugins/triggers_actions_ui/public/plugin.ts b/x-pack/plugins/triggers_actions_ui/public/plugin.ts index 62daf2ad198f..7661eefba7f6 100644 --- a/x-pack/plugins/triggers_actions_ui/public/plugin.ts +++ b/x-pack/plugins/triggers_actions_ui/public/plugin.ts @@ -43,12 +43,12 @@ import type { export interface TriggersAndActionsUIPublicPluginSetup { actionTypeRegistry: TypeRegistry; - alertTypeRegistry: TypeRegistry>; + ruleTypeRegistry: TypeRegistry>; } export interface TriggersAndActionsUIPublicPluginStart { actionTypeRegistry: TypeRegistry; - alertTypeRegistry: TypeRegistry>; + ruleTypeRegistry: TypeRegistry>; getAddConnectorFlyout: ( props: Omit ) => ReactElement; @@ -56,10 +56,10 @@ export interface TriggersAndActionsUIPublicPluginStart { props: Omit ) => ReactElement; getAddAlertFlyout: ( - props: Omit + props: Omit ) => ReactElement; getEditAlertFlyout: ( - props: Omit + props: Omit ) => ReactElement; } @@ -86,16 +86,16 @@ export class Plugin PluginsStart > { private actionTypeRegistry: TypeRegistry; - private alertTypeRegistry: TypeRegistry; + private ruleTypeRegistry: TypeRegistry; constructor() { this.actionTypeRegistry = new TypeRegistry(); - this.alertTypeRegistry = new TypeRegistry(); + this.ruleTypeRegistry = new TypeRegistry(); } public setup(core: CoreSetup, plugins: PluginsSetup): TriggersAndActionsUIPublicPluginSetup { const actionTypeRegistry = this.actionTypeRegistry; - const alertTypeRegistry = this.alertTypeRegistry; + const ruleTypeRegistry = this.ruleTypeRegistry; const featureTitle = i18n.translate('xpack.triggersActionsUI.managementSection.displayName', { defaultMessage: 'Rules and Connectors', @@ -153,7 +153,7 @@ export class Plugin setBreadcrumbs: params.setBreadcrumbs, history: params.history, actionTypeRegistry, - alertTypeRegistry, + ruleTypeRegistry, kibanaFeatures, }); }, @@ -165,14 +165,14 @@ export class Plugin return { actionTypeRegistry: this.actionTypeRegistry, - alertTypeRegistry: this.alertTypeRegistry, + ruleTypeRegistry: this.ruleTypeRegistry, }; } public start(): TriggersAndActionsUIPublicPluginStart { return { actionTypeRegistry: this.actionTypeRegistry, - alertTypeRegistry: this.alertTypeRegistry, + ruleTypeRegistry: this.ruleTypeRegistry, getAddConnectorFlyout: (props: Omit) => { return getAddConnectorFlyoutLazy({ ...props, actionTypeRegistry: this.actionTypeRegistry }); }, @@ -183,21 +183,21 @@ export class Plugin }); }, getAddAlertFlyout: ( - props: Omit + props: Omit ) => { return getAddAlertFlyoutLazy({ ...props, actionTypeRegistry: this.actionTypeRegistry, - alertTypeRegistry: this.alertTypeRegistry, + ruleTypeRegistry: this.ruleTypeRegistry, }); }, getEditAlertFlyout: ( - props: Omit + props: Omit ) => { return getEditAlertFlyoutLazy({ ...props, actionTypeRegistry: this.actionTypeRegistry, - alertTypeRegistry: this.alertTypeRegistry, + ruleTypeRegistry: this.ruleTypeRegistry, }); }, }; diff --git a/x-pack/plugins/triggers_actions_ui/public/types.ts b/x-pack/plugins/triggers_actions_ui/public/types.ts index 5ddddcb73a84..b17d0493c449 100644 --- a/x-pack/plugins/triggers_actions_ui/public/types.ts +++ b/x-pack/plugins/triggers_actions_ui/public/types.ts @@ -66,7 +66,7 @@ export type ActionTypeRegistryContract< ActionConnector = unknown, ActionParams = unknown > = PublicMethodsOf>>; -export type AlertTypeRegistryContract = PublicMethodsOf>; +export type RuleTypeRegistryContract = PublicMethodsOf>; export interface ActionConnectorFieldsProps { action: TActionConnector; @@ -273,7 +273,7 @@ export interface ConnectorEditFlyoutProps { export interface AlertEditProps> { initialAlert: Alert; - alertTypeRegistry: AlertTypeRegistryContract; + ruleTypeRegistry: RuleTypeRegistryContract; actionTypeRegistry: ActionTypeRegistryContract; onClose: (reason: AlertFlyoutCloseReason) => void; /** @deprecated use `onSave` as a callback after an alert is saved*/ @@ -284,7 +284,7 @@ export interface AlertEditProps> { export interface AlertAddProps> { consumer: string; - alertTypeRegistry: AlertTypeRegistryContract; + ruleTypeRegistry: RuleTypeRegistryContract; actionTypeRegistry: ActionTypeRegistryContract; onClose: (reason: AlertFlyoutCloseReason) => void; alertTypeId?: string; diff --git a/x-pack/plugins/uptime/public/apps/plugin.ts b/x-pack/plugins/uptime/public/apps/plugin.ts index 45067c6018cc..e611363b4ab4 100644 --- a/x-pack/plugins/uptime/public/apps/plugin.ts +++ b/x-pack/plugins/uptime/public/apps/plugin.ts @@ -150,7 +150,7 @@ export class UptimePlugin }); if ( clientPluginsStart.triggersActionsUi && - !clientPluginsStart.triggersActionsUi.alertTypeRegistry.has(alertInitializer.id) + !clientPluginsStart.triggersActionsUi.ruleTypeRegistry.has(alertInitializer.id) ) { observabilityRuleTypeRegistry.register(alertInitializer); } @@ -163,9 +163,9 @@ export class UptimePlugin }); if ( clientPluginsStart.triggersActionsUi && - !clientPluginsStart.triggersActionsUi.alertTypeRegistry.has(alertInitializer.id) + !clientPluginsStart.triggersActionsUi.ruleTypeRegistry.has(alertInitializer.id) ) { - plugins.triggersActionsUi.alertTypeRegistry.register(alertInitializer); + plugins.triggersActionsUi.ruleTypeRegistry.register(alertInitializer); } }); }); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/create.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/create.ts index f481eaded4eb..1e85cb301197 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/create.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/create.ts @@ -418,7 +418,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) { expect(response.body).to.eql({ statusCode: 400, error: 'Bad Request', - message: 'Alert type "test.unregistered-alert-type" is not registered.', + message: 'Rule type "test.unregistered-alert-type" is not registered.', }); break; default: diff --git a/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/public/plugin.ts b/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/public/plugin.ts index fc51740e8290..ee33c78fefbe 100644 --- a/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/public/plugin.ts +++ b/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/public/plugin.ts @@ -27,7 +27,7 @@ export class AlertingFixturePlugin implements Plugin `/rule/${alert.id}` ); - triggersActionsUi.alertTypeRegistry.register({ + triggersActionsUi.ruleTypeRegistry.register({ id: 'test.always-firing', description: 'Always fires', iconClass: 'alert', @@ -39,7 +39,7 @@ export class AlertingFixturePlugin implements Plugin