Skip to content

Commit

Permalink
[ResponseOps] Adds uiSettingsClient to alerting framework services (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee authored Mar 2, 2022
1 parent c365e60 commit 08b8bb8
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Alert, AlertFactoryDoneUtils } from './alert';
import {
elasticsearchServiceMock,
savedObjectsClientMock,
uiSettingsServiceMock,
} from '../../../../src/core/server/mocks';
import { AlertInstanceContext, AlertInstanceState } from './types';

Expand Down Expand Up @@ -105,6 +106,7 @@ const createAlertServicesMock = <
done: jest.fn().mockReturnValue(alertFactoryMockDone),
},
savedObjectsClient: savedObjectsClientMock.create(),
uiSettingsClient: uiSettingsServiceMock.createClient(),
scopedClusterClient: elasticsearchServiceMock.createScopedClusterClient(),
shouldWriteAlerts: () => true,
shouldStopExecution: () => true,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ export class AlertingPlugin {
taskRunnerFactory.initialize({
logger,
savedObjects: core.savedObjects,
uiSettings: core.uiSettings,
elasticsearch: core.elasticsearch,
getRulesClientWithRequest,
spaceIdToNamespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
executionContextServiceMock,
savedObjectsServiceMock,
elasticsearchServiceMock,
uiSettingsServiceMock,
} from '../../../../../src/core/server/mocks';
import { PluginStartContract as ActionsPluginStart } from '../../../actions/server';
import { actionsMock, actionsClientMock } from '../../../actions/server/mocks';
Expand Down Expand Up @@ -95,6 +96,7 @@ describe('Task Runner', () => {
const ruleTypeRegistry = ruleTypeRegistryMock.create();
const savedObjectsService = savedObjectsServiceMock.createInternalStartContract();
const elasticsearchService = elasticsearchServiceMock.createInternalStart();
const uiSettingsService = uiSettingsServiceMock.createStartContract();

type TaskRunnerFactoryInitializerParamsType = jest.Mocked<TaskRunnerContext> & {
actionsPlugin: jest.Mocked<ActionsPluginStart>;
Expand All @@ -106,6 +108,7 @@ describe('Task Runner', () => {

const taskRunnerFactoryInitializerParams: TaskRunnerFactoryInitializerParamsType = {
savedObjects: savedObjectsService,
uiSettings: uiSettingsService,
elasticsearch: elasticsearchService,
actionsPlugin: actionsMock.createStart(),
getRulesClientWithRequest: jest.fn().mockReturnValue(rulesClient),
Expand Down
9 changes: 6 additions & 3 deletions x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,17 @@ export class TaskRunner<
}] namespace`,
};

const savedObjectsClient = this.context.savedObjects.getScopedClient(fakeRequest, {
includedHiddenTypes: ['alert', 'action'],
});

updatedRuleTypeState = await this.context.executionContext.withContext(ctx, () =>
this.ruleType.executor({
alertId: ruleId,
executionId: this.executionId,
services: {
savedObjectsClient: this.context.savedObjects.getScopedClient(fakeRequest, {
includedHiddenTypes: ['alert', 'action'],
}),
savedObjectsClient,
uiSettingsClient: this.context.uiSettings.asScopedToClient(savedObjectsClient),
scopedClusterClient: wrappedScopedClusterClient.client(),
alertFactory: createAlertFactory<
InstanceState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
executionContextServiceMock,
savedObjectsServiceMock,
elasticsearchServiceMock,
uiSettingsServiceMock,
} from '../../../../../src/core/server/mocks';
import { PluginStartContract as ActionsPluginStart } from '../../../actions/server';
import { actionsMock, actionsClientMock } from '../../../actions/server/mocks';
Expand Down Expand Up @@ -94,6 +95,7 @@ describe('Task Runner Cancel', () => {
const ruleTypeRegistry = ruleTypeRegistryMock.create();
const savedObjectsService = savedObjectsServiceMock.createInternalStartContract();
const elasticsearchService = elasticsearchServiceMock.createInternalStart();
const uiSettingsService = uiSettingsServiceMock.createStartContract();

type TaskRunnerFactoryInitializerParamsType = jest.Mocked<TaskRunnerContext> & {
actionsPlugin: jest.Mocked<ActionsPluginStart>;
Expand All @@ -103,6 +105,7 @@ describe('Task Runner Cancel', () => {

const taskRunnerFactoryInitializerParams: TaskRunnerFactoryInitializerParamsType = {
savedObjects: savedObjectsService,
uiSettings: uiSettingsService,
elasticsearch: elasticsearchService,
actionsPlugin: actionsMock.createStart(),
getRulesClientWithRequest: jest.fn().mockReturnValue(rulesClient),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
httpServiceMock,
savedObjectsServiceMock,
elasticsearchServiceMock,
uiSettingsServiceMock,
} from '../../../../../src/core/server/mocks';
import { actionsMock } from '../../../actions/server/mocks';
import { rulesClientMock } from '../mocks';
Expand All @@ -28,6 +29,7 @@ const executionContext = executionContextServiceMock.createSetupContract();
const mockUsageCountersSetup = usageCountersServiceMock.createSetupContract();
const mockUsageCounter = mockUsageCountersSetup.createUsageCounter('test');
const savedObjectsService = savedObjectsServiceMock.createInternalStartContract();
const uiSettingsService = uiSettingsServiceMock.createStartContract();
const elasticsearchService = elasticsearchServiceMock.createInternalStart();
const ruleType: UntypedNormalizedRuleType = {
id: 'test',
Expand Down Expand Up @@ -77,6 +79,7 @@ describe('Task Runner Factory', () => {

const taskRunnerFactoryInitializerParams: jest.Mocked<TaskRunnerContext> = {
savedObjects: savedObjectsService,
uiSettings: uiSettingsService,
elasticsearch: elasticsearchService,
getRulesClientWithRequest: jest.fn().mockReturnValue(rulesClient),
actionsPlugin: actionsMock.createStart(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
ExecutionContextStart,
SavedObjectsServiceStart,
ElasticsearchServiceStart,
UiSettingsServiceStart,
} from '../../../../../src/core/server';
import { RunContext } from '../../../task_manager/server';
import { EncryptedSavedObjectsClient } from '../../../encrypted_saved_objects/server';
Expand All @@ -35,6 +36,7 @@ import { NormalizedRuleType } from '../rule_type_registry';
export interface TaskRunnerContext {
logger: Logger;
savedObjects: SavedObjectsServiceStart;
uiSettings: UiSettingsServiceStart;
elasticsearch: ElasticsearchServiceStart;
getRulesClientWithRequest(request: KibanaRequest): PublicMethodsOf<RulesClient>;
actionsPlugin: ActionsPluginStartContract;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
RequestHandlerContext,
SavedObjectReference,
ElasticsearchClient,
IUiSettingsClient,
} from 'src/core/server';
import type { PublicMethodsOf } from '@kbn/utility-types';
import { AlertFactoryDoneUtils, PublicAlert } from './alert';
Expand Down Expand Up @@ -78,6 +79,7 @@ export interface AlertServices<
ActionGroupIds extends string = never
> {
savedObjectsClient: SavedObjectsClientContract;
uiSettingsClient: IUiSettingsClient;
scopedClusterClient: IScopedClusterClient;
alertFactory: {
create: (id: string) => PublicAlert<InstanceState, InstanceContext, ActionGroupIds>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function createRule(shouldWriteAlerts: boolean = true) {
services: {
alertFactory,
savedObjectsClient: {} as any,
uiSettingsClient: {} as any,
scopedClusterClient: {} as any,
shouldWriteAlerts: () => shouldWriteAlerts,
shouldStopExecution: () => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {
elasticsearchServiceMock,
savedObjectsClientMock,
uiSettingsServiceMock,
} from '../../../../../src/core/server/mocks';
import {
AlertExecutorOptions,
Expand Down Expand Up @@ -69,6 +70,7 @@ export const createDefaultAlertExecutorOptions = <
services: {
alertFactory: alertsMock.createAlertServices<InstanceState, InstanceContext>().alertFactory,
savedObjectsClient: savedObjectsClientMock.create(),
uiSettingsClient: uiSettingsServiceMock.createClient(),
scopedClusterClient: elasticsearchServiceMock.createScopedClusterClient(),
shouldWriteAlerts: () => shouldWriteAlerts,
shouldStopExecution: () => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export const previewRulesRoute = async (
}),
savedObjectsClient: context.core.savedObjects.client,
scopedClusterClient: context.core.elasticsearch.client,
uiSettingsClient: context.core.uiSettings.client,
},
spaceId,
startedAt: startedAt.toDate(),
Expand Down

0 comments on commit 08b8bb8

Please sign in to comment.