From bf673d9c565c288223483c4c622f37f745ce70e6 Mon Sep 17 00:00:00 2001 From: Tim Sullivan Date: Thu, 22 Aug 2024 11:03:03 -0700 Subject: [PATCH] [Screenshotting] Server package for stateless code (#188390) ## Summary This PR moves code that is usually impacted by a Puppeteer/Chromium upgrade to a package. The same work is happening to a lesser degree in the 7.17 branch. Together, these changes will ease the manual labor of backporting the upgrades from main to 7.17. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .github/CODEOWNERS | 1 + package.json | 1 + packages/kbn-screenshotting-server/README.md | 3 +++ packages/kbn-screenshotting-server/index.ts | 13 +++++++++++ .../kbn-screenshotting-server/jest.config.js | 13 +++++++++++ .../kbn-screenshotting-server/kibana.jsonc | 5 ++++ .../kbn-screenshotting-server/package.json | 6 +++++ .../src}/args.test.ts | 5 ++-- .../kbn-screenshotting-server/src}/args.ts | 7 +++--- .../src}/config/create_config.test.ts | 5 ++-- .../src}/config/create_config.ts | 5 ++-- .../default_chromium_sandbox_disabled.test.ts | 5 ++-- .../default_chromium_sandbox_disabled.ts | 5 ++-- .../src}/config/index.ts | 5 ++-- .../src}/config/schema.ts | 5 ++-- .../src/get_chromium_package.ts | 23 +++++++++++++++++++ .../kbn-screenshotting-server/src}/paths.ts | 5 ++-- .../kbn-screenshotting-server/tsconfig.json | 21 +++++++++++++++++ tsconfig.base.json | 2 ++ .../server/browsers/chromium/driver.test.ts | 2 +- .../server/browsers/chromium/driver.ts | 4 ++-- .../chromium/driver_factory/index.test.ts | 2 +- .../browsers/chromium/driver_factory/index.ts | 9 ++++---- .../server/browsers/chromium/index.ts | 2 -- .../integration_tests/downloads.test.ts | 2 +- .../server/browsers/download/index.test.ts | 10 ++++---- .../server/browsers/download/index.ts | 6 ++--- .../screenshotting/server/browsers/index.ts | 1 - .../screenshotting/server/browsers/install.ts | 4 ++-- .../server/config/schema.test.ts | 2 +- x-pack/plugins/screenshotting/server/index.ts | 2 +- .../plugins/screenshotting/server/plugin.ts | 15 +++++++----- .../screenshots/event_logger/index.test.ts | 4 ++-- .../server/screenshots/event_logger/index.ts | 2 +- .../get_element_position_data.test.ts | 2 +- .../screenshots/get_number_of_items.test.ts | 2 +- .../screenshots/get_render_errors.test.ts | 2 +- .../screenshots/get_screenshots.test.ts | 2 +- .../server/screenshots/get_time_range.test.ts | 2 +- .../server/screenshots/index.test.ts | 2 +- .../server/screenshots/observable.test.ts | 5 ++-- .../server/screenshots/observable.ts | 14 ++++++++--- .../server/screenshots/screenshots.test.ts | 2 +- .../server/screenshots/screenshots.ts | 21 +++++++++++++---- x-pack/plugins/screenshotting/server/utils.ts | 15 ++---------- x-pack/plugins/screenshotting/tsconfig.json | 3 +-- yarn.lock | 4 ++++ 47 files changed, 193 insertions(+), 85 deletions(-) create mode 100644 packages/kbn-screenshotting-server/README.md create mode 100644 packages/kbn-screenshotting-server/index.ts create mode 100644 packages/kbn-screenshotting-server/jest.config.js create mode 100644 packages/kbn-screenshotting-server/kibana.jsonc create mode 100644 packages/kbn-screenshotting-server/package.json rename {x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory => packages/kbn-screenshotting-server/src}/args.test.ts (89%) rename {x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory => packages/kbn-screenshotting-server/src}/args.ts (92%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/create_config.test.ts (86%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/create_config.ts (89%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/default_chromium_sandbox_disabled.test.ts (92%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/default_chromium_sandbox_disabled.ts (90%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/index.ts (93%) rename {x-pack/plugins/screenshotting/server => packages/kbn-screenshotting-server/src}/config/schema.ts (94%) create mode 100644 packages/kbn-screenshotting-server/src/get_chromium_package.ts rename {x-pack/plugins/screenshotting/server/browsers/chromium => packages/kbn-screenshotting-server/src}/paths.ts (96%) create mode 100644 packages/kbn-screenshotting-server/tsconfig.json diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f366f654c7770..8a307d8ce90a1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -732,6 +732,7 @@ examples/screenshot_mode_example @elastic/appex-sharedux src/plugins/screenshot_mode @elastic/appex-sharedux x-pack/examples/screenshotting_example @elastic/appex-sharedux x-pack/plugins/screenshotting @elastic/kibana-reporting-services +packages/kbn-screenshotting-server @elastic/appex-sharedux packages/kbn-search-api-panels @elastic/search-kibana x-pack/plugins/search_assistant @elastic/search-kibana packages/kbn-search-connectors @elastic/search-kibana diff --git a/package.json b/package.json index 949f7bbaad953..20221c21a8f7b 100644 --- a/package.json +++ b/package.json @@ -750,6 +750,7 @@ "@kbn/screenshot-mode-plugin": "link:src/plugins/screenshot_mode", "@kbn/screenshotting-example-plugin": "link:x-pack/examples/screenshotting_example", "@kbn/screenshotting-plugin": "link:x-pack/plugins/screenshotting", + "@kbn/screenshotting-server": "link:packages/kbn-screenshotting-server", "@kbn/search-api-panels": "link:packages/kbn-search-api-panels", "@kbn/search-assistant": "link:x-pack/plugins/search_assistant", "@kbn/search-connectors": "link:packages/kbn-search-connectors", diff --git a/packages/kbn-screenshotting-server/README.md b/packages/kbn-screenshotting-server/README.md new file mode 100644 index 0000000000000..5dbac6d0ea00f --- /dev/null +++ b/packages/kbn-screenshotting-server/README.md @@ -0,0 +1,3 @@ +# @kbn/screenshotting-server + +Stateless code pertaining to the capture of screenshots for Kibana Reporting diff --git a/packages/kbn-screenshotting-server/index.ts b/packages/kbn-screenshotting-server/index.ts new file mode 100644 index 0000000000000..8ba3e368f4629 --- /dev/null +++ b/packages/kbn-screenshotting-server/index.ts @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export { args } from './src/args'; +export { ChromiumArchivePaths, type PackageInfo } from './src/paths'; +export { getChromiumPackage } from './src/get_chromium_package'; +export { type ConfigType, createConfig, config, durationToNumber } from './src/config'; +export { ConfigSchema } from './src/config/schema'; diff --git a/packages/kbn-screenshotting-server/jest.config.js b/packages/kbn-screenshotting-server/jest.config.js new file mode 100644 index 0000000000000..7436a349ebfc7 --- /dev/null +++ b/packages/kbn-screenshotting-server/jest.config.js @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../..', + roots: ['/packages/kbn-screenshotting-server'], +}; diff --git a/packages/kbn-screenshotting-server/kibana.jsonc b/packages/kbn-screenshotting-server/kibana.jsonc new file mode 100644 index 0000000000000..1f2aa1c0f5794 --- /dev/null +++ b/packages/kbn-screenshotting-server/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "type": "shared-server", + "id": "@kbn/screenshotting-server", + "owner": "@elastic/appex-sharedux" +} diff --git a/packages/kbn-screenshotting-server/package.json b/packages/kbn-screenshotting-server/package.json new file mode 100644 index 0000000000000..11f02c6cb5c30 --- /dev/null +++ b/packages/kbn-screenshotting-server/package.json @@ -0,0 +1,6 @@ +{ + "name": "@kbn/screenshotting-server", + "private": true, + "version": "1.0.0", + "license": "SSPL-1.0 OR Elastic License 2.0" +} \ No newline at end of file diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.test.ts b/packages/kbn-screenshotting-server/src/args.test.ts similarity index 89% rename from x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.test.ts rename to packages/kbn-screenshotting-server/src/args.test.ts index d66386deb1669..b3ed9a8a4003c 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.test.ts +++ b/packages/kbn-screenshotting-server/src/args.test.ts @@ -1,8 +1,9 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ import os from 'os'; diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.ts b/packages/kbn-screenshotting-server/src/args.ts similarity index 92% rename from x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.ts rename to packages/kbn-screenshotting-server/src/args.ts index 2337e452cdc94..a1b1b82e8a24a 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/args.ts +++ b/packages/kbn-screenshotting-server/src/args.ts @@ -1,12 +1,13 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ import os from 'os'; -import type { ConfigType } from '../../../config'; +import type { ConfigType } from './config'; interface WindowSize { height: number; diff --git a/x-pack/plugins/screenshotting/server/config/create_config.test.ts b/packages/kbn-screenshotting-server/src/config/create_config.test.ts similarity index 86% rename from x-pack/plugins/screenshotting/server/config/create_config.test.ts rename to packages/kbn-screenshotting-server/src/config/create_config.test.ts index 4bc5ff65727d0..9a6a7e1cdd579 100644 --- a/x-pack/plugins/screenshotting/server/config/create_config.test.ts +++ b/packages/kbn-screenshotting-server/src/config/create_config.test.ts @@ -1,8 +1,9 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ import type { Logger } from '@kbn/core/server'; diff --git a/x-pack/plugins/screenshotting/server/config/create_config.ts b/packages/kbn-screenshotting-server/src/config/create_config.ts similarity index 89% rename from x-pack/plugins/screenshotting/server/config/create_config.ts rename to packages/kbn-screenshotting-server/src/config/create_config.ts index c2ab86b5de76e..099dc0b8cb9e6 100644 --- a/x-pack/plugins/screenshotting/server/config/create_config.ts +++ b/packages/kbn-screenshotting-server/src/config/create_config.ts @@ -1,8 +1,9 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ import { set } from '@kbn/safer-lodash-set'; diff --git a/x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.test.ts b/packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.test.ts similarity index 92% rename from x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.test.ts rename to packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.test.ts index 0b5f503e86921..01e863556691d 100644 --- a/x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.test.ts +++ b/packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.test.ts @@ -1,8 +1,9 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ jest.mock('getos', () => jest.fn()); diff --git a/x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.ts b/packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.ts similarity index 90% rename from x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.ts rename to packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.ts index 34986e804f45a..19b268f20439c 100644 --- a/x-pack/plugins/screenshotting/server/config/default_chromium_sandbox_disabled.ts +++ b/packages/kbn-screenshotting-server/src/config/default_chromium_sandbox_disabled.ts @@ -1,8 +1,9 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ import getOsSync from 'getos'; diff --git a/x-pack/plugins/screenshotting/server/config/index.ts b/packages/kbn-screenshotting-server/src/config/index.ts similarity index 93% rename from x-pack/plugins/screenshotting/server/config/index.ts rename to packages/kbn-screenshotting-server/src/config/index.ts index 468f092780112..583952da6cba6 100644 --- a/x-pack/plugins/screenshotting/server/config/index.ts +++ b/packages/kbn-screenshotting-server/src/config/index.ts @@ -1,8 +1,9 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ import type { PluginConfigDescriptor } from '@kbn/core/server'; diff --git a/x-pack/plugins/screenshotting/server/config/schema.ts b/packages/kbn-screenshotting-server/src/config/schema.ts similarity index 94% rename from x-pack/plugins/screenshotting/server/config/schema.ts rename to packages/kbn-screenshotting-server/src/config/schema.ts index 0dda1e3ae9981..ce542f2a849f4 100644 --- a/x-pack/plugins/screenshotting/server/config/schema.ts +++ b/packages/kbn-screenshotting-server/src/config/schema.ts @@ -1,8 +1,9 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ import { schema, TypeOf, offeringBasedSchema } from '@kbn/config-schema'; diff --git a/packages/kbn-screenshotting-server/src/get_chromium_package.ts b/packages/kbn-screenshotting-server/src/get_chromium_package.ts new file mode 100644 index 0000000000000..af79341d0046a --- /dev/null +++ b/packages/kbn-screenshotting-server/src/get_chromium_package.ts @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import os from 'os'; +import { ChromiumArchivePaths } from './paths'; + +const paths = new ChromiumArchivePaths(); + +export const getChromiumPackage = () => { + const platform = process.platform; + const architecture = os.arch(); + + const chromiumPackageInfo = paths.find(process.platform, architecture); + if (!chromiumPackageInfo) { + throw new Error(`Unsupported platform: ${platform}-${architecture}`); + } + return chromiumPackageInfo; +}; diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/paths.ts b/packages/kbn-screenshotting-server/src/paths.ts similarity index 96% rename from x-pack/plugins/screenshotting/server/browsers/chromium/paths.ts rename to packages/kbn-screenshotting-server/src/paths.ts index ba82fe21734e4..f3c339988567f 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/paths.ts +++ b/packages/kbn-screenshotting-server/src/paths.ts @@ -1,8 +1,9 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ import path from 'path'; diff --git a/packages/kbn-screenshotting-server/tsconfig.json b/packages/kbn-screenshotting-server/tsconfig.json new file mode 100644 index 0000000000000..1ca4b9da2b0f6 --- /dev/null +++ b/packages/kbn-screenshotting-server/tsconfig.json @@ -0,0 +1,21 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "jest", + "node" + ] + }, + "include": [ + "**/*.ts" + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [ + "@kbn/core", + "@kbn/safer-lodash-set", + "@kbn/config-schema" + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index 9f37b2ad90f59..690d74cfab916 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1458,6 +1458,8 @@ "@kbn/screenshotting-example-plugin/*": ["x-pack/examples/screenshotting_example/*"], "@kbn/screenshotting-plugin": ["x-pack/plugins/screenshotting"], "@kbn/screenshotting-plugin/*": ["x-pack/plugins/screenshotting/*"], + "@kbn/screenshotting-server": ["packages/kbn-screenshotting-server"], + "@kbn/screenshotting-server/*": ["packages/kbn-screenshotting-server/*"], "@kbn/search-api-panels": ["packages/kbn-search-api-panels"], "@kbn/search-api-panels/*": ["packages/kbn-search-api-panels/*"], "@kbn/search-assistant": ["x-pack/plugins/search_assistant"], diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.test.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.test.ts index c9b9bbc9f8b03..e63d6690c72f1 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.test.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.test.ts @@ -7,9 +7,9 @@ import type { Logger } from '@kbn/logging'; import { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; +import { ConfigType } from '@kbn/screenshotting-server'; import * as puppeteer from 'puppeteer'; import { Size } from '../../../common/layout'; -import { ConfigType } from '../../config'; import { PreserveLayout } from '../../layouts/preserve_layout'; import { HeadlessChromiumDriver } from './driver'; diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts index fbe118280fe85..02d611f9ca00f 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts @@ -10,13 +10,13 @@ import { KBN_SCREENSHOT_MODE_HEADER, ScreenshotModePluginSetup, } from '@kbn/screenshot-mode-plugin/server'; +import { ConfigType } from '@kbn/screenshotting-server'; import { truncate } from 'lodash'; import open from 'opn'; -import { ElementHandle, Page, EvaluateFunc, HTTPResponse } from 'puppeteer'; +import { ElementHandle, EvaluateFunc, HTTPResponse, Page } from 'puppeteer'; import { Subject } from 'rxjs'; import { parse as parseUrl } from 'url'; import { getDisallowedOutgoingUrlError } from '.'; -import { ConfigType } from '../../config'; import { Layout } from '../../layouts'; import { getPrintLayoutSelectors } from '../../layouts/print_layout'; import { allowRequest } from '../network_policy'; diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.test.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.test.ts index 13b9070edb7fb..109de627a78e5 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.test.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.test.ts @@ -8,11 +8,11 @@ import type { Logger } from '@kbn/core/server'; import { loggerMock } from '@kbn/logging-mocks'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; +import { ConfigType } from '@kbn/screenshotting-server'; import * as puppeteer from 'puppeteer'; import * as Rx from 'rxjs'; import { mergeMap, take } from 'rxjs'; import { DEFAULT_VIEWPORT, HeadlessChromiumDriverFactory } from '.'; -import { ConfigType } from '../../../config'; jest.mock('puppeteer'); diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts index 66a4dac0c37a2..f6015c319cc0a 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts @@ -7,23 +7,22 @@ import type { Logger } from '@kbn/core/server'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; +import { ConfigType, args } from '@kbn/screenshotting-server'; import { getDataPath } from '@kbn/utils'; import { spawn } from 'child_process'; import del from 'del'; import fs from 'fs'; import { uniq } from 'lodash'; import path from 'path'; -import puppeteer, { Browser, ConsoleMessage, Page, Viewport, PageEvents } from 'puppeteer'; +import puppeteer, { Browser, ConsoleMessage, Page, PageEvents, Viewport } from 'puppeteer'; import { createInterface } from 'readline'; import * as Rx from 'rxjs'; -import { catchError, concatMap, ignoreElements, mergeMap, map, reduce, takeUntil, tap } from 'rxjs'; -import { PerformanceMetrics } from '../../../../common/types'; +import { catchError, concatMap, ignoreElements, map, mergeMap, reduce, takeUntil, tap } from 'rxjs'; import { getChromiumDisconnectedError } from '..'; import { errors } from '../../../../common'; -import { ConfigType } from '../../../config'; +import { PerformanceMetrics } from '../../../../common/types'; import { safeChildProcess } from '../../safe_child_process'; import { HeadlessChromiumDriver } from '../driver'; -import { args } from './args'; import { getMetrics } from './metrics'; interface CreatePageOptions { diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/index.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/index.ts index e3f96f3a7445b..78b66601663d5 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/index.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/index.ts @@ -20,5 +20,3 @@ export const getDisallowedOutgoingUrlError = (interceptedUrl: string) => export { HeadlessChromiumDriver } from './driver'; export type { Context } from './driver'; export { DEFAULT_VIEWPORT, HeadlessChromiumDriverFactory } from './driver_factory'; -export { ChromiumArchivePaths } from './paths'; -export type { PackageInfo } from './paths'; diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/integration_tests/downloads.test.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/integration_tests/downloads.test.ts index d6f215df9bef4..da9add2c33c4f 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/integration_tests/downloads.test.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/integration_tests/downloads.test.ts @@ -6,10 +6,10 @@ */ import { loggingSystemMock } from '@kbn/core-logging-server-mocks'; +import { PackageInfo } from '@kbn/screenshotting-server'; import assert from 'assert'; import axios from 'axios'; import path from 'path'; -import { PackageInfo } from '..'; import { paths as chromiumArchivePaths } from '../../../utils'; import { download } from '../../download'; import { install } from '../../install'; diff --git a/x-pack/plugins/screenshotting/server/browsers/download/index.test.ts b/x-pack/plugins/screenshotting/server/browsers/download/index.test.ts index 96d9bd0299327..24725c811f5d1 100644 --- a/x-pack/plugins/screenshotting/server/browsers/download/index.test.ts +++ b/x-pack/plugins/screenshotting/server/browsers/download/index.test.ts @@ -5,13 +5,13 @@ * 2.0. */ -import path from 'path'; -import mockFs from 'mock-fs'; +import { ChromiumArchivePaths, PackageInfo } from '@kbn/screenshotting-server'; import { access, readdir } from 'fs/promises'; -import { ChromiumArchivePaths, PackageInfo } from '../chromium'; -import { fetch } from './fetch'; -import { sha256 } from './checksum'; +import mockFs from 'mock-fs'; +import path from 'path'; import { download } from '.'; +import { sha256 } from './checksum'; +import { fetch } from './fetch'; jest.mock('./checksum'); jest.mock('./fetch'); diff --git a/x-pack/plugins/screenshotting/server/browsers/download/index.ts b/x-pack/plugins/screenshotting/server/browsers/download/index.ts index bef22c7c2196a..03c3ecda02eb4 100644 --- a/x-pack/plugins/screenshotting/server/browsers/download/index.ts +++ b/x-pack/plugins/screenshotting/server/browsers/download/index.ts @@ -5,10 +5,10 @@ * 2.0. */ -import { access } from 'fs/promises'; -import del from 'del'; import type { Logger } from '@kbn/core/server'; -import type { ChromiumArchivePaths, PackageInfo } from '../chromium'; +import type { ChromiumArchivePaths, PackageInfo } from '@kbn/screenshotting-server'; +import del from 'del'; +import { access } from 'fs/promises'; import { sha256 } from './checksum'; import { fetch } from './fetch'; diff --git a/x-pack/plugins/screenshotting/server/browsers/index.ts b/x-pack/plugins/screenshotting/server/browsers/index.ts index 0b6402a0bd6fb..3c3a1a2171686 100644 --- a/x-pack/plugins/screenshotting/server/browsers/index.ts +++ b/x-pack/plugins/screenshotting/server/browsers/index.ts @@ -10,7 +10,6 @@ export { install } from './install'; export type { Context } from './chromium'; export { getChromiumDisconnectedError, - ChromiumArchivePaths, DEFAULT_VIEWPORT, HeadlessChromiumDriver, HeadlessChromiumDriverFactory, diff --git a/x-pack/plugins/screenshotting/server/browsers/install.ts b/x-pack/plugins/screenshotting/server/browsers/install.ts index 84b9ddc85923b..2a7e79e7fe150 100644 --- a/x-pack/plugins/screenshotting/server/browsers/install.ts +++ b/x-pack/plugins/screenshotting/server/browsers/install.ts @@ -5,10 +5,10 @@ * 2.0. */ +import type { Logger } from '@kbn/core/server'; +import { ChromiumArchivePaths, PackageInfo } from '@kbn/screenshotting-server'; import del from 'del'; import path from 'path'; -import type { Logger } from '@kbn/core/server'; -import { ChromiumArchivePaths, PackageInfo } from './chromium'; import { download } from './download'; import { sha256 } from './download/checksum'; import { extract } from './extract'; diff --git a/x-pack/plugins/screenshotting/server/config/schema.test.ts b/x-pack/plugins/screenshotting/server/config/schema.test.ts index a3a141429b4db..18ef1aa41415c 100644 --- a/x-pack/plugins/screenshotting/server/config/schema.test.ts +++ b/x-pack/plugins/screenshotting/server/config/schema.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { ConfigSchema } from './schema'; +import { ConfigSchema } from '@kbn/screenshotting-server'; describe('ConfigSchema', () => { it(`should produce correct config for context {"dev": false,"dist": false}`, () => { diff --git a/x-pack/plugins/screenshotting/server/index.ts b/x-pack/plugins/screenshotting/server/index.ts index 414fde21c85a9..f8d448aba412d 100755 --- a/x-pack/plugins/screenshotting/server/index.ts +++ b/x-pack/plugins/screenshotting/server/index.ts @@ -15,7 +15,7 @@ export async function plugin(pluginInitializerContext: PluginInitializerContext) return new ScreenshottingPlugin(pluginInitializerContext); } -export { config } from './config'; +export { config } from '@kbn/screenshotting-server'; export type { PdfScreenshotOptions, PdfScreenshotResult, diff --git a/x-pack/plugins/screenshotting/server/plugin.ts b/x-pack/plugins/screenshotting/server/plugin.ts index 7cfb5d3982eb8..30ca101b8b422 100755 --- a/x-pack/plugins/screenshotting/server/plugin.ts +++ b/x-pack/plugins/screenshotting/server/plugin.ts @@ -5,8 +5,7 @@ * 2.0. */ -import { from } from 'rxjs'; -import { switchMap } from 'rxjs'; +import type { CloudSetup } from '@kbn/cloud-plugin/server'; import type { CoreSetup, CoreStart, @@ -16,11 +15,15 @@ import type { PluginInitializerContext, } from '@kbn/core/server'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; -import type { CloudSetup } from '@kbn/cloud-plugin/server'; -import { ChromiumArchivePaths, HeadlessChromiumDriverFactory, install } from './browsers'; -import { ConfigType, createConfig } from './config'; +import { + ChromiumArchivePaths, + ConfigType, + createConfig, + getChromiumPackage, +} from '@kbn/screenshotting-server'; +import { from, switchMap } from 'rxjs'; +import { HeadlessChromiumDriverFactory, install } from './browsers'; import { Screenshots } from './screenshots'; -import { getChromiumPackage } from './utils'; interface SetupDeps { screenshotMode: ScreenshotModePluginSetup; diff --git a/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.test.ts b/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.test.ts index 3a20c404ff497..5a4236704e232 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.test.ts @@ -5,11 +5,11 @@ * 2.0. */ -import moment from 'moment'; import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; +import moment from 'moment'; import { Actions, EventLogger, ScreenshottingAction, Transactions } from '.'; import { ElementPosition } from '../get_element_position_data'; -import { ConfigType } from '../../config'; jest.mock('uuid', () => ({ v4: () => 'NEW_UUID', diff --git a/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.ts b/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.ts index d067b99750d19..c31e1870615b6 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/event_logger/index.ts @@ -6,11 +6,11 @@ */ import { Logger, LogMeta } from '@kbn/core/server'; +import { ConfigType } from '@kbn/screenshotting-server'; import apm from 'elastic-apm-node'; import { v4 as uuidv4 } from 'uuid'; import { CaptureResult } from '..'; import { PLUGIN_ID } from '../../../common'; -import { ConfigType } from '../../config'; import { ElementPosition } from '../get_element_position_data'; import type { Screenshot } from '../types'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/get_element_position_data.test.ts b/x-pack/plugins/screenshotting/server/screenshots/get_element_position_data.test.ts index c32135f530bf3..cb88b9369a5c0 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/get_element_position_data.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/get_element_position_data.test.ts @@ -6,8 +6,8 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; import { createMockBrowserDriver } from '../browsers/mock'; -import { ConfigType } from '../config'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; import { getElementPositionAndAttributes } from './get_element_position_data'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/get_number_of_items.test.ts b/x-pack/plugins/screenshotting/server/screenshots/get_number_of_items.test.ts index a7c4f27065bcf..a968ff458804d 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/get_number_of_items.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/get_number_of_items.test.ts @@ -6,8 +6,8 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; import { createMockBrowserDriver } from '../browsers/mock'; -import { ConfigType } from '../config'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; import { getNumberOfItems } from './get_number_of_items'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/get_render_errors.test.ts b/x-pack/plugins/screenshotting/server/screenshots/get_render_errors.test.ts index ece25b37725c8..70a914f4aa4d5 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/get_render_errors.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/get_render_errors.test.ts @@ -6,8 +6,8 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; import { createMockBrowserDriver } from '../browsers/mock'; -import { ConfigType } from '../config'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; import { getRenderErrors } from './get_render_errors'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/get_screenshots.test.ts b/x-pack/plugins/screenshotting/server/screenshots/get_screenshots.test.ts index 52298b5966f25..cc1235a852b87 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/get_screenshots.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/get_screenshots.test.ts @@ -6,8 +6,8 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; import { createMockBrowserDriver } from '../browsers/mock'; -import { ConfigType } from '../config'; import { Layout } from '../layouts'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/get_time_range.test.ts b/x-pack/plugins/screenshotting/server/screenshots/get_time_range.test.ts index a7a7b9295068e..a3b4677ef7357 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/get_time_range.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/get_time_range.test.ts @@ -6,8 +6,8 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { ConfigType } from '@kbn/screenshotting-server'; import { createMockBrowserDriver } from '../browsers/mock'; -import { ConfigType } from '../config'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; import { getTimeRange } from './get_time_range'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/index.test.ts b/x-pack/plugins/screenshotting/server/screenshots/index.test.ts index 3c6540f287706..6ecaa0916b0f3 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/index.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/index.test.ts @@ -8,6 +8,7 @@ import type { CloudSetup } from '@kbn/cloud-plugin/server'; import type { Logger, PackageInfo } from '@kbn/core/server'; import { httpServiceMock, loggingSystemMock } from '@kbn/core/server/mocks'; +import type { ConfigType } from '@kbn/screenshotting-server'; import { lastValueFrom, of, throwError } from 'rxjs'; import { ScreenshotOptions, Screenshots } from '.'; import { @@ -18,7 +19,6 @@ import { import * as errors from '../../common/errors'; import type { HeadlessChromiumDriverFactory } from '../browsers'; import { createMockBrowserDriver, createMockBrowserDriverFactory } from '../browsers/mock'; -import type { ConfigType } from '../config'; import type { PngScreenshotOptions } from '../formats'; import * as Layouts from '../layouts/create_layout'; import { createMockLayout } from '../layouts/mock'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/observable.test.ts b/x-pack/plugins/screenshotting/server/screenshots/observable.test.ts index 9ebbead104cc6..82f1467ffa5d1 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/observable.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/observable.test.ts @@ -6,10 +6,9 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; -import { interval, lastValueFrom, of, throwError } from 'rxjs'; -import { map } from 'rxjs'; +import type { ConfigType } from '@kbn/screenshotting-server'; +import { interval, lastValueFrom, map, of, throwError } from 'rxjs'; import { createMockBrowserDriver } from '../browsers/mock'; -import type { ConfigType } from '../config'; import { createMockLayout } from '../layouts/mock'; import { EventLogger } from './event_logger'; import { ScreenshotObservableHandler, ScreenshotObservableOptions } from './observable'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/observable.ts b/x-pack/plugins/screenshotting/server/screenshots/observable.ts index 8c9854f376706..0b7382a5770b5 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/observable.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/observable.ts @@ -6,8 +6,17 @@ */ import type { Headers } from '@kbn/core/server'; -import { defer, forkJoin, Observable, throwError } from 'rxjs'; -import { catchError, mergeMap, switchMapTo, timeoutWith } from 'rxjs'; +import { ConfigType, durationToNumber as toNumber } from '@kbn/screenshotting-server'; +import { + catchError, + defer, + forkJoin, + mergeMap, + Observable, + switchMapTo, + throwError, + timeoutWith, +} from 'rxjs'; import { errors } from '../../common'; import { Context, @@ -15,7 +24,6 @@ import { getChromiumDisconnectedError, HeadlessChromiumDriver, } from '../browsers'; -import { ConfigType, durationToNumber as toNumber } from '../config'; import type { PdfScreenshotOptions } from '../formats'; import { Layout } from '../layouts'; import { Actions, EventLogger } from './event_logger'; diff --git a/x-pack/plugins/screenshotting/server/screenshots/screenshots.test.ts b/x-pack/plugins/screenshotting/server/screenshots/screenshots.test.ts index 9ba12f2211cfa..4f217ef96c611 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/screenshots.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/screenshots.test.ts @@ -11,12 +11,12 @@ import type { PackageInfo } from '@kbn/core/server'; import type { Logger } from '@kbn/logging'; import { loggerMock } from '@kbn/logging-mocks'; import type { ScreenshotModePluginSetup } from '@kbn/screenshot-mode-plugin/server'; +import type { ConfigType } from '@kbn/screenshotting-server'; import puppeteer from 'puppeteer'; import * as Rx from 'rxjs'; import { firstValueFrom } from 'rxjs'; import type { PngScreenshotOptions } from '..'; import { HeadlessChromiumDriverFactory } from '../browsers'; -import type { ConfigType } from '../config'; import { Screenshots } from './screenshots'; jest.mock('puppeteer'); diff --git a/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts b/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts index 24a00ed00108a..abc731b4fbcfe 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/screenshots.ts @@ -8,13 +8,28 @@ import ipaddr from 'ipaddr.js'; import { defaultsDeep, sum } from 'lodash'; import moment from 'moment'; -import { Observable, from, of, throwError } from 'rxjs'; -import { catchError, concatMap, first, map, mergeMap, take, takeUntil, tap, toArray } from 'rxjs'; +import { + Observable, + catchError, + concatMap, + first, + from, + map, + mergeMap, + of, + take, + takeUntil, + tap, + throwError, + toArray, +} from 'rxjs'; import type { CloudSetup } from '@kbn/cloud-plugin/server'; import type { HttpServiceSetup, Logger, PackageInfo } from '@kbn/core/server'; import { Semaphore } from '@kbn/std'; +import type { ConfigType } from '@kbn/screenshotting-server'; +import { durationToNumber } from '@kbn/screenshotting-server'; import { CaptureResult, ScreenshotOptions, ScreenshotResult } from '.'; import { SCREENSHOTTING_APP_ID, @@ -24,8 +39,6 @@ import { } from '../../common'; import { HeadlessChromiumDriverFactory } from '../browsers'; import { systemHasInsufficientMemory } from '../cloud'; -import type { ConfigType } from '../config'; -import { durationToNumber } from '../config'; import { PdfScreenshotOptions, PdfScreenshotResult, diff --git a/x-pack/plugins/screenshotting/server/utils.ts b/x-pack/plugins/screenshotting/server/utils.ts index cee0837e067a1..40262b1e65e7b 100644 --- a/x-pack/plugins/screenshotting/server/utils.ts +++ b/x-pack/plugins/screenshotting/server/utils.ts @@ -5,22 +5,11 @@ * 2.0. */ -import os from 'os'; -import { ChromiumArchivePaths, download as baseDownload, install as baseInstall } from './browsers'; +import { ChromiumArchivePaths } from '@kbn/screenshotting-server'; +import { download as baseDownload, install as baseInstall } from './browsers'; const paths = new ChromiumArchivePaths(); -export const getChromiumPackage = () => { - const platform = process.platform; - const architecture = os.arch(); - - const chromiumPackageInfo = paths.find(process.platform, architecture); - if (!chromiumPackageInfo) { - throw new Error(`Unsupported platform: ${platform}-${architecture}`); - } - return chromiumPackageInfo; -}; - export const download = baseDownload.bind(undefined, paths); export const install = baseInstall.bind(undefined, paths); diff --git a/x-pack/plugins/screenshotting/tsconfig.json b/x-pack/plugins/screenshotting/tsconfig.json index 8421b0c9fdd7d..5e37b84bbf2e9 100644 --- a/x-pack/plugins/screenshotting/tsconfig.json +++ b/x-pack/plugins/screenshotting/tsconfig.json @@ -16,17 +16,16 @@ "@kbn/screenshot-mode-plugin", "@kbn/cloud-plugin", "@kbn/utility-types", - "@kbn/config-schema", "@kbn/logging", "@kbn/std", "@kbn/i18n", "@kbn/utils", - "@kbn/safer-lodash-set", "@kbn/core-logging-server-mocks", "@kbn/logging-mocks", "@kbn/core-http-server", "@kbn/core-plugins-server", "@kbn/task-manager-plugin", + "@kbn/screenshotting-server", ], "exclude": [ "target/**/*", diff --git a/yarn.lock b/yarn.lock index 549fd4e2e86bf..d6eaf10e8d0eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6212,6 +6212,10 @@ version "0.0.0" uid "" +"@kbn/screenshotting-server@link:packages/kbn-screenshotting-server": + version "0.0.0" + uid "" + "@kbn/search-api-panels@link:packages/kbn-search-api-panels": version "0.0.0" uid ""