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

Use savedObjectsClient.resolve in saved query service #111229

Merged
merged 8 commits into from
Sep 13, 2021

Conversation

lukasolson
Copy link
Member

@lukasolson lukasolson commented Sep 4, 2021

Summary

Resolves #108336.

Updates the saved query service to use savedObjectsClient.resolve rather than savedObjectsClient.get.

For background, see https://www.elastic.co/guide/en/kibana/master/sharing-saved-objects.html#sharing-saved-objects-faq-resolve-instead-of-get. Saved queries can be deep-linked inside URLs, so we need to use the new resolve method to handle conflicts. Currently, conflicts will throw an error... (though I'm not sure if that's the best behavior... should they log an error and return the exact match?)

Checklist

For maintainers

@lukasolson lukasolson added review Feature:Filters Feature:Query Bar Querying and query bar features v8.0.0 Team:AppServices release_note:skip Skip the PR/issue when compiling release notes labels Sep 4, 2021
@lukasolson lukasolson requested a review from a team as a code owner September 4, 2021 00:06
@lukasolson lukasolson self-assigned this Sep 4, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServices)

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.

Code review only --

One nit on an error message, and one problem with the type conversion, see individual comments

Edit: and this PR should be backported to 7.16

Comment on lines 107 to 117
const getSavedQuery = async (id: string): Promise<SavedQuery> => {
const savedObject = await savedObjectsClient.get<SerializedSavedQueryAttributes>('query', id);
if (savedObject.error) {
const {
saved_object: savedObject,
outcome,
} = await savedObjectsClient.resolve<SerializedSavedQueryAttributes>('query', id);
if (outcome === 'conflict') {
throw new Error(`Multiple saved queries found with ID: ${id}`);
} else if (savedObject.error) {
throw new Error(savedObject.error.message);
}
return parseSavedQueryObject(savedObject);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to let you know, when a saved query is not found, this error checking logic won't work as expected.
Currently if you get an object with the public SOC, it batches the request into a bulkGet under the hood - if it can't find the object, it doesn't throw an error, rather it just returns an object with an error field.

The resolve API doesn't work the same way, so it will actually throw an error when an object is not found.

That said, I have an open issue to add a bulkResolve with the same type of transparent batching, so after that is merged the behavior will be back to how you expect it: #111201

TL;DR no changes needed here 👍

namespaceType: 'single',
namespaceType: 'multiple-isolated',
Copy link
Contributor

@jportner jportner Sep 7, 2021

Choose a reason for hiding this comment

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

The rest of this PR is Step 2 of the Sharing Saved Objects Dev Guide, but this bit is Step 4.
Step 2 should be backported to 7.x, but Step 4 should not be backported, it should only land in 8.0.

  1. You should split that into a separate PR that is not backported
  2. In addition, you can't make this change without also using the convertToMultiNamespaceTypeVersion field.

@lukasolson lukasolson added auto-backport Deprecated - use backport:version if exact versions are needed v7.16.0 labels Sep 7, 2021
lukasolson and others added 2 commits September 7, 2021 13:30
Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
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.

LGTM, thanks!

Copy link
Member

@tsullivan tsullivan left a comment

Choose a reason for hiding this comment

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

LGTM reviewed the code only.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 777.8KB 777.9KB +149.0B

History

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

cc @lukasolson

@lukasolson lukasolson merged commit a8f9468 into elastic:master Sep 13, 2021
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Sep 13, 2021
* Use resolve instead of get for saved query service

* Update tests

* Update src/plugins/data/public/query/saved_query/saved_query_service.ts

Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>

* Revert step 4

* Fix test

Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Sep 14, 2021
)

* Use resolve instead of get for saved query service

* Update tests

* Update src/plugins/data/public/query/saved_query/saved_query_service.ts

Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>

* Revert step 4

* Fix test

Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>

Co-authored-by: Lukas Olson <olson.lukas@gmail.com>
Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Filters Feature:Query Bar Querying and query bar features release_note:skip Skip the PR/issue when compiling release notes review v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use savedObjectsClient.resolve inside saved queries service
5 participants