-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Conversation
Pinging @elastic/kibana-app-services (Team:AppServices) |
There was a problem hiding this 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
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); |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
- You should split that into a separate PR that is not backported
- In addition, you can't make this change without also using the
convertToMultiNamespaceTypeVersion
field.
src/plugins/data/public/query/saved_query/saved_query_service.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this 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.
💚 Build Succeeded
Metrics [docs]Page load bundle
History
To update your PR or re-run it, just comment with: cc @lukasolson |
* 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>
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
) * 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>
Summary
Resolves #108336.
Updates the saved query service to use
savedObjectsClient.resolve
rather thansavedObjectsClient.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