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

[Lens] Make Lens saved object share-capable #111403

Merged
merged 6 commits into from
Sep 13, 2021

Conversation

mbondyra
Copy link
Contributor

@mbondyra mbondyra commented Sep 7, 2021

Fixes #105808

Step 4 of https://www.elastic.co/guide/en/kibana/master/sharing-saved-objects.html#sharing-saved-objects-step-4

I was thinking about waiting with this one closer to 8.0.0, but it's such a small change that I don't think it'll cause any conflicts.

@mbondyra mbondyra added Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 release_note:skip Skip the PR/issue when compiling release notes labels Sep 7, 2021
@mbondyra mbondyra marked this pull request as ready for review September 7, 2021 14:51
@mbondyra mbondyra requested a review from a team as a code owner September 7, 2021 14:51
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-vis-editors (Team:VisEditors)

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

Code changes LGTM

@mbondyra mbondyra marked this pull request as draft September 7, 2021 20:38
Copy link
Contributor

@jportner jportner left a comment

Choose a reason for hiding this comment

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

The code changes LGTM!

I think your tests are likely failing due to the fixtures in x-pack/test/functional/es_archives/lens/basic/data.json.
I did a quick look at the objects and I noticed that the lens objects in that file don't have a migrationVersion field defined.
Because of that, the document migrator thinks that the object is up-to-date, and doesn't attempt to convert it. But our SOR deserializer also expects multiple-isolated object types to have a namespaces field.
So as a quick fix you could add these fields to your lens objects in that test fixture file:

namespaces: ['default'],
migrationVersion: { lens: '8.0.0' }

If that doesn't work, perhaps it would be a good idea to add some ES queries before the test assertions to see what saved object documents actually exist, and make sure that the lens was converted properly.

Feel free to ping me if you need a hand troubleshooting.

(Also note: I am not sure why x-pack/test/functional/es_archives/lens/basic/data.json.gz also exists, you should be able to delete that)

@mbondyra mbondyra force-pushed the lens/make_lens_so_sharecapable branch from 5e73d37 to f8da524 Compare September 8, 2021 13:01
@mbondyra mbondyra added the backport:skip This commit does not require backporting label Sep 8, 2021
@mbondyra mbondyra force-pushed the lens/make_lens_so_sharecapable branch from 874977f to 3332a3e Compare September 10, 2021 12:13
@mbondyra
Copy link
Contributor Author

mbondyra commented Sep 10, 2021

Found the cause of the breaking test. We use a bit hacky safeUpdate. When updating Lens, we firstly clean all the attributes and then save the new ones, that’s because update method merges instead of replacing (it's very well explained in the linked PR)

I wanted to replace update with index but I don't see it exposed in saved object code, unless I am missing something?

We use bulkUpdate assuming that it works in order.

https://github.com/elastic/kibana/blob/master/x-pack/plugins/lens/public/persistence/saved_object_store.ts#L84-L90

return (
      await this.client.bulkUpdate([
        { type: DOC_TYPE, id: savedObjectId, attributes: resetAttributes, references },
        { type: DOC_TYPE, id: savedObjectId, attributes, references },
      ])
    ).savedObjects[1];

I think something about bulkUpdate works different with my changes because now it returns empty attributes for the second object, not sure why. @jportner you know what could have caused that?
I am thinking to simply change it to two awaited updates, is there a better option?

EDIT: I found overwrite=true this comment so I've switched to using single create instead of two updates 🙌🏼

@mbondyra mbondyra force-pushed the lens/make_lens_so_sharecapable branch from 3332a3e to 0c2af3f Compare September 10, 2021 12:26
@mbondyra mbondyra marked this pull request as ready for review September 10, 2021 14:41
@jportner
Copy link
Contributor

Found the cause of the breaking test. We use a bit hacky safeUpdate. When updating Lens, we firstly clean all the attributes and then save the new ones, that’s because update method merges instead of replacing (it's very well explained in the linked PR)

Nice sleuthing!

I think something about bulkUpdate works different with my changes because now it returns empty attributes for the second object, not sure why. @jportner you know what could have caused that?

I don't believe anything in the Elasticsearch Bulk API guarantees that operations will be executed in the order that they are specified. The SavedObjectsClient doesn't explicitly prevent specifying the same object twice in a single operation, but this hacky approach certainly isn't recommended.

I wanted to replace update with index but I don't see it exposed in saved object code, unless I am missing something?
...
EDIT: I found overwrite=true this comment but I don't see it exposed in SO client.

The SavedObjectsClient abstracts the bulk API details away from the consumer. To use an index operation, you'll want to make this call:

return await this.client.create(DOC_TYPE, attributes, { id: savedObjectId, overwrite: true });

@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 1.6MB 1.6MB -375.0B

History

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

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

Very nice investigation Marta! Code LGTM I didn't test it locally but everything looks fine :)

@mbondyra mbondyra merged commit 15a31a1 into elastic:master Sep 13, 2021
@mbondyra mbondyra deleted the lens/make_lens_so_sharecapable branch September 13, 2021 07:33
jloleysens added a commit to jloleysens/kibana that referenced this pull request Sep 13, 2021
…-link-to-kibana-app

* 'master' of github.com:elastic/kibana: (120 commits)
  [TSVB] Support custom field format (elastic#101245)
  [VisEditors] Add code ownership to the functional tests (elastic#111680)
  [Lens] Make Lens saved object share-capable (elastic#111403)
  [Graph] Make Graph saved object share-capable (elastic#111404)
  [Stack Monitoring] Add breadcrumb support (elastic#111850)
  Update Jira Cloud to use OAuth2.0 (elastic#111493)
  Show warning message when attempting to create an APM alert in stack management (elastic#111781)
  Skip suite blocking ES snapshot promotion (elastic#111907)
  Respect `auth_provider_hint` if session is not authenticated. (elastic#111521)
  Added in 'Responses' field in alert telemetry & updated test (elastic#111892)
  [Usage collection] refactor cloud detector collector (elastic#110439)
  Make classnames a shared dep (elastic#111636)
  Fix link to e2e tests in APM testing.md (elastic#111869)
  [Security Solution] Add host.os.name.caseless mapping and runtime field (elastic#111455)
  [APM] Removes the beta label from APM tutorial (elastic#111499) (elastic#111828)
  [RAC] [Observability] Expand Observability alerts page functional tests (elastic#111297)
  Fix extra white space on the alert table whe page size is 50 or 100 (elastic#111568)
  [Metrics UI] Add Inventory Timeline open/close state to context and URL state (elastic#111034)
  [Graph] Switch to SavedObjectClient.resolve  (elastic#109617)
  [APM] Adding lambda icon (elastic#111834)
  ...

# Conflicts:
#	x-pack/plugins/reporting/public/management/__snapshots__/report_listing.test.tsx.snap
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:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Switch to SavedObjectClient.resolve
6 participants