Skip to content

Commit

Permalink
Merge branch 'master' into kertal-pr-2020-01-18-discover-persist-char…
Browse files Browse the repository at this point in the history
…t-state
  • Loading branch information
kibanamachine authored Feb 2, 2021
2 parents 4e4637f + 8ef8f3b commit b76f033
Show file tree
Hide file tree
Showing 203 changed files with 5,552 additions and 3,654 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pageLoadAssetSize:
tileMap: 65337
timelion: 29920
transform: 41007
triggersActionsUi: 170001
triggersActionsUi: 186732
uiActions: 97717
uiActionsEnhanced: 313011
upgradeAssistant: 81241
Expand Down
54 changes: 38 additions & 16 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47961,11 +47961,13 @@ __webpack_require__.r(__webpack_exports__);
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "installBazelTools", function() { return installBazelTools; });
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _child_process__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(319);
/* harmony import */ var _fs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(131);
/* harmony import */ var _log__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(246);
/* harmony import */ var dedent__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
/* harmony import */ var dedent__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(dedent__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _child_process__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(319);
/* harmony import */ var _fs__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(131);
/* harmony import */ var _log__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(246);
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
Expand All @@ -47978,8 +47980,9 @@ __webpack_require__.r(__webpack_exports__);




async function readBazelToolsVersionFile(repoRootPath, versionFilename) {
const version = (await Object(_fs__WEBPACK_IMPORTED_MODULE_2__["readFile"])(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(repoRootPath, versionFilename))).toString().split('\n')[0];
const version = (await Object(_fs__WEBPACK_IMPORTED_MODULE_3__["readFile"])(Object(path__WEBPACK_IMPORTED_MODULE_1__["resolve"])(repoRootPath, versionFilename))).toString().split('\n')[0];

if (!version) {
throw new Error(`[bazel_tools] Failed on reading bazel tools versions\n ${versionFilename} file do not contain any version set`);
Expand All @@ -47988,30 +47991,49 @@ async function readBazelToolsVersionFile(repoRootPath, versionFilename) {
return version;
}

async function isBazelBinAvailable() {
try {
await Object(_child_process__WEBPACK_IMPORTED_MODULE_2__["spawn"])('bazel', ['--version'], {
stdio: 'pipe'
});
return true;
} catch {
return false;
}
}

async function installBazelTools(repoRootPath) {
_log__WEBPACK_IMPORTED_MODULE_3__["log"].debug(`[bazel_tools] reading bazel tools versions from version files`);
_log__WEBPACK_IMPORTED_MODULE_4__["log"].debug(`[bazel_tools] reading bazel tools versions from version files`);
const bazeliskVersion = await readBazelToolsVersionFile(repoRootPath, '.bazeliskversion');
const bazelVersion = await readBazelToolsVersionFile(repoRootPath, '.bazelversion'); // Check what globals are installed

_log__WEBPACK_IMPORTED_MODULE_3__["log"].debug(`[bazel_tools] verify if bazelisk is installed`);
_log__WEBPACK_IMPORTED_MODULE_4__["log"].debug(`[bazel_tools] verify if bazelisk is installed`);
const {
stdout
} = await Object(_child_process__WEBPACK_IMPORTED_MODULE_1__["spawn"])('yarn', ['global', 'list'], {
stdout: bazeliskPkgInstallStdout
} = await Object(_child_process__WEBPACK_IMPORTED_MODULE_2__["spawn"])('yarn', ['global', 'list'], {
stdio: 'pipe'
}); // Install bazelisk if not installed
});
const isBazelBinAlreadyAvailable = await isBazelBinAvailable(); // Install bazelisk if not installed

if (!stdout.includes(`@bazel/bazelisk@${bazeliskVersion}`)) {
_log__WEBPACK_IMPORTED_MODULE_3__["log"].info(`[bazel_tools] installing Bazel tools`);
_log__WEBPACK_IMPORTED_MODULE_3__["log"].debug(`[bazel_tools] bazelisk is not installed. Installing @bazel/bazelisk@${bazeliskVersion} and bazel@${bazelVersion}`);
await Object(_child_process__WEBPACK_IMPORTED_MODULE_1__["spawn"])('yarn', ['global', 'add', `@bazel/bazelisk@${bazeliskVersion}`], {
if (!bazeliskPkgInstallStdout.includes(`@bazel/bazelisk@${bazeliskVersion}`) || !isBazelBinAlreadyAvailable) {
_log__WEBPACK_IMPORTED_MODULE_4__["log"].info(`[bazel_tools] installing Bazel tools`);
_log__WEBPACK_IMPORTED_MODULE_4__["log"].debug(`[bazel_tools] bazelisk is not installed. Installing @bazel/bazelisk@${bazeliskVersion} and bazel@${bazelVersion}`);
await Object(_child_process__WEBPACK_IMPORTED_MODULE_2__["spawn"])('yarn', ['global', 'add', `@bazel/bazelisk@${bazeliskVersion}`], {
env: {
USE_BAZEL_VERSION: bazelVersion
},
stdio: 'pipe'
});
const isBazelBinAvailableAfterInstall = await isBazelBinAvailable();

if (!isBazelBinAvailableAfterInstall) {
throw new Error(dedent__WEBPACK_IMPORTED_MODULE_0___default.a`
[bazel_tools] an error occurred when installing the Bazel tools. Please make sure 'yarn global bin' is on your $PATH, otherwise just add it there
`);
}
}

_log__WEBPACK_IMPORTED_MODULE_3__["log"].success(`[bazel_tools] all bazel tools are correctly installed`);
_log__WEBPACK_IMPORTED_MODULE_4__["log"].success(`[bazel_tools] all bazel tools are correctly installed`);
}

/***/ }),
Expand Down
29 changes: 27 additions & 2 deletions packages/kbn-pm/src/utils/bazel/install_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Public License, v 1.
*/

import dedent from 'dedent';
import { resolve } from 'path';
import { spawn } from '../child_process';
import { readFile } from '../fs';
Expand All @@ -25,17 +26,34 @@ async function readBazelToolsVersionFile(repoRootPath: string, versionFilename:
return version;
}

async function isBazelBinAvailable() {
try {
await spawn('bazel', ['--version'], { stdio: 'pipe' });

return true;
} catch {
return false;
}
}

export async function installBazelTools(repoRootPath: string) {
log.debug(`[bazel_tools] reading bazel tools versions from version files`);
const bazeliskVersion = await readBazelToolsVersionFile(repoRootPath, '.bazeliskversion');
const bazelVersion = await readBazelToolsVersionFile(repoRootPath, '.bazelversion');

// Check what globals are installed
log.debug(`[bazel_tools] verify if bazelisk is installed`);
const { stdout } = await spawn('yarn', ['global', 'list'], { stdio: 'pipe' });
const { stdout: bazeliskPkgInstallStdout } = await spawn('yarn', ['global', 'list'], {
stdio: 'pipe',
});

const isBazelBinAlreadyAvailable = await isBazelBinAvailable();

// Install bazelisk if not installed
if (!stdout.includes(`@bazel/bazelisk@${bazeliskVersion}`)) {
if (
!bazeliskPkgInstallStdout.includes(`@bazel/bazelisk@${bazeliskVersion}`) ||
!isBazelBinAlreadyAvailable
) {
log.info(`[bazel_tools] installing Bazel tools`);

log.debug(
Expand All @@ -47,6 +65,13 @@ export async function installBazelTools(repoRootPath: string) {
},
stdio: 'pipe',
});

const isBazelBinAvailableAfterInstall = await isBazelBinAvailable();
if (!isBazelBinAvailableAfterInstall) {
throw new Error(dedent`
[bazel_tools] an error occurred when installing the Bazel tools. Please make sure 'yarn global bin' is on your $PATH, otherwise just add it there
`);
}
}

log.success(`[bazel_tools] all bazel tools are correctly installed`);
Expand Down
51 changes: 27 additions & 24 deletions preinstall_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,37 @@
* Public License, v 1.
*/

const isUsingNpm = process.env.npm_config_git !== undefined;
(() => {
const isUsingNpm = process.env.npm_config_git !== undefined;

if (isUsingNpm) {
throw `Use Yarn instead of npm, see Kibana's contributing guidelines`;
}

// The value of the `npm_config_argv` env for each command:
//
// - `npm install`: '{"remain":[],"cooked":["install"],"original":[]}'
// - `yarn`: '{"remain":[],"cooked":["install"],"original":[]}'
// - `yarn kbn bootstrap`: '{"remain":[],"cooked":["run","kbn"],"original":["kbn","bootstrap"]}'
const rawArgv = process.env.npm_config_argv;

if (rawArgv === undefined) {
return;
}
if (isUsingNpm) {
throw `Use Yarn instead of npm, see Kibana's contributing guidelines`;
}

try {
const argv = JSON.parse(rawArgv);
// The value of the `npm_config_argv` env for each command:
//
// - `npm install`: '{"remain":[],"cooked":["install"],"original":[]}'
// - `yarn`: '{"remain":[],"cooked":["install"],"original":[]}'
// - `yarn kbn bootstrap`: '{"remain":[],"cooked":["run","kbn"],"original":["kbn","bootstrap"]}'
const rawArgv = process.env.npm_config_argv;

if (argv.cooked.includes('kbn')) {
// all good, trying to install deps using `kbn`
if (rawArgv === undefined) {
return;
}

if (argv.cooked.includes('install')) {
console.log('\nWARNING: When installing dependencies, prefer `yarn kbn bootstrap`\n');
try {
const argv = JSON.parse(rawArgv);

// allow dependencies to be installed with `yarn kbn bootstrap` or `bazel run @nodejs//:yarn` (called under the hood by bazel)
if (argv.cooked.includes('kbn') || !!process.env.BAZEL_YARN_INSTALL) {
// all good, trying to install deps using `kbn` or bazel directly
return;
}

if (argv.cooked.includes('install')) {
console.log('\nWARNING: When installing dependencies, prefer `yarn kbn bootstrap`\n');
}
} catch (e) {
// if it fails we do nothing, as this is just intended to be a helpful message
}
} catch (e) {
// if it fails we do nothing, as this is just intended to be a helpful message
}
})();
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ import { loggingSystemMock } from '../../../logging/logging_system.mock';
import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry';
import { SavedObjectsType } from '../../types';
import { errors as esErrors } from '@elastic/elasticsearch';
import { DocumentMigrator } from '../core/document_migrator';
jest.mock('../core/document_migrator', () => {
return {
// Create a mock for spying on the constructor
DocumentMigrator: jest.fn().mockImplementation((...args) => {
const { DocumentMigrator: RealDocMigrator } = jest.requireActual('../core/document_migrator');
return new RealDocMigrator(args[0]);
}),
};
});

const createRegistry = (types: Array<Partial<SavedObjectsType>>) => {
const registry = new SavedObjectTypeRegistry();
Expand All @@ -31,12 +41,16 @@ const createRegistry = (types: Array<Partial<SavedObjectsType>>) => {
};

describe('KibanaMigrator', () => {
beforeEach(() => {
(DocumentMigrator as jest.Mock).mockClear();
});
describe('constructor', () => {
it('coerces the current Kibana version if it has a hyphen', () => {
const options = mockOptions();
options.kibanaVersion = '3.2.1-SNAPSHOT';
const migrator = new KibanaMigrator(options);
expect(migrator.kibanaVersion).toEqual('3.2.1');
expect((DocumentMigrator as jest.Mock).mock.calls[0][0].kibanaVersion).toEqual('3.2.1');
});
});
describe('getActiveMappings', () => {
Expand Down Expand Up @@ -105,8 +119,8 @@ describe('KibanaMigrator', () => {

const migrator = new KibanaMigrator(options);

expect(() => migrator.runMigrations()).rejects.toThrow(
/Migrations are not ready. Make sure prepareMigrations is called first./i
await expect(() => migrator.runMigrations()).toThrowErrorMatchingInlineSnapshot(
`"Migrations are not ready. Make sure prepareMigrations is called first."`
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

import { BehaviorSubject } from 'rxjs';
import Semver from 'semver';
import { KibanaConfigType } from '../../../kibana_config';
import { ElasticsearchClient } from '../../../elasticsearch';
import { Logger } from '../../../logging';
Expand Down Expand Up @@ -97,7 +98,7 @@ export class KibanaMigrator {
this.log = logger;
this.kibanaVersion = kibanaVersion.split('-')[0]; // coerce a semver-like string (x.y.z-SNAPSHOT) or prerelease version (x.y.z-alpha) to a regular semver (x.y.z);
this.documentMigrator = new DocumentMigrator({
kibanaVersion,
kibanaVersion: this.kibanaVersion,
typeRegistry,
log: this.log,
});
Expand Down Expand Up @@ -163,6 +164,15 @@ export class KibanaMigrator {
registry: this.typeRegistry,
});

this.log.debug('Applying registered migrations for the following saved object types:');
Object.entries(this.documentMigrator.migrationVersion)
.sort(([t1, v1], [t2, v2]) => {
return Semver.compare(v1, v2);
})
.forEach(([type, migrationVersion]) => {
this.log.debug(`migrationVersion: ${migrationVersion} saved object type: ${type}`);
});

const migrators = Object.keys(indexMap).map((index) => {
// TODO migrationsV2: remove old migrations algorithm
if (this.savedObjectsConfig.enableV2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { resolve } from 'path';
import execa from 'execa';
import expect from '@kbn/expect';
import shell from 'shelljs';

const ROOT_DIR = resolve(__dirname, '../../../../..');
Expand Down Expand Up @@ -38,11 +37,14 @@ describe('Team Assignment', () => {
describe(`when the codeowners file contains #CC#`, () => {
it(`should strip the prefix and still drill down through the fs`, async () => {
const { stdout } = await execa('grep', ['tre', teamAssignmentsPath], { cwd: ROOT_DIR });
expect(stdout).to.be(`x-pack/plugins/code/jest.config.js kibana-tre
x-pack/plugins/code/server/config.ts kibana-tre
x-pack/plugins/code/server/index.ts kibana-tre
x-pack/plugins/code/server/plugin.test.ts kibana-tre
x-pack/plugins/code/server/plugin.ts kibana-tre`);
const lines = stdout.split('\n').filter((line) => !line.includes('/target'));
expect(lines).toEqual([
'x-pack/plugins/code/jest.config.js kibana-tre',
'x-pack/plugins/code/server/config.ts kibana-tre',
'x-pack/plugins/code/server/index.ts kibana-tre',
'x-pack/plugins/code/server/plugin.test.ts kibana-tre',
'x-pack/plugins/code/server/plugin.ts kibana-tre',
]);
});
});
});
23 changes: 23 additions & 0 deletions src/plugins/kibana_overview/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true
},
"include": [
"public/**/*",
"common/**/*",
],
"references": [
{ "path": "../../core/tsconfig.json" },
{ "path": "../../plugins/navigation/tsconfig.json" },
{ "path": "../../plugins/data/tsconfig.json" },
{ "path": "../../plugins/home/tsconfig.json" },
{ "path": "../../plugins/newsfeed/tsconfig.json" },
{ "path": "../../plugins/usage_collection/tsconfig.json" },
{ "path": "../../plugins/kibana_react/tsconfig.json" },
]
}
Loading

0 comments on commit b76f033

Please sign in to comment.