From dc8ef3edcb5c8493f4863fd4a853ac56b2293cf8 Mon Sep 17 00:00:00 2001 From: Tim Sullivan Date: Wed, 9 Oct 2019 09:14:08 -0700 Subject: [PATCH] [Reporting] Performance instrumenting 1 (#47081) --- .../common/lib/screenshots/index.ts | 41 ++++++++++--------- .../common/lib/screenshots/types.ts | 13 ------ 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/index.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/index.ts index 125baa314e07e..bcf6c63b08dd8 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/index.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/index.ts @@ -11,10 +11,9 @@ import { HeadlessChromiumDriverFactory } from '../../../../server/browsers/chrom import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers/chromium/driver'; import { ElementsPositionAndAttribute, - ScreenShotOpts, - TimeRangeOpts, + Screenshot, ScreenshotObservableOpts, - BrowserOpts, + TimeRange, } from './types'; import { checkForToastMessage } from './check_for_toast'; @@ -27,6 +26,12 @@ import { getTimeRange } from './get_time_range'; import { getElementPositionAndAttributes } from './get_element_position_data'; import { getScreenshots } from './get_screenshots'; +// NOTE: Typescript does not throw an error if this interface has errors! +interface ScreenshotResults { + timeRange: TimeRange; + screenshots: Screenshot[]; +} + export function screenshotsObservableFactory(server: KbnServer) { const browserDriverFactory: HeadlessChromiumDriverFactory = server.plugins.reporting.browserDriverFactory; // prettier-ignore const config = server.config(); @@ -38,7 +43,7 @@ export function screenshotsObservableFactory(server: KbnServer) { conditionalHeaders, layout, browserTimezone, - }: ScreenshotObservableOpts): Rx.Observable { + }: ScreenshotObservableOpts): Rx.Observable { const create$ = browserDriverFactory.create({ viewport: layout.getBrowserViewport(), browserTimezone, @@ -72,7 +77,7 @@ export function screenshotsObservableFactory(server: KbnServer) { ), mergeMap( (browser: HeadlessBrowser) => getNumberOfItems(browser, layout, logger), - (browser, itemsCount) => ({ browser, itemsCount }) + (browser, itemsCount: number) => ({ browser, itemsCount }) ), mergeMap( async ({ browser, itemsCount }) => { @@ -85,24 +90,24 @@ export function screenshotsObservableFactory(server: KbnServer) { mergeMap( ({ browser, itemsCount }) => waitForElementsToBeInDOM(browser, itemsCount, layout, logger), - ({ browser, itemsCount }) => ({ browser, itemsCount }) + ({ browser }) => browser ), mergeMap( - ({ browser }) => { + browser => { // Waiting till _after_ elements have rendered before injecting our CSS // allows for them to be displayed properly in many cases return injectCustomCss(browser, layout, logger); }, - ({ browser }) => ({ browser }) + browser => browser ), mergeMap( - async ({ browser }) => { + async browser => { if (layout.positionElements) { // position panel elements for print layout return await layout.positionElements(browser, logger); } }, - ({ browser }) => browser + browser => browser ), mergeMap( (browser: HeadlessBrowser) => { @@ -111,21 +116,17 @@ export function screenshotsObservableFactory(server: KbnServer) { browser => browser ), mergeMap( - (browser: HeadlessBrowser) => getTimeRange(browser, layout, logger), - (browser, timeRange) => ({ browser, timeRange }) + browser => getTimeRange(browser, layout, logger), + (browser, timeRange: TimeRange | null) => ({ browser, timeRange }) ), mergeMap( ({ browser }) => getElementPositionAndAttributes(browser, layout), - ( - { browser, timeRange }: BrowserOpts & TimeRangeOpts, - elementsPositionAndAttributes: ElementsPositionAndAttribute[] - ) => ({ browser, timeRange, elementsPositionAndAttributes }) + ({ browser, timeRange }, elementsPositionAndAttributes: ElementsPositionAndAttribute[]) => { + return { browser, timeRange, elementsPositionAndAttributes }; + } // prettier-ignore ), mergeMap( - ({ - browser, - elementsPositionAndAttributes, - }: BrowserOpts & ScreenShotOpts & TimeRangeOpts) => { + ({ browser, elementsPositionAndAttributes }) => { return getScreenshots({ browser, elementsPositionAndAttributes, logger }); }, ({ timeRange }, screenshots) => ({ timeRange, screenshots }) diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/types.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/types.ts index b8179ab5e7b25..586814d2d1959 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/types.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/types.ts @@ -5,7 +5,6 @@ */ import { ElementPosition, ConditionalHeaders } from '../../../../types'; -import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers/chromium/driver'; import { LevelLogger } from '../../../../server/lib'; import { LayoutInstance } from '../../layouts/layout'; @@ -36,15 +35,3 @@ export interface Screenshot { title: any; description: any; } - -export interface ScreenShotOpts { - elementsPositionAndAttributes: ElementsPositionAndAttribute[]; -} - -export interface BrowserOpts { - browser: HeadlessBrowser; -} - -export interface TimeRangeOpts { - timeRange: TimeRange; -}