Skip to content
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
4 changes: 2 additions & 2 deletions x-pack/plugins/alerting/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ const createRuleExecutorServicesMock = <
shouldWriteAlerts: () => true,
shouldStopExecution: () => true,
search: createAbortableSearchServiceMock(),
searchSourceClient: searchSourceCommonMock,
getSearchSourceClient: jest.fn().mockResolvedValue(searchSourceCommonMock),
ruleMonitoringService: createRuleMonitoringServiceMock(),
share: createShareStartMock(),
dataViews: dataViewPluginMocks.createStartContract(),
getDataViews: jest.fn().mockResolvedValue(dataViewPluginMocks.createStartContract()),
};
};
export type RuleExecutorServicesMock = ReturnType<typeof createRuleExecutorServicesMock>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class AdHocTaskRunner implements CancellableTask {
taskInstance: this.taskInstance,
});

const executorServices = await getExecutorServices({
const executorServices = getExecutorServices({
context: this.context,
fakeRequest,
abortController: this.searchAbortController,
Expand Down
41 changes: 21 additions & 20 deletions x-pack/plugins/alerting/server/task_runner/get_executor_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ interface GetExecutorServicesOpts {
}

export interface ExecutorServices {
dataViews: DataViewsContract;
ruleMonitoringService: PublicRuleMonitoringService;
ruleResultService: PublicRuleResultService;
savedObjectsClient: SavedObjectsClientContract;
uiSettingsClient: IUiSettingsClient;
wrappedScopedClusterClient: WrappedScopedClusterClient;
wrappedSearchSourceClient: WrappedSearchSourceClient;
getDataViews: () => Promise<DataViewsContract>;
getWrappedSearchSourceClient: () => Promise<WrappedSearchSourceClient>;
}

export const getExecutorServices = async (opts: GetExecutorServicesOpts) => {
export const getExecutorServices = (opts: GetExecutorServicesOpts) => {
const { context, abortController, fakeRequest, logger, ruleData, ruleTaskTimeout } = opts;

const wrappedClientOptions = {
Expand All @@ -66,34 +66,35 @@ export const getExecutorServices = async (opts: GetExecutorServicesOpts) => {
scopedClusterClient,
});

const searchSourceClient = await withAlertingSpan('alerting:get-search-source-client', () =>
context.data.search.searchSource.asScoped(fakeRequest)
);
const wrappedSearchSourceClient = wrapSearchSourceClient({
...wrappedClientOptions,
searchSourceClient,
});

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

const dataViews = await await withAlertingSpan('alerting:get-data-views-factory', () =>
context.dataViews.dataViewsServiceFactory(
savedObjectsClient,
scopedClusterClient.asInternalUser
)
);

const uiSettingsClient = context.uiSettings.asScopedToClient(savedObjectsClient);

return {
dataViews,
ruleMonitoringService: opts.ruleMonitoringService.getLastRunMetricsSetters(),
ruleResultService: opts.ruleResultService.getLastRunSetters(),
savedObjectsClient,
uiSettingsClient,
wrappedScopedClusterClient,
wrappedSearchSourceClient,
getDataViews: async () => {
const dataViews = await withAlertingSpan('alerting:get-data-views-factory', () =>
context.dataViews.dataViewsServiceFactory(
savedObjectsClient,
scopedClusterClient.asInternalUser
)
);
return dataViews;
},
getWrappedSearchSourceClient: async () => {
const searchSourceClient = await withAlertingSpan('alerting:get-search-source-client', () =>
context.data.search.searchSource.asScoped(fakeRequest)
);
return wrapSearchSourceClient({
...wrappedClientOptions,
searchSourceClient,
});
},
};
};
Loading