Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Alerting] Renamed Alerting framework AlertsClient to RulesClient according to the new terminology. #106382

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions api_docs/alerting.json
Original file line number Diff line number Diff line change
Expand Up @@ -669,19 +669,19 @@
"children": [
{
"parentPluginId": "alerting",
"id": "def-server.AlertingApiRequestHandlerContext.getAlertsClient",
"id": "def-server.AlertingApiRequestHandlerContext.getRulesClient",
"type": "Function",
"tags": [],
"label": "getAlertsClient",
"label": "getRulesClient",
"description": [],
"signature": [
"() => ",
{
"pluginId": "alerting",
"scope": "server",
"docId": "kibAlertingPluginApi",
"section": "def-server.AlertsClient",
"text": "AlertsClient"
"section": "def-server.RulesClient",
"text": "RulesClient"
}
],
"source": {
Expand Down Expand Up @@ -1170,7 +1170,7 @@
"<Params>"
],
"source": {
"path": "x-pack/plugins/alerting/server/alerts_client/alerts_client.ts",
"path": "x-pack/plugins/alerting/server/rules_client/rules_client.ts",
"lineNumber": 140
},
"deprecated": false,
Expand All @@ -1183,7 +1183,7 @@
"label": "page",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/alerts_client/alerts_client.ts",
"path": "x-pack/plugins/alerting/server/rules_client/rules_client.ts",
"lineNumber": 141
},
"deprecated": false
Expand All @@ -1196,7 +1196,7 @@
"label": "perPage",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/alerts_client/alerts_client.ts",
"path": "x-pack/plugins/alerting/server/rules_client/rules_client.ts",
"lineNumber": 142
},
"deprecated": false
Expand All @@ -1209,7 +1209,7 @@
"label": "total",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/alerts_client/alerts_client.ts",
"path": "x-pack/plugins/alerting/server/rules_client/rules_client.ts",
"lineNumber": 143
},
"deprecated": false
Expand All @@ -1233,7 +1233,7 @@
"<Params>, \"enabled\" | \"id\" | \"name\" | \"params\" | \"actions\" | \"tags\" | \"alertTypeId\" | \"consumer\" | \"schedule\" | \"scheduledTaskId\" | \"createdBy\" | \"updatedBy\" | \"createdAt\" | \"updatedAt\" | \"apiKeyOwner\" | \"throttle\" | \"notifyWhen\" | \"muteAll\" | \"mutedInstanceIds\" | \"executionStatus\">[]"
],
"source": {
"path": "x-pack/plugins/alerting/server/alerts_client/alerts_client.ts",
"path": "x-pack/plugins/alerting/server/rules_client/rules_client.ts",
"lineNumber": 144
},
"deprecated": false
Expand Down Expand Up @@ -1343,10 +1343,10 @@
},
{
"parentPluginId": "alerting",
"id": "def-server.PluginStartContract.getAlertsClientWithRequest",
"id": "def-server.PluginStartContract.getRulesClientWithRequest",
"type": "Function",
"tags": [],
"label": "getAlertsClientWithRequest",
"label": "getRulesClientWithRequest",
"description": [],
"signature": [
"(request: ",
Expand All @@ -1362,8 +1362,8 @@
"pluginId": "alerting",
"scope": "server",
"docId": "kibAlertingPluginApi",
"section": "def-server.AlertsClient",
"text": "AlertsClient"
"section": "def-server.RulesClient",
"text": "RulesClient"
},
", \"get\" | \"delete\" | \"create\" | \"find\" | \"update\" | \"aggregate\" | \"enable\" | \"disable\" | \"muteAll\" | \"getAlertState\" | \"getAlertInstanceSummary\" | \"updateApiKey\" | \"unmuteAll\" | \"muteInstance\" | \"unmuteInstance\" | \"listAlertTypes\">"
],
Expand All @@ -1375,7 +1375,7 @@
"children": [
{
"parentPluginId": "alerting",
"id": "def-server.PluginStartContract.getAlertsClientWithRequest.$1",
"id": "def-server.PluginStartContract.getRulesClientWithRequest.$1",
"type": "Object",
"tags": [],
"label": "request",
Expand Down Expand Up @@ -1571,10 +1571,10 @@
},
{
"parentPluginId": "alerting",
"id": "def-server.AlertsClient",
"id": "def-server.RulesClient",
"type": "Type",
"tags": [],
"label": "AlertsClient",
"label": "RulesClient",
"description": [],
"signature": [
"{ get: <Params extends Record<string, unknown> = never>({ id, }: { id: string; }) => Promise<Pick<",
Expand Down
4 changes: 2 additions & 2 deletions api_docs/deprecations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ warning: This document is auto-generated and is meant to be viewed inside our ex
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [audit_logger.ts#L8](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/authorization/audit_logger.ts#L8) | - |
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [audit_logger.ts#L21](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/authorization/audit_logger.ts#L21) | - |
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [audit_logger.ts#L23](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/authorization/audit_logger.ts#L23) | - |
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [alerts_client_factory.test.ts#L23](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/alerts_client_factory.test.ts#L23) | - |
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [alerts_client_factory.test.ts#L98](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/alerts_client_factory.test.ts#L98) | - |
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [rules_client_factory.test.ts#L23](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/rules_client_factory.test.ts#L23) | - |
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [rules_client_factory.test.ts#L98](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/rules_client_factory.test.ts#L98) | - |



Expand Down
4 changes: 2 additions & 2 deletions api_docs/security.json
Original file line number Diff line number Diff line change
Expand Up @@ -1739,14 +1739,14 @@
{
"plugin": "alerting",
"link": {
"path": "x-pack/plugins/alerting/server/alerts_client_factory.test.ts",
"path": "x-pack/plugins/alerting/server/rules_client_factory.test.ts",
"lineNumber": 23
}
},
{
"plugin": "alerting",
"link": {
"path": "x-pack/plugins/alerting/server/alerts_client_factory.test.ts",
"path": "x-pack/plugins/alerting/server/rules_client_factory.test.ts",
"lineNumber": 98
}
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ Finally, all users, whether they're granted any role or not, are privileged to c

- `listAlertTypes`, but the output is limited to displaying the rule types the user is privileged to `get`.

Attempting to execute any operation the user isn't privileged to execute will result in an Authorization error thrown by the AlertsClient.
Attempting to execute any operation the user isn't privileged to execute will result in an Authorization error thrown by the RulesClient.

## Alert Navigation

Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/alerting/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { AlertsClient as AlertsClientClass } from './alerts_client';
import { RulesClient as RulesClientClass } from './rules_client';
import { PluginConfigDescriptor, PluginInitializerContext } from '../../../../src/core/server';
import { AlertingPlugin } from './plugin';
import { configSchema } from './config';
import { AlertsConfigType } from './types';

export type AlertsClient = PublicMethodsOf<AlertsClientClass>;
export type RulesClient = PublicMethodsOf<RulesClientClass>;

export type {
AlertType,
Expand All @@ -32,7 +32,7 @@ export type {
} from './types';
export { DEFAULT_MAX_EPHEMERAL_ACTIONS_PER_ALERT } from './config';
export { PluginSetupContract, PluginStartContract } from './plugin';
export { FindResult } from './alerts_client';
export { FindResult } from './rules_client';
export { PublicAlertInstance as AlertInstance } from './alert_instance';
export { parseDuration } from './lib';
export { getEsErrorMessage } from './lib/errors';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
TaskManagerSetupContract,
TaskManagerStartContract,
} from '../../../task_manager/server';
import { InvalidateAPIKeyResult } from '../alerts_client';
import { InvalidateAPIKeyResult } from '../rules_client';
import { AlertsConfig } from '../config';
import { timePeriodBeforeDate } from '../lib/get_cadence';
import { AlertingPluginsStart } from '../plugin';
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/alerting/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { alertsClientMock } from './alerts_client.mock';
import { rulesClientMock } from './rules_client.mock';
import { PluginSetupContract, PluginStartContract } from './plugin';
import { AlertInstance } from './alert_instance';
import {
Expand All @@ -14,7 +14,7 @@ import {
} from '../../../../src/core/server/mocks';
import { AlertInstanceContext, AlertInstanceState } from './types';

export { alertsClientMock };
export { rulesClientMock };

const createSetupMock = () => {
const mock: jest.Mocked<PluginSetupContract> = {
Expand All @@ -27,7 +27,7 @@ const createStartMock = () => {
const mock: jest.Mocked<PluginStartContract> = {
listTypes: jest.fn(),
getAlertingAuthorizationWithRequest: jest.fn(),
getAlertsClientWithRequest: jest.fn().mockResolvedValue(alertsClientMock.create()),
getRulesClientWithRequest: jest.fn().mockResolvedValue(rulesClientMock.create()),
getFrameworkHealth: jest.fn(),
};
return mock;
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/alerting/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('Alerting Plugin', () => {
});

describe('start()', () => {
describe('getAlertsClientWithRequest()', () => {
describe('getRulesClientWithRequest()', () => {
it('throws error when encryptedSavedObjects plugin is missing encryption key', async () => {
const context = coreMock.createPluginInitializerContext<AlertsConfig>({
healthCheck: {
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('Alerting Plugin', () => {

expect(encryptedSavedObjectsSetup.canEncrypt).toEqual(false);
expect(() =>
startContract.getAlertsClientWithRequest({} as KibanaRequest)
startContract.getRulesClientWithRequest({} as KibanaRequest)
).toThrowErrorMatchingInlineSnapshot(
`"Unable to create alerts client because the Encrypted Saved Objects plugin is missing encryption key. Please set xpack.encryptedSavedObjects.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command."`
);
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('Alerting Plugin', () => {
},
getSavedObjectsClient: jest.fn(),
} as unknown) as KibanaRequest;
startContract.getAlertsClientWithRequest(fakeRequest);
startContract.getRulesClientWithRequest(fakeRequest);
});
});

Expand Down
30 changes: 15 additions & 15 deletions x-pack/plugins/alerting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {
} from '../../encrypted_saved_objects/server';
import { TaskManagerSetupContract, TaskManagerStartContract } from '../../task_manager/server';
import { SpacesPluginStart } from '../../spaces/server';
import { AlertsClient } from './alerts_client';
import { RulesClient } from './rules_client';
import { AlertTypeRegistry } from './alert_type_registry';
import { TaskRunnerFactory } from './task_runner';
import { AlertsClientFactory } from './alerts_client_factory';
import { RulesClientFactory } from './rules_client_factory';
import { ILicenseState, LicenseState } from './lib/license_state';
import {
KibanaRequest,
Expand Down Expand Up @@ -108,7 +108,7 @@ export interface PluginSetupContract {

export interface PluginStartContract {
listTypes: AlertTypeRegistry['list'];
getAlertsClientWithRequest(request: KibanaRequest): PublicMethodsOf<AlertsClient>;
getRulesClientWithRequest(request: KibanaRequest): PublicMethodsOf<RulesClient>;
getAlertingAuthorizationWithRequest(
request: KibanaRequest
): PublicMethodsOf<AlertingAuthorization>;
Expand Down Expand Up @@ -144,7 +144,7 @@ export class AlertingPlugin {
private licenseState: ILicenseState | null = null;
private isESOCanEncrypt?: boolean;
private security?: SecurityPluginSetup;
private readonly alertsClientFactory: AlertsClientFactory;
private readonly rulesClientFactory: RulesClientFactory;
private readonly alertingAuthorizationClientFactory: AlertingAuthorizationClientFactory;
private readonly telemetryLogger: Logger;
private readonly kibanaVersion: PluginInitializerContext['env']['packageInfo']['version'];
Expand All @@ -157,7 +157,7 @@ export class AlertingPlugin {
this.config = initializerContext.config.create<AlertsConfig>().pipe(first()).toPromise();
this.logger = initializerContext.logger.get();
this.taskRunnerFactory = new TaskRunnerFactory();
this.alertsClientFactory = new AlertsClientFactory();
this.rulesClientFactory = new RulesClientFactory();
this.alertingAuthorizationClientFactory = new AlertingAuthorizationClientFactory();
this.telemetryLogger = initializerContext.logger.get('usage');
this.kibanaIndexConfig = initializerContext.config.legacy.globalConfig$;
Expand Down Expand Up @@ -310,7 +310,7 @@ export class AlertingPlugin {
logger,
taskRunnerFactory,
alertTypeRegistry,
alertsClientFactory,
rulesClientFactory,
alertingAuthorizationClientFactory,
security,
licenseState,
Expand Down Expand Up @@ -338,7 +338,7 @@ export class AlertingPlugin {
features: plugins.features,
});

alertsClientFactory.initialize({
rulesClientFactory.initialize({
alertTypeRegistry: alertTypeRegistry!,
logger,
taskManager: plugins.taskManager,
Expand All @@ -355,13 +355,13 @@ export class AlertingPlugin {
authorization: alertingAuthorizationClientFactory,
});

const getAlertsClientWithRequest = (request: KibanaRequest) => {
const getRulesClientWithRequest = (request: KibanaRequest) => {
if (isESOCanEncrypt !== true) {
throw new Error(
`Unable to create alerts client because the Encrypted Saved Objects plugin is missing encryption key. Please set xpack.encryptedSavedObjects.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command.`
);
}
return alertsClientFactory!.create(request, core.savedObjects);
return rulesClientFactory!.create(request, core.savedObjects);
};

const getAlertingAuthorizationWithRequest = (request: KibanaRequest) => {
Expand All @@ -371,7 +371,7 @@ export class AlertingPlugin {
taskRunnerFactory.initialize({
logger,
getServices: this.getServicesFactory(core.savedObjects, core.elasticsearch),
getAlertsClientWithRequest,
getRulesClientWithRequest,
spaceIdToNamespace,
actionsPlugin: plugins.actions,
encryptedSavedObjectsClient,
Expand All @@ -385,7 +385,7 @@ export class AlertingPlugin {
});

this.eventLogService!.registerSavedObjectProvider('alert', (request) => {
const client = getAlertsClientWithRequest(request);
const client = getRulesClientWithRequest(request);
return (objects?: SavedObjectsBulkGetObject[]) =>
objects
? Promise.all(objects.map(async (objectItem) => await client.get({ id: objectItem.id })))
Expand All @@ -400,7 +400,7 @@ export class AlertingPlugin {
return {
listTypes: alertTypeRegistry!.list.bind(this.alertTypeRegistry!),
getAlertingAuthorizationWithRequest,
getAlertsClientWithRequest,
getRulesClientWithRequest,
getFrameworkHealth: async () =>
await getHealth(core.savedObjects.createInternalRepository(['alert'])),
};
Expand All @@ -409,12 +409,12 @@ export class AlertingPlugin {
private createRouteHandlerContext = (
core: CoreSetup<AlertingPluginsStart, unknown>
): IContextProvider<AlertingRequestHandlerContext, 'alerting'> => {
const { alertTypeRegistry, alertsClientFactory } = this;
const { alertTypeRegistry, rulesClientFactory } = this;
return async function alertsRouteHandlerContext(context, request) {
const [{ savedObjects }] = await core.getStartServices();
return {
getAlertsClient: () => {
return alertsClientFactory!.create(request, savedObjects);
getRulesClient: () => {
return rulesClientFactory!.create(request, savedObjects);
},
listTypes: alertTypeRegistry!.list.bind(alertTypeRegistry!),
getFrameworkHealth: async () =>
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/alerting/server/routes/_mock_handler_arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import { KibanaRequest, KibanaResponseFactory } from 'kibana/server';
import { identity } from 'lodash';
import type { MethodKeysOf } from '@kbn/utility-types';
import { httpServerMock } from '../../../../../src/core/server/mocks';
import { alertsClientMock, AlertsClientMock } from '../alerts_client.mock';
import { rulesClientMock, RulesClientMock } from '../rules_client.mock';
import { AlertsHealth, AlertType } from '../../common';
import type { AlertingRequestHandlerContext } from '../types';

export function mockHandlerArguments(
{
alertsClient = alertsClientMock.create(),
rulesClient = rulesClientMock.create(),
listTypes: listTypesRes = [],
getFrameworkHealth,
areApiKeysEnabled,
}: {
alertsClient?: AlertsClientMock;
rulesClient?: RulesClientMock;
listTypes?: AlertType[];
getFrameworkHealth?: jest.MockInstance<Promise<AlertsHealth>, []> &
(() => Promise<AlertsHealth>);
Expand All @@ -38,8 +38,8 @@ export function mockHandlerArguments(
({
alerting: {
listTypes,
getAlertsClient() {
return alertsClient || alertsClientMock.create();
getRulesClient() {
return rulesClient || rulesClientMock.create();
},
getFrameworkHealth,
areApiKeysEnabled: areApiKeysEnabled ? areApiKeysEnabled : () => Promise.resolve(true),
Expand Down
Loading