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

[Cases] Mark lens migrations as deferred #159291

Merged
merged 5 commits into from
Jun 9, 2023

Conversation

cnasikas
Copy link
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 Label for the ResponseOps team (formerly the Cases and Alerting teams) 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
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
Contributor

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

@elasticmachine
Copy link
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
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
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
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
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
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
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

@cnasikas
Copy link
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
Collaborator

💚 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 commit does not require backporting label Jun 9, 2023
saarikabhasi pushed a commit to saarikabhasi/kibana that referenced this pull request Jun 14, 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 elastic#158468

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Cases Cases feature release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants