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

Fix running Kibana Platform migrations in development #61325

Merged
merged 3 commits into from
Mar 25, 2020

Conversation

joshdover
Copy link
Contributor

Summary

This solves a problem where migrations were failing in development for saved object types registered by plugins:

  log   [14:43:33.439] [fatal][root] { Error: Document "7a694860-6cfc-11ea-ba22-77a4b53bec34" has property "index-pattern" which belongs to
a more recent version of Kibana (7.6.0).
    at find (C:\gitRepositories\kibana\src\core\server\saved_objects\migrations\core/document_migrator.ts:351:18)
    at Array.find (<anonymous>)
    at nextUnmigratedProp (C:\gitRepositories\kibana\src\core\server\saved_objects\migrations\core/document_migrator.ts:337:21)
    at applyMigrations (C:\gitRepositories\kibana\src\core\server\saved_objects\migrations\core/document_migrator.ts:262:18)
    at DocumentMigrator.transformDoc (C:\gitRepositories\kibana\src\core\server\saved_objects\migrations\core/document_migrator.ts:244:9)
    at migrateDoc (C:\gitRepositories\kibana\src\core\server\saved_objects\migrations\core/document_migrator.ts:155:17)
    at map (C:\gitRepositories\kibana\src\core\server\saved_objects\migrations\core/migrate_raw_docs.ts:46:12)
    at Array.map (<anonymous>)
    at migrateRawDocs (C:\gitRepositories\kibana\src\core\server\saved_objects\migrations\core/migrate_raw_docs.ts:40:18)
    at migrateSourceToDest (C:\gitRepositories\kibana\src\core\server\saved_objects\migrations\core/index_migrator.ts:198:7)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  data:

This was failing because the migrations were being run in the master dev process where plugins are not initialized, so the migrations were missing for types registered by Kibana Platform plugins.

This change ensures that migrations are only ran on the actual server process where plugins are initialized.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@joshdover joshdover added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes v7.7.0 labels Mar 25, 2020
@joshdover joshdover requested a review from a team as a code owner March 25, 2020 17:41
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

Comment on lines 380 to 383
const cliArgs = this.coreContext.env.cliArgs;
const skipMigrations = cliArgs.optimize || this.config.migration.skip;
const skipMigrations =
this.config.migration.skip || this.coreContext.env.isDevClusterMaster || !pluginsInitialized;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cliArgs.optimize was the wrong option to be listening for. This CLI arg is only specified when running kibana to only run the optimizer and then exit. It is not set when running the optimizer in dev. However, in both cases, plugin initialization is disabled which is really the case where we shouldn't run migrations.

const cliArgs = this.coreContext.env.cliArgs;
const skipMigrations = cliArgs.optimize || this.config.migration.skip;
const skipMigrations =
this.config.migration.skip || this.coreContext.env.isDevClusterMaster || !pluginsInitialized;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this flag isDevClusterMaster already used when calculating pluginsInitialized ? https://github.com/elastic/kibana/pull/61325/files#diff-725c498a267472754f01cff2baa3901bR110

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No there's a --plugin.initialized config option that is used (optimizer also specifies this flag)

@joshdover
Copy link
Contributor Author

I think we may actually be able to drop the --migrations.skip flag completely and only look at --plugins.initialize.

@rudolf Are there any cases where we would want to specify one of these but not the other? I did not find any in the codebase.

@rudolf
Copy link
Contributor

rudolf commented Mar 25, 2020

@rudolf Are there any cases where we would want to specify one of these but not the other? I did not find any in the codebase.

We use it for some tests when ES isn't available which would otherwise block migrations, like

['src/cli', '--config', INVALID_CONFIG_PATH, '--migrations.skip=true'],

Not sure if we can use plugins.initialize for those as we probably want plugins to be enabled during those tests.

Edit: realized after a closer look that this specific test doesn't require plugins to be initialized, but the use case is probably still valid

@rudolf
Copy link
Contributor

rudolf commented Mar 25, 2020

Just had a look through our existing migrations.skip occurrences:

Redundant, can be removed:

'--migrations.skip=true',

Can be replaced with plugins.initialize=false

['src/cli', '--config', INVALID_CONFIG_PATH, '--migrations.skip=true'],

This test spins up ES so not necessary to skip migrations. It might not be necessary to start ES for this test, if that's the case and we want to speed up the test, this would be the only case where skip migrations is useful:

Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

Left a comment of some occurrences of migrations.skip that we could clean up, but doesn't have to block this PR.

@joshdover
Copy link
Contributor Author

I'm opting to keep migrations.skip for now until we're sure there isn't a valid use case. I can imagine other test scenarios where we may want this.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Comment on lines +174 to +179
it('skips KibanaMigrator migrations when pluginsInitialized=false', async () => {
const coreContext = createCoreContext({ skipMigration: false });
const soService = new SavedObjectsService(coreContext);

await soService.setup(createSetupDeps());
await soService.start({});
await soService.start({ pluginsInitialized: false });
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably low impact, but we now have the config SO type that is registered by core, not plugins. The type would be usable but not migrated with PR changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably the correct way to solve is to have the processes that need to run Core only run setup and extract whatever information they need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants