Skip to content

[Cases] Mark lens migrations as deferred#159291

Merged
cnasikas merged 5 commits intoelastic:mainfrom
cnasikas:lens_deferred_migrations
Jun 9, 2023
Merged

[Cases] Mark lens migrations as deferred#159291
cnasikas merged 5 commits intoelastic:mainfrom
cnasikas:lens_deferred_migrations

Conversation

@cnasikas
Copy link
Copy Markdown
Member

@cnasikas cnasikas commented Jun 8, 2023

Summary

In Cases, users can add lens visualizations in a case. The lens's attributes persist inside the cases-comments saved object. If the lens team adds a migration a migration will run for the cases-comments SOs to migrate any lens visualization inside the case comment. In this PR we defer the lens migrations to be done on read when it is fetched by users. This way, the cases comments will not be migrated at Kibana startup.

Blocker for #158468

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@cnasikas cnasikas added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// Feature:Cases Cases feature v8.9.0 labels Jun 8, 2023
@cnasikas cnasikas requested review from rudolf and stratoula June 8, 2023 09:43
@cnasikas cnasikas self-assigned this Jun 8, 2023
return {
// @ts-expect-error: remove when core changes the types
deferred,
transform: (
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same function as before. Just set it to the transform attribute.

@cnasikas cnasikas marked this pull request as ready for review June 9, 2023 08:45
@cnasikas cnasikas requested a review from a team as a code owner June 9, 2023 08:45
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/response-ops-cases (Feature:Cases)


const migratedMarkdown = { ...parsedComment, children: migratedComment };
return {
// @ts-expect-error: remove when core changes the types
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@rudolf Is it ok to set it as true when needed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes, until #152807 is merged there's a caveat: if there's partial updates against this saved object it could cause migrations to run twice (update comment without updating typeVersion) or never run (updating typeVersion without updating comment).

Looking at https://github.com/elastic/kibana/blob/main/x-pack/plugins/cases/common/api/cases/comment/index.ts#L250C5-L261 it doesn't seem like we allow partial updates?

Otherwise we're blocked on #152807

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, this is correct. We do not allow partial updates for comments.

});

const migratedMarkdown = { ...parsedComment, children: migratedComment };
return {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We now change "normal" lens migrations into deferred ones. This would work, but I think it'd be more explicit if the actual lens migration was also forced to set deferred: true.

To do this we'd need to handle migrate being migrate: MigrateFunction | SavedObjectMigrationParams

And then do something like:

if(deferred) { // nit: I would call this variable shouldDefer 
  if(typeof(migrate) == "function" || migrate.deferred === false) { // just for illustration, typescript won't like this
   throw new Error("Cases only allows deferred migrations starting in 8.9.0")
  }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Discussed this with @cnasikas and @stratoula

This would require a small refactor in embeddable migration framework to allow for MigrateFunction | SavedObjectMigrationParams instead of just MigrateFunction. While we ultimately want all embeddable migrations to be deferred we're likely going to start moving to a client-side embeddable migration framework soon #158677

So for now we decided we won't force the lens migration to be deferred: true but only apply that when we migrate the case comments.


const migratedMarkdown = { ...parsedComment, children: migratedComment };
return {
// @ts-expect-error: remove when core changes the types
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes, until #152807 is merged there's a caveat: if there's partial updates against this saved object it could cause migrations to run twice (update comment without updating typeVersion) or never run (updating typeVersion without updating comment).

Looking at https://github.com/elastic/kibana/blob/main/x-pack/plugins/cases/common/api/cases/comment/index.ts#L250C5-L261 it doesn't seem like we allow partial updates?

Otherwise we're blocked on #152807

Comment thread x-pack/plugins/cases/server/saved_object_types/migrations/comments.test.ts Outdated
@cnasikas
Copy link
Copy Markdown
Member Author

cnasikas commented Jun 9, 2023

@elasticmachine merge upstream

@cnasikas cnasikas enabled auto-merge (squash) June 9, 2023 16:18
@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
securitySolution 413 417 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
securitySolution 497 501 +4
total +6

History

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

cc @cnasikas

@cnasikas cnasikas merged commit d2f00a1 into elastic:main Jun 9, 2023
@cnasikas cnasikas deleted the lens_deferred_migrations branch June 9, 2023 16:51
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:Cases Cases feature release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v8.9.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants