diff --git a/x-pack/legacy/plugins/oss_telemetry/index.d.ts b/x-pack/legacy/plugins/oss_telemetry/index.d.ts deleted file mode 100644 index 1b592dabf2053..0000000000000 --- a/x-pack/legacy/plugins/oss_telemetry/index.d.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -export interface VisState { - type: string; -} - -export interface Visualization { - visState: string; -} - -export interface SavedObjectDoc { - _id: string; - _source: { - visualization: Visualization; - type: string; - }; -} - -export interface ESQueryResponse { - hits: { - hits: SavedObjectDoc[]; - }; -} - -export interface TaskInstance { - state: { - runs: number; - stats: any; - }; - error?: any; -} - -export interface HapiServer { - plugins: { - xpack_main: any; - elasticsearch: { - getCluster: ( - cluster: string - ) => { - callWithInternalUser: () => Promise; - }; - }; - task_manager: { - registerTaskDefinitions: (opts: any) => void; - ensureScheduled: (opts: any) => Promise; - fetch: ( - opts: any - ) => Promise<{ - docs: TaskInstance[]; - }>; - }; - }; - config: () => { - get: (prop: string) => any; - }; - log: (context: string[], message: string) => void; -} diff --git a/x-pack/legacy/plugins/oss_telemetry/index.js b/x-pack/legacy/plugins/oss_telemetry/index.js deleted file mode 100644 index f86baef020aa2..0000000000000 --- a/x-pack/legacy/plugins/oss_telemetry/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { registerCollectors } from './server/lib/collectors'; -import { registerTasks, scheduleTasks } from './server/lib/tasks'; -import { PLUGIN_ID } from './constants'; - -export const ossTelemetry = (kibana) => { - return new kibana.Plugin({ - id: PLUGIN_ID, - require: ['elasticsearch', 'xpack_main'], - configPrefix: 'xpack.oss_telemetry', - - init(server) { - const { usageCollection } = server.newPlatform.setup.plugins; - registerCollectors(usageCollection, server); - registerTasks(server); - scheduleTasks(server); - } - }); -}; diff --git a/x-pack/legacy/plugins/oss_telemetry/index.ts b/x-pack/legacy/plugins/oss_telemetry/index.ts new file mode 100644 index 0000000000000..8b16c7cf13cad --- /dev/null +++ b/x-pack/legacy/plugins/oss_telemetry/index.ts @@ -0,0 +1,41 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { Logger, PluginInitializerContext } from 'kibana/server'; +import { PLUGIN_ID } from './constants'; +import { OssTelemetryPlugin } from './server/plugin'; +import { LegacyPluginInitializer } from '../../../../src/legacy/plugin_discovery/types'; + +export const ossTelemetry: LegacyPluginInitializer = kibana => { + return new kibana.Plugin({ + id: PLUGIN_ID, + require: ['elasticsearch', 'xpack_main'], + configPrefix: 'xpack.oss_telemetry', + + init(server) { + const plugin = new OssTelemetryPlugin({ + logger: { + get: () => + ({ + info: (message: string) => server.log(['info', 'task_manager'], message), + debug: (message: string) => server.log(['debug', 'task_manager'], message), + warn: (message: string) => server.log(['warn', 'task_manager'], message), + error: (message: string) => server.log(['error', 'task_manager'], message), + } as Logger), + }, + } as PluginInitializerContext); + plugin.setup(server.newPlatform.setup.core, { + usageCollection: server.newPlatform.setup.plugins.usageCollection, + taskManager: server.plugins.task_manager, + __LEGACY: { + config: server.config(), + xpackMainStatus: ((server.plugins.xpack_main as unknown) as { status: any }).status + .plugin, + }, + }); + }, + }); +}; diff --git a/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/index.ts b/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/index.ts index 0121ed4304d26..3b47099fdc462 100644 --- a/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/index.ts +++ b/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/index.ts @@ -4,10 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; -import { HapiServer } from '../../../'; import { registerVisualizationsCollector } from './visualizations/register_usage_collector'; +import { OssTelemetrySetupDependencies } from '../../plugin'; -export function registerCollectors(usageCollection: UsageCollectionSetup, server: HapiServer) { - registerVisualizationsCollector(usageCollection, server); +export function registerCollectors(deps: OssTelemetrySetupDependencies) { + registerVisualizationsCollector(deps.usageCollection, deps.taskManager); } diff --git a/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/get_usage_collector.test.ts b/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/get_usage_collector.test.ts index d316562c826d6..ec35266646650 100644 --- a/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/get_usage_collector.test.ts +++ b/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/get_usage_collector.test.ts @@ -4,24 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import sinon from 'sinon'; -import { HapiServer } from '../../../../'; -import { - getMockCallWithInternal, - getMockKbnServer, - getMockTaskFetch, -} from '../../../../test_utils'; +import { getMockTaskFetch, getMockTaskManager } from '../../../../test_utils'; import { getUsageCollector } from './get_usage_collector'; describe('getVisualizationsCollector#fetch', () => { - let mockKbnServer: HapiServer; - - beforeEach(() => { - mockKbnServer = getMockKbnServer(getMockCallWithInternal(), getMockTaskFetch()); - }); - test('can return empty stats', async () => { - const { type, fetch } = getUsageCollector(mockKbnServer); + const { type, fetch } = getUsageCollector(getMockTaskManager()); expect(type).toBe('visualization_types'); const fetchResult = await fetch(); expect(fetchResult).toEqual({}); @@ -34,11 +22,11 @@ describe('getVisualizationsCollector#fetch', () => { runs: 1, stats: { comic_books: { total: 16, max: 12, min: 2, avg: 6 } }, }, + taskType: 'test', + params: {}, }, ]); - mockKbnServer = getMockKbnServer(getMockCallWithInternal(), mockTaskFetch); - - const { type, fetch } = getUsageCollector(mockKbnServer); + const { type, fetch } = getUsageCollector(getMockTaskManager(mockTaskFetch)); expect(type).toBe('visualization_types'); const fetchResult = await fetch(); expect(fetchResult).toEqual({ comic_books: { avg: 6, max: 12, min: 2, total: 16 } }); @@ -46,23 +34,21 @@ describe('getVisualizationsCollector#fetch', () => { describe('Error handling', () => { test('Silently handles Task Manager NotInitialized', async () => { - const mockTaskFetch = sinon.stub(); - mockTaskFetch.rejects( - new Error('NotInitialized taskManager is still waiting for plugins to load') - ); - mockKbnServer = getMockKbnServer(getMockCallWithInternal(), mockTaskFetch); - - const { fetch } = getUsageCollector(mockKbnServer); - await expect(fetch()).resolves.toBe(undefined); + const mockTaskFetch = jest.fn(() => { + throw new Error('NotInitialized taskManager is still waiting for plugins to load'); + }); + const { fetch } = getUsageCollector(getMockTaskManager(mockTaskFetch)); + const result = await fetch(); + expect(result).toBe(undefined); }); // In real life, the CollectorSet calls fetch and handles errors test('defers the errors', async () => { - const mockTaskFetch = sinon.stub(); - mockTaskFetch.rejects(new Error('BOOM')); - mockKbnServer = getMockKbnServer(getMockCallWithInternal(), mockTaskFetch); + const mockTaskFetch = jest.fn(() => { + throw new Error('BOOM'); + }); - const { fetch } = getUsageCollector(mockKbnServer); - await expect(fetch()).rejects.toMatchObject(new Error('BOOM')); + const { fetch } = getUsageCollector(getMockTaskManager(mockTaskFetch)); + await expect(fetch()).rejects.toThrowErrorMatchingInlineSnapshot(`"BOOM"`); }); }); }); diff --git a/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/get_usage_collector.ts b/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/get_usage_collector.ts index 63640c87f80a6..680cb97e0fda3 100644 --- a/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/get_usage_collector.ts +++ b/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/get_usage_collector.ts @@ -5,17 +5,15 @@ */ import { get } from 'lodash'; -import { HapiServer } from '../../../../'; +import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../../../../task_manager/plugin'; import { PLUGIN_ID, VIS_TELEMETRY_TASK, VIS_USAGE_TYPE } from '../../../../constants'; -async function isTaskManagerReady(server: HapiServer) { - const result = await fetch(server); +async function isTaskManagerReady(taskManager: TaskManagerPluginSetupContract | undefined) { + const result = await fetch(taskManager); return result !== null; } -async function fetch(server: HapiServer) { - const taskManager = server.plugins.task_manager; - +async function fetch(taskManager: TaskManagerPluginSetupContract | undefined) { if (!taskManager) { return null; } @@ -40,12 +38,12 @@ async function fetch(server: HapiServer) { return docs; } -export function getUsageCollector(server: HapiServer) { +export function getUsageCollector(taskManager: TaskManagerPluginSetupContract | undefined) { let isCollectorReady = false; async function determineIfTaskManagerIsReady() { let isReady = false; try { - isReady = await isTaskManagerReady(server); + isReady = await isTaskManagerReady(taskManager); } catch (err) {} // eslint-disable-line if (isReady) { @@ -60,7 +58,7 @@ export function getUsageCollector(server: HapiServer) { type: VIS_USAGE_TYPE, isReady: () => isCollectorReady, fetch: async () => { - const docs = await fetch(server); + const docs = await fetch(taskManager); // get the accumulated state from the recurring task return get(docs, '[0].state.stats'); }, diff --git a/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/register_usage_collector.ts b/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/register_usage_collector.ts index 09843a6f87ad7..1a47f68adcc58 100644 --- a/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/register_usage_collector.ts +++ b/x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/register_usage_collector.ts @@ -5,13 +5,13 @@ */ import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; -import { HapiServer } from '../../../../'; +import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../../../../task_manager/plugin'; import { getUsageCollector } from './get_usage_collector'; export function registerVisualizationsCollector( - usageCollection: UsageCollectionSetup, - server: HapiServer + collectorSet: UsageCollectionSetup, + taskManager: TaskManagerPluginSetupContract | undefined ): void { - const collector = usageCollection.makeUsageCollector(getUsageCollector(server)); - usageCollection.registerCollector(collector); + const collector = collectorSet.makeUsageCollector(getUsageCollector(taskManager)); + collectorSet.registerCollector(collector); } diff --git a/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/index.ts b/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/index.ts index 16e83a7938e60..cb6b4eab09741 100644 --- a/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/index.ts +++ b/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/index.ts @@ -4,15 +4,27 @@ * you may not use this file except in compliance with the Elastic License. */ -import { HapiServer } from '../../../'; +import { CoreSetup, Logger } from 'kibana/server'; +import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../../../task_manager/plugin'; import { PLUGIN_ID, VIS_TELEMETRY_TASK } from '../../../constants'; import { visualizationsTaskRunner } from './visualizations/task_runner'; +import KbnServer from '../../../../../../../src/legacy/server/kbn_server'; +import { LegacyConfig } from '../../plugin'; +import { TaskInstance } from '../../../../task_manager'; -export function registerTasks(server: HapiServer) { - const taskManager = server.plugins.task_manager; - +export function registerTasks({ + taskManager, + logger, + elasticsearch, + config, +}: { + taskManager?: TaskManagerPluginSetupContract; + logger: Logger; + elasticsearch: CoreSetup['elasticsearch']; + config: LegacyConfig; +}) { if (!taskManager) { - server.log(['debug', 'telemetry'], `Task manager is not available`); + logger.debug('Task manager is not available'); return; } @@ -20,18 +32,30 @@ export function registerTasks(server: HapiServer) { [VIS_TELEMETRY_TASK]: { title: 'X-Pack telemetry calculator for Visualizations', type: VIS_TELEMETRY_TASK, - createTaskRunner({ taskInstance }: { taskInstance: any }) { + createTaskRunner({ taskInstance }: { taskInstance: TaskInstance }) { return { - run: visualizationsTaskRunner(taskInstance, server), + run: visualizationsTaskRunner(taskInstance, config, elasticsearch), }; }, }, }); } -export function scheduleTasks(server: HapiServer) { - const taskManager = server.plugins.task_manager; - const { kbnServer } = server.plugins.xpack_main.status.plugin; +export function scheduleTasks({ + taskManager, + xpackMainStatus, + logger, +}: { + taskManager?: TaskManagerPluginSetupContract; + xpackMainStatus: { kbnServer: KbnServer }; + logger: Logger; +}) { + if (!taskManager) { + logger.debug('Task manager is not available'); + return; + } + + const { kbnServer } = xpackMainStatus; kbnServer.afterPluginsInit(() => { // The code block below can't await directly within "afterPluginsInit" @@ -46,9 +70,10 @@ export function scheduleTasks(server: HapiServer) { id: `${PLUGIN_ID}-${VIS_TELEMETRY_TASK}`, taskType: VIS_TELEMETRY_TASK, state: { stats: {}, runs: 0 }, + params: {}, }); } catch (e) { - server.log(['debug', 'telemetry'], `Error scheduling task, received ${e.message}`); + logger.debug(`Error scheduling task, received ${e.message}`); } })(); }); diff --git a/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.test.ts b/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.test.ts index 5db08ed291d6d..0663a5bd330ca 100644 --- a/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.test.ts +++ b/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.test.ts @@ -5,28 +5,30 @@ */ import moment from 'moment'; -import { HapiServer, TaskInstance } from '../../../../'; import { getMockCallWithInternal, - getMockKbnServer, + getMockConfig, + getMockEs, getMockTaskInstance, } from '../../../../test_utils'; import { visualizationsTaskRunner } from './task_runner'; +import { TaskInstance } from '../../../../../task_manager'; describe('visualizationsTaskRunner', () => { let mockTaskInstance: TaskInstance; - let mockKbnServer: HapiServer; beforeEach(() => { mockTaskInstance = getMockTaskInstance(); - mockKbnServer = getMockKbnServer(); }); describe('Error handling', () => { test('catches its own errors', async () => { const mockCallWithInternal = () => Promise.reject(new Error('Things did not go well!')); - mockKbnServer = getMockKbnServer(mockCallWithInternal); - const runner = visualizationsTaskRunner(mockTaskInstance, mockKbnServer); + const runner = visualizationsTaskRunner( + mockTaskInstance, + getMockConfig(), + getMockEs(mockCallWithInternal) + ); const result = await runner(); expect(result).toMatchObject({ error: 'Things did not go well!', @@ -45,7 +47,7 @@ describe('visualizationsTaskRunner', () => { .startOf('day') .toDate(); - const runner = visualizationsTaskRunner(mockTaskInstance, mockKbnServer); + const runner = visualizationsTaskRunner(mockTaskInstance, getMockConfig(), getMockEs()); const result = await runner(); expect(result).toMatchObject({ @@ -123,9 +125,12 @@ describe('visualizationsTaskRunner', () => { }, }, ]); - mockKbnServer = getMockKbnServer(mockCallWithInternal); - const runner = visualizationsTaskRunner(mockTaskInstance, mockKbnServer); + const runner = visualizationsTaskRunner( + mockTaskInstance, + getMockConfig(), + getMockEs(mockCallWithInternal) + ); const result = await runner(); expect(result).toMatchObject({ diff --git a/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.ts b/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.ts index 3372101c2b457..9d8f76f6a10dc 100644 --- a/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.ts +++ b/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.ts @@ -5,15 +5,12 @@ */ import _, { countBy, groupBy, mapValues } from 'lodash'; -import { - ESQueryResponse, - HapiServer, - SavedObjectDoc, - TaskInstance, - VisState, - Visualization, -} from '../../../../'; +import { APICaller, CoreSetup } from 'kibana/server'; import { getNextMidnight } from '../../get_next_midnight'; +import { VisState } from '../../../../../../../../src/legacy/core_plugins/visualizations/public'; +import { TaskInstance } from '../../../../../task_manager'; +import { ESSearchHit } from '../../../../../apm/typings/elasticsearch'; +import { LegacyConfig } from '../../../plugin'; interface VisSummary { type: string; @@ -23,7 +20,7 @@ interface VisSummary { /* * Parse the response data into telemetry payload */ -async function getStats(callCluster: (method: string, params: any) => Promise, index: string) { +async function getStats(callCluster: APICaller, index: string) { const searchParams = { size: 10000, // elasticsearch index.max_result_window default value index, @@ -35,24 +32,26 @@ async function getStats(callCluster: (method: string, params: any) => Promise(esResponse, 'hits.hits.length'); if (size < 1) { return; } // `map` to get the raw types - const visSummaries: VisSummary[] = esResponse.hits.hits.map((hit: SavedObjectDoc) => { - const spacePhrases: string[] = hit._id.split(':'); - const space = spacePhrases.length === 3 ? spacePhrases[0] : 'default'; // if in a custom space, the format of a saved object ID is space:type:id - const visualization: Visualization = _.get(hit, '_source.visualization', { visState: '{}' }); - const visState: VisState = JSON.parse(visualization.visState); + const visSummaries: VisSummary[] = esResponse.hits.hits.map( + (hit: ESSearchHit<{ visState: string }>) => { + const spacePhrases: string[] = hit._id.split(':'); + const space = spacePhrases.length === 3 ? spacePhrases[0] : 'default'; // if in a custom space, the format of a saved object ID is space:type:id + const visualization = _.get(hit, '_source.visualization', { visState: '{}' }); + const visState: VisState = JSON.parse(visualization.visState); - return { - type: visState.type || '_na_', - space, - }; - }); + return { + type: visState.type || '_na_', + space, + }; + } + ); // organize stats per type const visTypes = groupBy(visSummaries, 'type'); @@ -72,9 +71,12 @@ async function getStats(callCluster: (method: string, params: any) => Promise { diff --git a/x-pack/legacy/plugins/oss_telemetry/server/plugin.ts b/x-pack/legacy/plugins/oss_telemetry/server/plugin.ts new file mode 100644 index 0000000000000..f661311fc24b8 --- /dev/null +++ b/x-pack/legacy/plugins/oss_telemetry/server/plugin.ts @@ -0,0 +1,50 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { CoreSetup, Logger, Plugin, PluginInitializerContext } from 'kibana/server'; +import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../task_manager/plugin'; +import { registerCollectors } from './lib/collectors'; +import { registerTasks, scheduleTasks } from './lib/tasks'; +import KbnServer from '../../../../../src/legacy/server/kbn_server'; +import { UsageCollectionSetup } from '../../../../../src/plugins/usage_collection/server'; + +export interface LegacyConfig { + get: (key: string) => string | number | boolean; +} + +export interface OssTelemetrySetupDependencies { + usageCollection: UsageCollectionSetup; + __LEGACY: { + config: LegacyConfig; + xpackMainStatus: { kbnServer: KbnServer }; + }; + taskManager?: TaskManagerPluginSetupContract; +} + +export class OssTelemetryPlugin implements Plugin { + private logger: Logger; + + constructor(initializerContext: PluginInitializerContext) { + this.logger = initializerContext.logger.get(); + } + + public setup(core: CoreSetup, deps: OssTelemetrySetupDependencies) { + registerCollectors(deps); + registerTasks({ + taskManager: deps.taskManager, + logger: this.logger, + elasticsearch: core.elasticsearch, + config: deps.__LEGACY.config, + }); + scheduleTasks({ + taskManager: deps.taskManager, + xpackMainStatus: deps.__LEGACY.xpackMainStatus, + logger: this.logger, + }); + } + + public start() {} +} diff --git a/x-pack/legacy/plugins/oss_telemetry/test_utils/index.ts b/x-pack/legacy/plugins/oss_telemetry/test_utils/index.ts index 1cebe78b9c7f0..04e248d28b577 100644 --- a/x-pack/legacy/plugins/oss_telemetry/test_utils/index.ts +++ b/x-pack/legacy/plugins/oss_telemetry/test_utils/index.ts @@ -4,9 +4,16 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ESQueryResponse, HapiServer, SavedObjectDoc, TaskInstance } from '../'; +import { APICaller, CoreSetup } from 'kibana/server'; -export const getMockTaskInstance = (): TaskInstance => ({ state: { runs: 0, stats: {} } }); +import { TaskInstance } from '../../task_manager'; +import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../task_manager/plugin'; + +export const getMockTaskInstance = (): TaskInstance => ({ + state: { runs: 0, stats: {} }, + taskType: 'test', + params: {}, +}); const defaultMockSavedObjects = [ { @@ -20,10 +27,15 @@ const defaultMockSavedObjects = [ const defaultMockTaskDocs = [getMockTaskInstance()]; -export const getMockCallWithInternal = (hits: SavedObjectDoc[] = defaultMockSavedObjects) => { - return (): Promise => { +export const getMockEs = (mockCallWithInternal: APICaller = getMockCallWithInternal()) => + (({ + createClient: () => ({ callAsInternalUser: mockCallWithInternal }), + } as unknown) as CoreSetup['elasticsearch']); + +export const getMockCallWithInternal = (hits: unknown[] = defaultMockSavedObjects): APICaller => { + return ((() => { return Promise.resolve({ hits: { hits } }); - }; + }) as unknown) as APICaller; }; export const getMockTaskFetch = (docs: TaskInstance[] = defaultMockTaskDocs) => { @@ -36,24 +48,13 @@ export const getMockConfig = () => { }; }; -export const getMockKbnServer = ( - mockCallWithInternal = getMockCallWithInternal(), - mockTaskFetch = getMockTaskFetch(), - mockConfig = getMockConfig() -): HapiServer => ({ - plugins: { - elasticsearch: { - getCluster: (cluster: string) => ({ - callWithInternalUser: mockCallWithInternal, - }), - }, - xpack_main: {}, - task_manager: { - registerTaskDefinitions: (opts: any) => undefined, - ensureScheduled: (opts: any) => Promise.resolve(), - fetch: mockTaskFetch, - }, - }, - config: () => mockConfig, - log: () => undefined, +export const getMockTaskManager = (fetch: any = getMockTaskFetch()) => + (({ + registerTaskDefinitions: () => undefined, + ensureScheduled: () => Promise.resolve(), + fetch, + } as unknown) as TaskManagerPluginSetupContract); + +export const getCluster = () => ({ + callWithInternalUser: getMockCallWithInternal(), });