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

Invalid searchSourceJSON causes saved object migration to fail #78535

Merged
merged 5 commits into from
Sep 30, 2020

Conversation

alexwizp
Copy link
Contributor

@alexwizp alexwizp commented Sep 25, 2020

Closes: #78530

Summary

Migration script (migrateMatchAllQuery) was added into 7.9.3

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@alexwizp alexwizp self-assigned this Sep 25, 2020
@alexwizp alexwizp added v7.8.2 v7.9.3 v7.10.0 v8.0.0 Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Discover Discover Application Feature:Saved Objects Feature:Visualizations Generic visualization features (in case no more specific feature label is available) labels Sep 25, 2020
@alexwizp alexwizp marked this pull request as ready for review September 26, 2020 07:13
@alexwizp alexwizp requested a review from a team September 26, 2020 07:13
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

* in that version. So we apply this twice, once with 6.7.2 and once with 7.0.1 while the backport to 6.7
* only contained the 6.7.2 migration and not the 7.0.1 migration.
*/
'6.7.2': flow(migrateMatchAllQuery),
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if we "can" remove (or should) old migrations. The problem is, that depending on from which version you then came, you'll either ran in 6.7.2 over that migration or not. E.g. you were updating from 6.6.0 to 7.6.0 and then 7.10.0, will give you different migrations then upgrading from 6.6.0 to 7.10.0. @rudolf Do you know if this is at all possible? If it's possible I still would like to hear your opinion on if we should do something like that, because this sounds like a horrible source for errors that we'll never be able to find later, since we removed old migrations from the code and won't see it when debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timroes you highlighted a good question in general. It seems to me that wherever we add this migration script, there will still be questions.
Also, analyzing this particular script, I see no problems if it is executed in 7.8. On the other hand, it seems strange to me to add in 7.8 something that is valid for an upgrade from version 5 to 6

From my point of view we should keep version as it (6.7.2) and just a fix reason of an exception:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that this migration fixes a bug introduced in v5 (or a bug in the v6 migration). The version the data bug was introduced is irrelevant, the migration version captures when this migration was applied and the data was transformed and fixed. So a search document with a migrationVersion of 7.9.3 means that this data has been migrated and fixed in Kibana 7.9.3. And then we know that any kibana > 7.9.3 can safely consume this document knowing it has the expected shape.

What complicates matters here is that we first released this migration in v7.8.0 as "6.7.2". As Joe pointed out in the original PR this means that this migration would not have been applied to documents which for instance had already been upgraded to v7.4.0 because we only apply newer migrations. So if someone created a v5 document with this bug (or however you reproduce the original issue) and then upgraded through some path to v7.4.0 this transformation will not be applied when they later upgrade to > v7.8.0

So there are two issues which should be addressed, one is correctly handling invalid JSON, the other is making sure that this migration is applied to all documents. To get this migration applied to all versions we need to set it's version to the oldest Kibana this will get released in (e.g. 7.9.3).

Since the "new" 7.9.3 migration is the same as the 6.7.2 migration, anyone running Kibana > 7.9.3 will always have this migration applied (perhaps it's applied twice, but that's fine).

However removing the migration might still be a bad idea because it makes it harder to find and debug because it's no longer in the master codebase. So I can see some benefit in keeping the 6.7.2 migration just as a historic reference so that if someone ever wonders why a document had a migration applied with v6.7.2 they'll be able to find that migration in the codebase. We would then have two identical migration scripts with different versions.

Copy link
Contributor

Choose a reason for hiding this comment

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

The other option is to not have duplicate migrations but just have a big comment block in the code above the 7.9.3 migration stating that at some point this was released as a 6.7.2 migration and later changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the "traceability" here would outrule that small performance drawback of running that other (same) migration in 6.7.2 and as far as I understand there'll be no other drawback to it, why I'd suggest we're not removing it, but instead keeping it for the old version.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, I also prefer the better traceability of duplicate migrations.

@alexwizp alexwizp removed the v7.8.2 label Sep 29, 2020
Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Code LGTM, didn't run. Thanks for following up on this @rudolf

