Skip to content

Commit

Permalink
fixed empty TaskManager issue in oss_telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Jan 3, 2020
1 parent 1108dfb commit 5f8e2e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
17 changes: 12 additions & 5 deletions x-pack/legacy/plugins/oss_telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

import { Logger, PluginInitializerContext } from 'kibana/server';
import { Legacy } from 'kibana';
import { isFunction } from 'lodash';
import { PLUGIN_ID } from './constants';
import { OssTelemetryPlugin } from './server/plugin';
import { LegacyPluginInitializer } from '../../../../src/legacy/plugin_discovery/types';
Expand All @@ -16,7 +18,7 @@ export const ossTelemetry: LegacyPluginInitializer = kibana => {
require: ['elasticsearch', 'xpack_main'],
configPrefix: 'xpack.oss_telemetry',

init(server) {
init(server: Legacy.Server) {
const plugin = new OssTelemetryPlugin({
logger: {
get: () =>
Expand All @@ -30,10 +32,7 @@ export const ossTelemetry: LegacyPluginInitializer = kibana => {
} as PluginInitializerContext);
plugin.setup(server.newPlatform.setup.core, {
usageCollection: server.newPlatform.setup.plugins.usageCollection,
taskManager: {
...server.newPlatform.setup.plugins.kibanaTaskManager,
...server.newPlatform.start.plugins.kibanaTaskManager,
} as TaskManager,
taskManager: getTaskManager(server),
__LEGACY: {
config: server.config(),
xpackMainStatus: ((server.plugins.xpack_main as unknown) as { status: any }).status
Expand All @@ -43,3 +42,11 @@ export const ossTelemetry: LegacyPluginInitializer = kibana => {
},
});
};

function getTaskManager(server: Legacy.Server) {
const taskManager = {
...(server?.newPlatform?.setup?.plugins?.kibanaTaskManager || {}),
...(server?.newPlatform?.start?.plugins?.kibanaTaskManager || {}),
} as TaskManager;
return isFunction(taskManager.ensureScheduled) ? taskManager : undefined;
}
28 changes: 17 additions & 11 deletions x-pack/plugins/kibana_task_manager/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ export type TaskManagerPluginStartContract = Omit<
export class TaskManagerPlugin
implements Plugin<TaskManagerPluginSetupContract, TaskManagerPluginStartContract> {
legacySetup$: AsyncSubject<LegacySetup> = new AsyncSubject<LegacySetup>();
legacySetupResult: Promise<LegacySetup> = new Promise(resolve => {
this.legacySetup$.subscribe(__LEGACY => {
resolve(__LEGACY);
});
});
legacySetupResult: Promise<LegacySetup> = resolveOnFirstValue<LegacySetup>(this.legacySetup$);
currentConfig: TaskManagerConfig;

constructor(private readonly initContext: PluginInitializerContext) {
Expand Down Expand Up @@ -84,13 +80,15 @@ export class TaskManagerPlugin
}

public start(): TaskManagerPluginStartContract {
const taskManager = this.legacySetupResult.then(({ legacyPlugin }) => legacyPlugin.start());
const legacyTaskManager = this.legacySetupResult.then(({ legacyPlugin }) =>
legacyPlugin.start()
);
return {
fetch: (...args) => taskManager.then(tm => tm.fetch(...args)),
remove: (...args) => taskManager.then(tm => tm.remove(...args)),
schedule: (...args) => taskManager.then(tm => tm.schedule(...args)),
runNow: (...args) => taskManager.then(tm => tm.runNow(...args)),
ensureScheduled: (...args) => taskManager.then(tm => tm.ensureScheduled(...args)),
fetch: (...args) => legacyTaskManager.then(tm => tm.fetch(...args)),
remove: (...args) => legacyTaskManager.then(tm => tm.remove(...args)),
schedule: (...args) => legacyTaskManager.then(tm => tm.schedule(...args)),
runNow: (...args) => legacyTaskManager.then(tm => tm.runNow(...args)),
ensureScheduled: (...args) => legacyTaskManager.then(tm => tm.ensureScheduled(...args)),
};
}
public stop() {
Expand All @@ -99,3 +97,11 @@ export class TaskManagerPlugin
});
}
}

function resolveOnFirstValue<T>(stream$: AsyncSubject<T>): Promise<T> {
return new Promise(resolve => {
stream$.subscribe(value => {
resolve(value);
});
});
}

0 comments on commit 5f8e2e5

Please sign in to comment.