Skip to content

Commit

Permalink
Run migrations on savedobjects start
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf committed Aug 22, 2019
1 parent 6fea102 commit ea6486a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/cli/serve/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ export default function (program) {
.option('--plugins <path>', 'an alias for --plugin-dir', pluginDirCollector)
.option('--optimize', 'Optimize and then stop the server');


if (CAN_REPL) {
command.option('--repl', 'Run the server with a REPL prompt and access to the server object');
}
Expand All @@ -211,7 +210,8 @@ export default function (program) {
.option('--ssl', 'Run the dev server using HTTPS')
.option('--no-base-path', 'Don\'t put a proxy in front of the dev server, which adds a random basePath')
.option('--no-watch', 'Prevents automatic restarts of the server in --dev mode')
.option('--no-dev-config', 'Prevents loading the kibana.dev.yml file in --dev mode');
.option('--no-dev-config', 'Prevents loading the kibana.dev.yml file in --dev mode')
.option('--skip-migrations', 'Don\'t run Saved Object migrations (testing only)');
}

command
Expand Down Expand Up @@ -241,6 +241,7 @@ export default function (program) {
basePath: !!opts.basePath,
optimize: !!opts.optimize,
oss: !!opts.oss,
skipMigrations: !!opts.skipMigrations,
},
features: {
isClusterModeSupported: CAN_CLUSTER,
Expand Down
1 change: 1 addition & 0 deletions src/core/server/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface CliArgs {
optimize: boolean;
open: boolean;
oss: boolean;
skipMigrations: boolean;
}

export class Env {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ export class KibanaMigrator {
* @returns
* @memberof KibanaMigrator
*/
public awaitMigration = once(async () => {
public awaitMigration = once(async (skipMigrations: boolean = false) => {
if (skipMigrations) {
this.log.warn(
'Skipping Saved Object migrations on startup. Note: Individual documents will still be migrated when reading or writing documents.'
);
return Object.keys(this.mappingProperties).map(() => ({ status: 'skipped' }));
}

const kibanaIndexName = this.kibanaConfig.index;
const indexMap = createIndexMap({
config: this.config,
Expand Down
15 changes: 13 additions & 2 deletions src/core/server/saved_objects/saved_objects_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface SetupDeps {
export class SavedObjectsService
implements CoreService<SavedObjectsServiceSetup, SavedObjectsServiceStart> {
private migrator: KibanaMigrator | undefined;

constructor(private readonly coreContext: CoreContext) {}

public async setup(coreSetup: SetupDeps) {
Expand Down Expand Up @@ -146,8 +147,18 @@ export class SavedObjectsService
}

public async start(core: StartDeps): Promise<SavedObjectsServiceStart> {
// Start migrations, but don't wait for them to complete
this.migrator!.awaitMigration();
/**
* Note: We want to ensure that migrations have completed before
* continuing with further Core startup steps such as running the legacy
* server, legacy plugins and allowing HTTP requests.
*
* However, our build system optimize step and some tests depend on the
* HTTP server running without an Elasticsearch server being available.
*/
const cliArgs = this.coreContext.env.cliArgs;
const skipMigrations = cliArgs.optimize || cliArgs.skipMigrations;
await this.migrator!.awaitMigration(skipMigrations);

return { migrator: this.migrator as KibanaMigrator };
}

Expand Down
13 changes: 0 additions & 13 deletions src/core/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,6 @@ export class Server {
plugins: mapToObject(pluginsStart.contracts),
});

/**
* Note: ideally we'd like to wait for migrations to complete before
* loading the legacy service which in turn starts legacy plugins. But,
* our build process relies on the optimize phase being able to run
* without a running ES server. Optimize in turn depends on the legacy
* server being started. So until optimization has been moved to the
* NP we move migrations till after legacy.start() and only if we're not
* running optimize.
*/
if (!this.env.cliArgs.optimize) {
await savedObjectsStart.migrator.awaitMigration();
}

await this.http.start();

return coreStart;
Expand Down
2 changes: 0 additions & 2 deletions src/legacy/server/kbn_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ export default class KbnServer {

const { server, config } = this;

await server.kibanaMigrator.awaitMigration();

if (isWorker) {
// help parent process know when we are ready
process.send(['WORKER_LISTENING']);
Expand Down
1 change: 1 addition & 0 deletions tasks/config/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module.exports = function (grunt) {
'--plugins.initialize=false',
'--optimize.bundleFilter=tests',
'--server.port=5610',
'--skip-migrations'
];

const NODE = 'node';
Expand Down

0 comments on commit ea6486a

Please sign in to comment.