Skip to content

Commit

Permalink
[Reporting] Fix task manager not to run tasks before Kibana is availa…
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic authored and fkanout committed Nov 17, 2021
1 parent 9028870 commit 2042db8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
18 changes: 17 additions & 1 deletion x-pack/plugins/reporting/server/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Hapi from '@hapi/hapi';
import * as Rx from 'rxjs';
import { first, map, take } from 'rxjs/operators';
import { filter, first, map, take } from 'rxjs/operators';
import { ScreenshotModePluginSetup } from 'src/plugins/screenshot_mode/server';
import {
BasePath,
Expand All @@ -17,6 +17,8 @@ import {
PluginInitializerContext,
SavedObjectsClientContract,
SavedObjectsServiceStart,
ServiceStatusLevels,
StatusServiceSetup,
UiSettingsServiceStart,
} from '../../../../src/core/server';
import { PluginStart as DataPluginStart } from '../../../../src/plugins/data/server';
Expand Down Expand Up @@ -44,6 +46,7 @@ export interface ReportingInternalSetup {
taskManager: TaskManagerSetupContract;
screenshotMode: ScreenshotModePluginSetup;
logger: LevelLogger;
status: StatusServiceSetup;
}

export interface ReportingInternalStart {
Expand Down Expand Up @@ -111,12 +114,25 @@ export class ReportingCore {
this.pluginStart$.next(startDeps); // trigger the observer
this.pluginStartDeps = startDeps; // cache

await this.assertKibanaIsAvailable();

const { taskManager } = startDeps;
const { executeTask, monitorTask } = this;
// enable this instance to generate reports and to monitor for pending reports
await Promise.all([executeTask.init(taskManager), monitorTask.init(taskManager)]);
}

private async assertKibanaIsAvailable(): Promise<void> {
const { status } = this.getPluginSetupDeps();

await status.overall$
.pipe(
filter((current) => current.level === ServiceStatusLevels.available),
first()
)
.toPromise();
}

/*
* Blocks the caller until setup is done
*/
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/reporting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class ReportingPlugin

const router = http.createRouter<ReportingRequestHandlerContext>();
const basePath = http.basePath;

reportingCore.pluginSetup({
screenshotMode,
features,
Expand All @@ -63,6 +62,7 @@ export class ReportingPlugin
spaces,
taskManager,
logger: this.logger,
status: core.status,
});

registerUiSettings(core);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jest.mock('../browsers');

import _ from 'lodash';
import * as Rx from 'rxjs';
import { coreMock, elasticsearchServiceMock } from 'src/core/server/mocks';
import { coreMock, elasticsearchServiceMock, statusServiceMock } from 'src/core/server/mocks';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { dataPluginMock } from 'src/plugins/data/server/mocks';
import { FieldFormatsRegistry } from 'src/plugins/field_formats/common';
Expand Down Expand Up @@ -45,6 +45,7 @@ export const createMockPluginSetup = (setupMock?: any): ReportingInternalSetup =
licensing: { license$: Rx.of({ isAvailable: true, isActive: true, type: 'basic' }) } as any,
taskManager: taskManagerMock.createSetup(),
logger: createMockLevelLogger(),
status: statusServiceMock.createSetupContract(),
...setupMock,
};
};
Expand Down

0 comments on commit 2042db8

Please sign in to comment.