From fd3fe9bd294f292b6f6c37452d2feb54d7cdca33 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Fri, 14 Jul 2023 09:16:47 +0200 Subject: [PATCH 1/7] Add buildFlavor to package info --- packages/kbn-config/src/env.ts | 1 + packages/kbn-config/src/types.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/packages/kbn-config/src/env.ts b/packages/kbn-config/src/env.ts index 64d147d9a4a85..99728f0dfc413 100644 --- a/packages/kbn-config/src/env.ts +++ b/packages/kbn-config/src/env.ts @@ -124,6 +124,7 @@ export class Env { version: pkg.version, dist: isKibanaDistributable, buildDate: isKibanaDistributable ? new Date(pkg.build.date) : new Date(), + buildFlavor: this.cliArgs.serverless ? 'serverless' : 'traditional', }); } } diff --git a/packages/kbn-config/src/types.ts b/packages/kbn-config/src/types.ts index dcb959f30cd01..f9038a1a7fd26 100644 --- a/packages/kbn-config/src/types.ts +++ b/packages/kbn-config/src/types.ts @@ -15,6 +15,7 @@ export interface PackageInfo { buildNum: number; buildSha: string; buildDate: Date; + buildFlavor: BuildFlavor; dist: boolean; } @@ -26,3 +27,5 @@ export interface EnvironmentMode { dev: boolean; prod: boolean; } + +export type BuildFlavor = 'serverless' | 'traditional'; From 2ee7826a95b787308c72b4be9463154c118a5afd Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Fri, 14 Jul 2023 09:27:03 +0200 Subject: [PATCH 2/7] start fixing usages --- .../core/base/core-base-browser-mocks/src/core_context.mock.ts | 1 + .../src/bootstrap/bootstrap_renderer.test.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/core/base/core-base-browser-mocks/src/core_context.mock.ts b/packages/core/base/core-base-browser-mocks/src/core_context.mock.ts index 4de9ca33e0eef..53933d4146df3 100644 --- a/packages/core/base/core-base-browser-mocks/src/core_context.mock.ts +++ b/packages/core/base/core-base-browser-mocks/src/core_context.mock.ts @@ -26,6 +26,7 @@ function createCoreContext({ production = false }: { production?: boolean } = {} buildSha: 'buildSha', dist: false, buildDate: new Date('2023-05-15T23:12:09.000Z'), + buildFlavor: 'traditional', }, }, }; diff --git a/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.test.ts b/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.test.ts index d7f4bb9007910..668cbc96904fe 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.test.ts +++ b/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.test.ts @@ -28,6 +28,7 @@ const createPackageInfo = (parts: Partial = {}): PackageInfo => ({ buildDate: new Date('2023-05-15T23:12:09.000Z'), dist: false, version: '8.0.0', + buildFlavor: 'traditional', ...parts, }); From 2a17a51ca4321302ecffeb3152e857e4a21d6d7f Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Fri, 14 Jul 2023 09:40:04 +0200 Subject: [PATCH 3/7] fixing usages - 2 --- .../src/bundle_routes/register_bundle_routes.test.ts | 3 ++- .../src/test_helpers/mocks.ts | 1 + .../src/discovery/plugin_manifest_parser.test.ts | 7 ++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core/apps/core-apps-server-internal/src/bundle_routes/register_bundle_routes.test.ts b/packages/core/apps/core-apps-server-internal/src/bundle_routes/register_bundle_routes.test.ts index 7f444d3221a38..e6550f6e86cb6 100644 --- a/packages/core/apps/core-apps-server-internal/src/bundle_routes/register_bundle_routes.test.ts +++ b/packages/core/apps/core-apps-server-internal/src/bundle_routes/register_bundle_routes.test.ts @@ -15,13 +15,14 @@ import { registerBundleRoutes } from './register_bundle_routes'; import { FileHashCache } from './file_hash_cache'; const createPackageInfo = (parts: Partial = {}): PackageInfo => ({ - ...parts, buildNum: 42, buildSha: 'sha', dist: true, branch: 'master', version: '8.0.0', buildDate: new Date('2023-05-15T23:12:09.000Z'), + buildFlavor: 'traditional', + ...parts, }); const createUiPlugins = (...ids: string[]): UiPlugins => ({ diff --git a/packages/core/plugins/core-plugins-browser-internal/src/test_helpers/mocks.ts b/packages/core/plugins/core-plugins-browser-internal/src/test_helpers/mocks.ts index aea293345175f..787a7d7678194 100644 --- a/packages/core/plugins/core-plugins-browser-internal/src/test_helpers/mocks.ts +++ b/packages/core/plugins/core-plugins-browser-internal/src/test_helpers/mocks.ts @@ -25,6 +25,7 @@ export const createPluginInitializerContextMock = (config: unknown = {}) => { buildSha: 'buildSha', dist: false, buildDate: new Date('2023-05-15T23:12:09.000Z'), + buildFlavor: 'traditional', }, }, logger: loggerMock.create(), diff --git a/packages/core/plugins/core-plugins-server-internal/src/discovery/plugin_manifest_parser.test.ts b/packages/core/plugins/core-plugins-server-internal/src/discovery/plugin_manifest_parser.test.ts index 9f2cd298adfbd..35cff51f820f9 100644 --- a/packages/core/plugins/core-plugins-server-internal/src/discovery/plugin_manifest_parser.test.ts +++ b/packages/core/plugins/core-plugins-server-internal/src/discovery/plugin_manifest_parser.test.ts @@ -8,20 +8,21 @@ import { mockReadFile } from './plugin_manifest_parser.test.mocks'; -import { PluginDiscoveryErrorType } from './plugin_discovery_error'; - import { resolve } from 'path'; +import type { PackageInfo } from '@kbn/config'; +import { PluginDiscoveryErrorType } from './plugin_discovery_error'; import { parseManifest } from './plugin_manifest_parser'; const pluginPath = resolve('path', 'existent-dir'); const pluginManifestPath = resolve(pluginPath, 'kibana.json'); -const packageInfo = { +const packageInfo: PackageInfo = { branch: 'master', buildNum: 1, buildSha: '', version: '7.0.0-alpha1', dist: false, buildDate: new Date('2023-05-15T23:12:09.000Z'), + buildFlavor: 'traditional', }; afterEach(() => { From 8aac0df9fa5b35cb654d19e386b8cc5ff043da16 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Fri, 14 Jul 2023 11:39:03 +0200 Subject: [PATCH 4/7] fixing usages - 3 --- .../src/plugins_service.mock.ts | 1 + .../__snapshots__/rendering_service.test.ts.snap | 14 ++++++++++++++ .../src/rendering_service.test.ts | 1 + 3 files changed, 16 insertions(+) diff --git a/packages/core/plugins/core-plugins-browser-mocks/src/plugins_service.mock.ts b/packages/core/plugins/core-plugins-browser-mocks/src/plugins_service.mock.ts index 45154fa0165d5..56ea09aed483c 100644 --- a/packages/core/plugins/core-plugins-browser-mocks/src/plugins_service.mock.ts +++ b/packages/core/plugins/core-plugins-browser-mocks/src/plugins_service.mock.ts @@ -43,6 +43,7 @@ const createPluginInitializerContextMock = (config: unknown = {}) => { buildSha: 'buildSha', dist: false, buildDate: new Date('2023-05-15T23:12:09.000Z'), + buildFlavor: 'serverless', }, }, logger: loggerMock.create(), diff --git a/packages/core/rendering/core-rendering-server-internal/src/__snapshots__/rendering_service.test.ts.snap b/packages/core/rendering/core-rendering-server-internal/src/__snapshots__/rendering_service.test.ts.snap index 84f58863363a7..3428f9842d44f 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/__snapshots__/rendering_service.test.ts.snap +++ b/packages/core/rendering/core-rendering-server-internal/src/__snapshots__/rendering_service.test.ts.snap @@ -20,6 +20,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -82,6 +83,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -148,6 +150,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -210,6 +213,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -272,6 +276,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -338,6 +343,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -400,6 +406,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -462,6 +469,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -528,6 +536,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -598,6 +607,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -660,6 +670,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -726,6 +737,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -796,6 +808,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, @@ -862,6 +875,7 @@ Object { "packageInfo": Object { "branch": Any, "buildDate": "2023-05-15T23:12:09.000Z", + "buildFlavor": Any, "buildNum": Any, "buildSha": Any, "dist": Any, diff --git a/packages/core/rendering/core-rendering-server-internal/src/rendering_service.test.ts b/packages/core/rendering/core-rendering-server-internal/src/rendering_service.test.ts index 81a1cea933f19..193ad54918d9f 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/rendering_service.test.ts +++ b/packages/core/rendering/core-rendering-server-internal/src/rendering_service.test.ts @@ -45,6 +45,7 @@ const INJECTED_METADATA = { dist: expect.any(Boolean), version: expect.any(String), buildDate: new Date(BUILD_DATE).toISOString(), + buildFlavor: expect.any(String), }, }, }; From 02f48ec3f78abde9c175c5be1827ee15bfde0155 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Fri, 14 Jul 2023 11:55:55 +0200 Subject: [PATCH 5/7] fixing usages - 4 --- src/core/server/integration_tests/status/routes/status.test.ts | 1 + src/core/server/mocks.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/core/server/integration_tests/status/routes/status.test.ts b/src/core/server/integration_tests/status/routes/status.test.ts index 41d1342090d7f..0d7d6a84e2497 100644 --- a/src/core/server/integration_tests/status/routes/status.test.ts +++ b/src/core/server/integration_tests/status/routes/status.test.ts @@ -86,6 +86,7 @@ describe('GET /api/status', () => { dist: true, version: '9.9.9-SNAPSHOT', buildDate: new Date('2023-05-15T23:12:09.000Z'), + buildFlavor: 'traditional', }, serverName: 'xkibana', uuid: 'xxxx-xxxxx', diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index 00f2497ab1dd8..62dd66f63ec62 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -100,6 +100,7 @@ function pluginInitializerContextMock(config: T = {} as T) { buildSha: 'buildSha', dist: false, buildDate: new Date('2023-05-15T23:12:09.000Z'), + buildFlavor: 'traditional', }, instanceUuid: 'instance-uuid', configs: ['/some/path/to/config/kibana.yml'], From 2fd0a000fe0b1ba702b9d048a996c259cf523a78 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Fri, 14 Jul 2023 12:57:33 +0200 Subject: [PATCH 6/7] fixing usages - 5 --- .../formats/pdf/pdf_maker/integration_tests/pdfmaker.test.ts | 1 + x-pack/plugins/screenshotting/server/screenshots/index.test.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/x-pack/plugins/screenshotting/server/formats/pdf/pdf_maker/integration_tests/pdfmaker.test.ts b/x-pack/plugins/screenshotting/server/formats/pdf/pdf_maker/integration_tests/pdfmaker.test.ts index cdd8350c0ae9a..2243f68b7ad71 100644 --- a/x-pack/plugins/screenshotting/server/formats/pdf/pdf_maker/integration_tests/pdfmaker.test.ts +++ b/x-pack/plugins/screenshotting/server/formats/pdf/pdf_maker/integration_tests/pdfmaker.test.ts @@ -36,6 +36,7 @@ describe('PdfMaker', () => { dist: false, version: '1000.0.0', buildDate: new Date('2023-05-15T23:12:09.000Z'), + buildFlavor: 'traditional', }; pdf = new PdfMaker(layout, undefined, packageInfo, logger); }); diff --git a/x-pack/plugins/screenshotting/server/screenshots/index.test.ts b/x-pack/plugins/screenshotting/server/screenshots/index.test.ts index bdaf96e710f7e..8208d7e2c451f 100644 --- a/x-pack/plugins/screenshotting/server/screenshots/index.test.ts +++ b/x-pack/plugins/screenshotting/server/screenshots/index.test.ts @@ -58,6 +58,7 @@ describe('Screenshot Observable Pipeline', () => { dist: false, version: '5000.0.0', buildDate: new Date('2023-05-15T23:12:09.000Z'), + buildFlavor: 'traditional', }; options = { browserTimezone: 'UTC', From f50a035d85984d176963a3068bcbe6de6b7a1ba0 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Fri, 14 Jul 2023 13:52:57 +0200 Subject: [PATCH 7/7] add env tests --- .../src/__snapshots__/env.test.ts.snap | 6 +++ packages/kbn-config/src/env.test.ts | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/packages/kbn-config/src/__snapshots__/env.test.ts.snap b/packages/kbn-config/src/__snapshots__/env.test.ts.snap index 39aae1dd9b2ff..e5d5a3816ced3 100644 --- a/packages/kbn-config/src/__snapshots__/env.test.ts.snap +++ b/packages/kbn-config/src/__snapshots__/env.test.ts.snap @@ -29,6 +29,7 @@ Env { "packageInfo": Object { "branch": "feature-v1", "buildDate": 2023-05-15T23:12:09.000Z, + "buildFlavor": "traditional", "buildNum": 9007199254740991, "buildSha": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "dist": false, @@ -71,6 +72,7 @@ Env { "packageInfo": Object { "branch": "feature-v1", "buildDate": 2023-05-15T23:12:09.000Z, + "buildFlavor": "traditional", "buildNum": 9007199254740991, "buildSha": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "dist": false, @@ -112,6 +114,7 @@ Env { "packageInfo": Object { "branch": "some-branch", "buildDate": 2023-05-15T23:12:09.000Z, + "buildFlavor": "traditional", "buildNum": 9007199254740991, "buildSha": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "dist": false, @@ -153,6 +156,7 @@ Env { "packageInfo": Object { "branch": "feature-v1", "buildDate": 2023-05-15T23:12:09.000Z, + "buildFlavor": "traditional", "buildNum": 100, "buildSha": "feature-v1-build-sha", "dist": true, @@ -194,6 +198,7 @@ Env { "packageInfo": Object { "branch": "feature-v1", "buildDate": 2023-05-15T23:12:09.000Z, + "buildFlavor": "traditional", "buildNum": 9007199254740991, "buildSha": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "dist": false, @@ -235,6 +240,7 @@ Env { "packageInfo": Object { "branch": "feature-v1", "buildDate": 2023-05-15T23:12:09.000Z, + "buildFlavor": "traditional", "buildNum": 100, "buildSha": "feature-v1-build-sha", "dist": true, diff --git a/packages/kbn-config/src/env.test.ts b/packages/kbn-config/src/env.test.ts index 5203c34b73214..7c301ff83e6f4 100644 --- a/packages/kbn-config/src/env.test.ts +++ b/packages/kbn-config/src/env.test.ts @@ -208,3 +208,43 @@ test('pluginSearchPaths only includes kibana-extra, regardless of plugin filters expect(env4.pluginSearchPaths).toEqual(['/some/home/kibana-extra', '/some/home/dir/plugins']); }); + +describe('packageInfo.buildFlavor', () => { + it('is set to `serverless` when the `serverless` cli flag is `true`', () => { + mockPackage.raw = { + branch: 'some-branch', + version: 'some-version', + }; + + const env = Env.createDefault( + REPO_ROOT, + getEnvOptions({ + configs: ['/test/cwd/config/kibana.yml'], + cliArgs: { + serverless: true, + }, + }) + ); + + expect(env.packageInfo.buildFlavor).toEqual('serverless'); + }); + + it('is set to `traditional` when the `serverless` cli flag is `false`', () => { + mockPackage.raw = { + branch: 'some-branch', + version: 'some-version', + }; + + const env = Env.createDefault( + REPO_ROOT, + getEnvOptions({ + configs: ['/test/cwd/config/kibana.yml'], + cliArgs: { + serverless: false, + }, + }) + ); + + expect(env.packageInfo.buildFlavor).toEqual('traditional'); + }); +});