Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Env] Add buildFlavor to package info #161930

Merged
merged 8 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

@pgayvallet pgayvallet Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual change. Everything else is just adapting the test usages.

dist: boolean;
}

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

export type BuildFlavor = 'serverless' | 'traditional';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with traditional for the "unflavored" version, but I can go with something else if we have a better idea.

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