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

Improve handling of invalid data during migrations #38669

Closed
4 tasks
stacey-gammon opened this issue Jun 11, 2019 · 4 comments
Closed
4 tasks

Improve handling of invalid data during migrations #38669

stacey-gammon opened this issue Jun 11, 2019 · 4 comments
Labels
discuss Feature:Saved Objects stale Used to mark issues that were closed for being stale Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@stacey-gammon
Copy link
Contributor

stacey-gammon commented Jun 11, 2019

Background

We currently handle invalid data during migrations inconsistently. Sometimes we throw an error, sometimes we just return the invalid data.

This makes it difficult for us to know what type of data we might be dealing with and increases the chances for migrations errors when our assumptions turn out to be wrong.

Goal

Be able to make assumptions about the shape of our data in any given release.

Proposal

If we start just throwing errors when we encounter unknown data, this could prevent users from upgrading, so we should get there slowly. If we increase our knowledge of the shape of data out in the wild, we should be able to account for that in future migrations until we are finally at a spot we can say we are confident we know the shape of the data.

  • Log warnings when a saved object is encountered with unexpected data.
  • Send telemetry when unexpected data is encountered.
  • When telemetry data starts coming in, we can adjust migrations for any unaccounted data that is actually valid.
  • We then log a deprecation warning when invalid data is encountered that the user will not be able to upgrade if they won't manually adjust, or delete, the invalid saved objects.

Related

@spalger - I see we have had similar thoughts!

@stacey-gammon stacey-gammon added discuss Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc labels Jun 11, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform

@rudolf
Copy link
Contributor

rudolf commented Jun 11, 2019

I agree that strictly defining what data we expect and throwing a runtime error if unexpected data appears will improve the quality and readability of the migrations.

The same problems you mentioned with not knowing the shape of the input data also filters through to any part of the code base that uses SavedObjects. This would require a bit more work, but I think it could be very valuable if plugins were required to define runtime types using something like https://github.com/gcanti/io-ts to define the shape of their SavedObjects. That would provide a strong guarantee to all consuming code (including migrations) about the shape of the data.

@stacey-gammon
Copy link
Contributor Author

Thinking more about this... I think we'd probably want to move to something like this slowly.

It's my understanding that throwing an error will prevent Kibana from starting up. A client who upgrades from 7.x to 7.x.+1 could potentially suddenly see their Kibana failing to start due to invalid data that was previously ignored.

A better plan may be to:

7.x:

  • Mark invalid saved objects as such { invalid: true } in es.
  • Provide a warning in kibana logs, and possibly the UI. Call out that starting in 8.0 if these objects are not removed, Kibana will fail to start. Perhaps mention contacting your support team if this seems to be in error.

8.0:

  • We throw the error and stop migrations on invalid data. We can now be assured that any instances running on 8.0 that pass migrations have validated data.

Benefits:

  • In migrations right now, we just return the doc if we hit invalid data. Any additional migrations that need to run are still attempted. This is a waste of time, we can avoid if we mark the saved object as invalid.
  • Gives our support team time to react to possible mistakes in our migration code. It will be difficult to know what kibana indices actually exist out in the wild. If we mark the invalid saved objects, and tell users to contact support, we have a chance to see what we are dealing with and how many users it would affect, and adjust our migration scripts to handle some that invalid data, and massage it into a valid shape.

@stacey-gammon stacey-gammon changed the title [Discuss] Migration validation and typescript Be strict with invalid data during migrations Jun 27, 2019
@stacey-gammon
Copy link
Contributor Author

stacey-gammon commented Jun 27, 2019

I had another idea, we could add telemetry to also see how often invalid data would be hit in the wild.

nevermind, trackUiMetric is not available at the time migrations are run.

regardless, I think it'd be great if migrations could throw errors and the migration system itself would catch those errors, track them somehow, log the error to the console/file, and then continue on with the migrations with a best attempt.

@stacey-gammon stacey-gammon changed the title Be strict with invalid data during migrations Improve handling of invalid data during migrations Jul 24, 2019
@joshdover joshdover added the stale Used to mark issues that were closed for being stale label Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Feature:Saved Objects stale Used to mark issues that were closed for being stale Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

No branches or pull requests

5 participants