Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting/NP Migration] Remove server.expose of ExportTypeRegistry #50973

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
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];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙇

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';
Comment on lines +54 to +58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use LicenseType from x-pack/plugins/licensing/server instead or redeclaring them

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