Skip to content

Commit

Permalink
[Reporting/NP Migration] Remove server.expose of ExportTypeRegistry (e…
Browse files Browse the repository at this point in the history
…lastic#50973)

* [Reporting/NPMigration] typescriptify ExportTypeRegistry, remove from server.expose

* Minor routes registration cleanup

* move the ETR test file

* Re-pack the route registration, reduce LOC changes

* add EnqueueJobFn type

* Fix usage collector test

* remove a throw error used for development/debugging

* fix imports error

* Fix execute job tests

* wip test fixes

* test fixes for real

* fix more tests

* fix diffs

* Add TODOs about the ExportTypesRegistry.register unwrap the factory functions.

* really make headlessbrowserdriver required as an execute job factory option

* fix tests

* Use constants for license type keywords
  • Loading branch information
tsullivan committed Dec 11, 2019
1 parent 3e0d353 commit 0960d28
Show file tree
Hide file tree
Showing 37 changed files with 645 additions and 404 deletions.
6 changes: 6 additions & 0 deletions x-pack/legacy/plugins/reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ export const PNG_JOB_TYPE = 'PNG';
export const CSV_JOB_TYPE = 'csv';
export const CSV_FROM_SAVEDOBJECT_JOB_TYPE = 'csv_from_savedobject';
export const USES_HEADLESS_JOB_TYPES = [PDF_JOB_TYPE, PNG_JOB_TYPE];

export const LICENSE_TYPE_TRIAL = 'trial';
export const LICENSE_TYPE_BASIC = 'basic';
export const LICENSE_TYPE_STANDARD = 'standard';
export const LICENSE_TYPE_GOLD = 'gold';
export const LICENSE_TYPE_PLATINUM = 'platinum';
64 changes: 0 additions & 64 deletions x-pack/legacy/plugins/reporting/common/export_types_registry.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

import * as Rx from 'rxjs';
import { first, mergeMap } from 'rxjs/operators';
import { ServerFacade, CaptureConfig } from '../../../../types';
import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers/chromium/driver';
import {
ServerFacade,
CaptureConfig,
HeadlessChromiumDriverFactory,
HeadlessChromiumDriver as HeadlessBrowser,
} from '../../../../types';
import {
ElementsPositionAndAttribute,
ScreenshotResults,
Expand All @@ -26,10 +30,12 @@ import { getElementPositionAndAttributes } from './get_element_position_data';
import { getScreenshots } from './get_screenshots';
import { skipTelemetry } from './skip_telemetry';

export function screenshotsObservableFactory(server: ServerFacade) {
export function screenshotsObservableFactory(
server: ServerFacade,
browserDriverFactory: HeadlessChromiumDriverFactory
) {
const config = server.config();
const captureConfig: CaptureConfig = config.get('xpack.reporting.capture');
const { browserDriverFactory } = server.plugins.reporting!;

return function screenshotsObservable({
logger,
Expand Down
39 changes: 39 additions & 0 deletions x-pack/legacy/plugins/reporting/export_types/csv/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 {
CSV_JOB_TYPE as jobType,
LICENSE_TYPE_TRIAL,
LICENSE_TYPE_BASIC,
LICENSE_TYPE_STANDARD,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
} from '../../common/constants';
import { ExportTypeDefinition, ESQueueCreateJobFn, ESQueueWorkerExecuteFn } from '../../types';
import { metadata } from './metadata';
import { createJobFactory } from './server/create_job';
import { executeJobFactory } from './server/execute_job';
import { JobParamsDiscoverCsv, JobDocPayloadDiscoverCsv } from './types';

export const getExportType = (): ExportTypeDefinition<
JobParamsDiscoverCsv,
ESQueueCreateJobFn<JobParamsDiscoverCsv>,
JobDocPayloadDiscoverCsv,
ESQueueWorkerExecuteFn<JobDocPayloadDiscoverCsv>
> => ({
...metadata,
jobType,
jobContentExtension: 'csv',
createJobFactory,
executeJobFactory,
validLicenses: [
LICENSE_TYPE_TRIAL,
LICENSE_TYPE_BASIC,
LICENSE_TYPE_STANDARD,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
],
});
22 changes: 0 additions & 22 deletions x-pack/legacy/plugins/reporting/export_types/csv/server/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,43 @@
* you may not use this file except in compliance with the Elastic License.
*/

import {
CSV_FROM_SAVEDOBJECT_JOB_TYPE,
LICENSE_TYPE_TRIAL,
LICENSE_TYPE_BASIC,
LICENSE_TYPE_STANDARD,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
} from '../../common/constants';
import { ExportTypeDefinition, ImmediateCreateJobFn, ImmediateExecuteFn } from '../../types';
import { createJobFactory } from './server/create_job';
import { executeJobFactory } from './server/execute_job';
import { metadata } from './metadata';
import { JobParamsPanelCsv } from './types';

/*
* These functions are exported to share with the API route handler that
* generates csv from saved object immediately on request.
*/
export { executeJobFactory } from './server/execute_job';
export { createJobFactory } from './server/create_job';

export const getExportType = (): ExportTypeDefinition<
JobParamsPanelCsv,
ImmediateCreateJobFn<JobParamsPanelCsv>,
JobParamsPanelCsv,
ImmediateExecuteFn<JobParamsPanelCsv>
> => ({
...metadata,
jobType: CSV_FROM_SAVEDOBJECT_JOB_TYPE,
jobContentExtension: 'csv',
createJobFactory,
executeJobFactory,
validLicenses: [
LICENSE_TYPE_TRIAL,
LICENSE_TYPE_BASIC,
LICENSE_TYPE_STANDARD,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
],
});

This file was deleted.

38 changes: 38 additions & 0 deletions x-pack/legacy/plugins/reporting/export_types/png/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 {
PNG_JOB_TYPE as jobType,
LICENSE_TYPE_TRIAL,
LICENSE_TYPE_STANDARD,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
} from '../../common/constants';
import { ExportTypeDefinition, ESQueueCreateJobFn, ESQueueWorkerExecuteFn } from '../../types';
import { createJobFactory } from './server/create_job';
import { executeJobFactory } from './server/execute_job';
import { metadata } from './metadata';
import { JobParamsPNG, JobDocPayloadPNG } from './types';

export const getExportType = (): ExportTypeDefinition<
JobParamsPNG,
ESQueueCreateJobFn<JobParamsPNG>,
JobDocPayloadPNG,
ESQueueWorkerExecuteFn<JobDocPayloadPNG>
> => ({
...metadata,
jobType,
jobContentEncoding: 'base64',
jobContentExtension: 'PNG',
createJobFactory,
executeJobFactory,
validLicenses: [
LICENSE_TYPE_TRIAL,
LICENSE_TYPE_STANDARD,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ test(`passes browserTimezone to generatePng`, async () => {
const generatePngObservable = generatePngObservableFactory();
generatePngObservable.mockReturnValue(Rx.of(Buffer.from('')));

const executeJob = executeJobFactory(mockServer);
const executeJob = executeJobFactory(mockServer, { browserDriverFactory: {} });
const browserTimezone = 'UTC';
await executeJob('pngJobId', { relativeUrl: '/app/kibana#/something', browserTimezone, headers: encryptedHeaders }, cancellationToken);

expect(generatePngObservable).toBeCalledWith(expect.any(LevelLogger), 'http://localhost:5601/sbp/app/kibana#/something', browserTimezone, expect.anything(), undefined);
});

test(`returns content_type of application/png`, async () => {
const executeJob = executeJobFactory(mockServer);
const executeJob = executeJobFactory(mockServer, { browserDriverFactory: {} });
const encryptedHeaders = await encryptHeaders({});

const generatePngObservable = generatePngObservableFactory();
Expand All @@ -93,7 +93,7 @@ test(`returns content of generatePng getBuffer base64 encoded`, async () => {
const generatePngObservable = generatePngObservableFactory();
generatePngObservable.mockReturnValue(Rx.of(Buffer.from(testContent)));

const executeJob = executeJobFactory(mockServer);
const executeJob = executeJobFactory(mockServer, { browserDriverFactory: {} });
const encryptedHeaders = await encryptHeaders({});
const { content } = await executeJob('pngJobId', { relativeUrl: '/app/kibana#/something',
timeRange: {}, headers: encryptedHeaders }, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import * as Rx from 'rxjs';
import { mergeMap, catchError, map, takeUntil } from 'rxjs/operators';
import { PLUGIN_ID, PNG_JOB_TYPE } from '../../../../common/constants';
import { ServerFacade, ExecuteJobFactory, ESQueueWorkerExecuteFn } from '../../../../types';
import {
ServerFacade,
ExecuteJobFactory,
ESQueueWorkerExecuteFn,
HeadlessChromiumDriverFactory,
} from '../../../../types';
import { LevelLogger } from '../../../../server/lib';
import {
decryptJobHeaders,
Expand All @@ -18,10 +23,13 @@ import {
import { JobDocPayloadPNG } from '../../types';
import { generatePngObservableFactory } from '../lib/generate_png';

export const executeJobFactory: ExecuteJobFactory<ESQueueWorkerExecuteFn<
JobDocPayloadPNG
>> = function executeJobFactoryFn(server: ServerFacade) {
const generatePngObservable = generatePngObservableFactory(server);
type QueuedPngExecutorFactory = ExecuteJobFactory<ESQueueWorkerExecuteFn<JobDocPayloadPNG>>;

export const executeJobFactory: QueuedPngExecutorFactory = function executeJobFactoryFn(
server: ServerFacade,
{ browserDriverFactory }: { browserDriverFactory: HeadlessChromiumDriverFactory }
) {
const generatePngObservable = generatePngObservableFactory(server, browserDriverFactory);
const logger = LevelLogger.createForServer(server, [PLUGIN_ID, PNG_JOB_TYPE, 'execute']);

return function executeJob(
Expand Down
23 changes: 0 additions & 23 deletions x-pack/legacy/plugins/reporting/export_types/png/server/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import * as Rx from 'rxjs';
import { map } from 'rxjs/operators';
import { LevelLogger } from '../../../../server/lib';
import { ServerFacade, ConditionalHeaders } from '../../../../types';
import { ServerFacade, HeadlessChromiumDriverFactory, ConditionalHeaders } from '../../../../types';
import { screenshotsObservableFactory } from '../../../common/lib/screenshots';
import { PreserveLayout } from '../../../common/layouts/preserve_layout';
import { LayoutParams } from '../../../common/layouts/layout';

export function generatePngObservableFactory(server: ServerFacade) {
const screenshotsObservable = screenshotsObservableFactory(server);
export function generatePngObservableFactory(
server: ServerFacade,
browserDriverFactory: HeadlessChromiumDriverFactory
) {
const screenshotsObservable = screenshotsObservableFactory(server, browserDriverFactory);

return function generatePngObservable(
logger: LevelLogger,
Expand Down
Loading

0 comments on commit 0960d28

Please sign in to comment.