Skip to content

Commit

Permalink
[Env] Add buildFlavor to package info (#161930)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
pgayvallet and kibanamachine authored Jul 20, 2023
1 parent e79f244 commit ab486af
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import { registerBundleRoutes } from './register_bundle_routes';
import { FileHashCache } from './file_hash_cache';

const createPackageInfo = (parts: Partial<PackageInfo> = {}): 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 => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const createPackageInfo = (parts: Partial<PackageInfo> = {}): PackageInfo => ({
buildDate: new Date('2023-05-15T23:12:09.000Z'),
dist: false,
version: '8.0.0',
buildFlavor: 'traditional',
...parts,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
};
Expand Down
6 changes: 6 additions & 0 deletions packages/kbn-config/src/__snapshots__/env.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions packages/kbn-config/src/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
1 change: 1 addition & 0 deletions packages/kbn-config/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
}
}
3 changes: 3 additions & 0 deletions packages/kbn-config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface PackageInfo {
buildNum: number;
buildSha: string;
buildDate: Date;
buildFlavor: BuildFlavor;
dist: boolean;
}

Expand All @@ -26,3 +27,5 @@ export interface EnvironmentMode {
dev: boolean;
prod: boolean;
}

export type BuildFlavor = 'serverless' | 'traditional';
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function pluginInitializerContextMock<T>(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'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit ab486af

Please sign in to comment.