A nice addition to https://github.com/elastic/kibana/blob/master/src/core/server/saved_objects/migrations/README.md would be a guide with examples on how to write migrations (don't change old migrations, always add to the next version, ...)

@rudolf
Copy link
Contributor

rudolf commented Sep 30, 2020

A nice addition to https://github.com/elastic/kibana/blob/master/src/core/server/saved_objects/migrations/README.md would be a guide with examples on how to write migrations (don't change old migrations, always add to the next version, ...)

I've created https://www.elastic.co/guide/en/kibana/master/development-plugin-saved-objects.html#_writing_migrations and added some of the lessons we learned from this issue. I'll add something about never removing old migrations and if fixing a bug in an old migration, always release it as a duplicate in the current version.

I should also link to the new docs from https://github.com/elastic/kibana/blob/master/src/core/server/saved_objects/migrations/README.md so help people find it.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

@timroes timroes dismissed their stale review September 30, 2020 12:01

Given concerns were addressed

@alexwizp alexwizp merged commit 4306082 into elastic:master Sep 30, 2020
alexwizp added a commit to alexwizp/kibana that referenced this pull request Sep 30, 2020
…stic#78535)

* Invalid `searchSourceJSON` causes saved object migration to fail

Closes: elastic#78530

* 7.8.2 -> 7.9.3

* return migration into 6.7.2
alexwizp added a commit to alexwizp/kibana that referenced this pull request Sep 30, 2020
…stic#78535)

* Invalid `searchSourceJSON` causes saved object migration to fail

Closes: elastic#78530

* 7.8.2 -> 7.9.3

* return migration into 6.7.2
# Conflicts:
#	src/plugins/visualizations/server/saved_objects/visualization_migrations.ts
alexwizp added a commit that referenced this pull request Sep 30, 2020
) (#78936)

* Invalid `searchSourceJSON` causes saved object migration to fail

Closes: #78530

* 7.8.2 -> 7.9.3

* return migration into 6.7.2
# Conflicts:
#	src/plugins/visualizations/server/saved_objects/visualization_migrations.ts
alexwizp added a commit that referenced this pull request Sep 30, 2020
) (#78935)

* Invalid `searchSourceJSON` causes saved object migration to fail

Closes: #78530

* 7.8.2 -> 7.9.3

* return migration into 6.7.2
phillipb added a commit to phillipb/kibana that referenced this pull request Sep 30, 2020
…aly-detection-partition-field

* 'master' of github.com:elastic/kibana: (37 commits)
  [UiActions] Don't throw an error if there are no compatible actions to execute (elastic#78917)
  [Observability] Kibana nav when docked overlaps the content of the pages. (elastic#78593)
  Invalid `searchSourceJSON` causes saved object migration to fail (elastic#78535)
  update vega version (elastic#78390)
  Fix warning text doesn't get displayed on filters with custom filter name (elastic#78617)
  [ILM] Data tier notices should reflect tier preferences (elastic#78398)
  [APM] Service Map: `Not Defined` option doesn't work properly (elastic#77757)
  Improve invalid field error message at search.aggs.param_types.field (elastic#78587)
  Remove isDeprecated flag on visType (elastic#78820)
  Remove unused elasticsearch.preserverHost setting (elastic#78608)
  Fix condition and adjust tests (elastic#78898)
  [UX] Add percentile selector (elastic#78562)
  [ML] Replace use of rest_total_hits_as_int with track_total_hits (elastic#78423)
  expression service docs (elastic#78774)
  [Functional] Wait for the page to load and then click the new vis button (elastic#78725)
  [TSVB] No data in visualizations with annotations (elastic#78794)
  [kbn/ui-shared-deps] track asset sizes (elastic#78718)
  delete target before building (elastic#78665)
  Move indexPattern.popularizeField into discover (elastic#77668)
  [Security Solution][Resolver]Add backdrop to pills (elastic#78625)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Discover Discover Application Feature:Visualizations Generic visualization features (in case no more specific feature label is available) release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.9.3 v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid searchSourceJSON causes saved object migration to fail
6 participants