From ab486aff0506a93bb249288e126c80f2cf8b9a81 Mon Sep 17 00:00:00 2001 From: Pierre Gayvallet Date: Thu, 20 Jul 2023 12:33:28 +0200 Subject: [PATCH] [Env] Add `buildFlavor` to package info (#161930) ## Summary Add a `buildFavor` property to `Env` (accessible from the plugin's initializer context), Mimicking the idea of ES's `version.buildFlavor` field. Note: this is not supposed to be a replacement for feature flags, but can be useful when wanting to toggle features based on actual capabilities of our serverless product. Also, we already expose this value through the configuration via the `serverless` context value, so it now adds another way to access the information. --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../register_bundle_routes.test.ts | 3 +- .../src/core_context.mock.ts | 1 + .../src/test_helpers/mocks.ts | 1 + .../src/plugins_service.mock.ts | 1 + .../discovery/plugin_manifest_parser.test.ts | 7 ++-- .../rendering_service.test.ts.snap | 14 +++++++ .../src/bootstrap/bootstrap_renderer.test.ts | 1 + .../src/rendering_service.test.ts | 1 + .../src/__snapshots__/env.test.ts.snap | 6 +++ packages/kbn-config/src/env.test.ts | 40 +++++++++++++++++++ packages/kbn-config/src/env.ts | 1 + packages/kbn-config/src/types.ts | 3 ++ .../status/routes/status.test.ts | 1 + src/core/server/mocks.ts | 1 + .../integration_tests/pdfmaker.test.ts | 1 + .../server/screenshots/index.test.ts | 1 + 16 files changed, 79 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/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/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-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/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(() => { 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/bootstrap/bootstrap_renderer.test.ts b/packages/core/rendering/core-rendering-server-internal/src/bootstrap/bootstrap_renderer.test.ts index 5140891d1eee0..df9589b043d2b 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, }); 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), }, }, }; 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'); + }); +}); 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'; 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'], 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',