-
Notifications
You must be signed in to change notification settings - Fork 8.5k
SavedObjects management: display explicit import error in case of failure and avoid invalid file to crash the server #82406
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
SavedObjects management: display explicit import error in case of failure and avoid invalid file to crash the server #82406
Conversation
| export async function createSavedObjectsStreamFromNdJson(ndJsonStream: Readable) { | ||
| const savedObjects = await createPromiseFromStreams([ | ||
| ndJsonStream, | ||
| createSplitStream('\n'), | ||
| createMapStream((str: string) => { | ||
| if (str && str.trim() !== '') { | ||
| return JSON.parse(str); | ||
| } | ||
| }), |
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.
Soooo, long story short:
Uncatched errors from streams (either unhandled promises or plain errors) are causing the process to crash due to unhandled errors (forget streams were THAT much of a pain since I've been using observables)
The implementation of createPromiseFromStreams that is used here
kibana/src/core/server/saved_objects/import/collect_saved_objects.ts
Lines 49 to 50 in cd86b81
| const collectedObjects: Array<SavedObject<{ title?: string }>> = await createPromiseFromStreams([ | |
| readStream, |
relies on stream.pipeline under the hood, that is supposed to intercept errors occurring during the stream/transform chain, however errors that occurred within a pipe of the argument observable are not.
The direct consequence is that any error thrown from the piping chain that is done in createSavedObjectsStreamFromNdJson was uncatched, therefor killing the server.
The correct solution would probably be to stop using streams and moving to observable instead, but these are significant changes (and collectSavedObjects is also used by the spaces plugin when copying to space), so the only solution I found for now was to collect the initial saved objects inside createSavedObjectsStreamFromNdJson and recreate a stream from that. That way, errors during the createSavedObjectsStreamFromNdJson stream chain are properly thrown via the added await createPromiseFromStreams. A FTR test has been added to assert that.
Note that this doesn't change the performances or memory usage: we were already collecting all emissions of the SO stream here before:
| const collectedObjects: Array<SavedObject<{ title?: string }>> = await createPromiseFromStreams([ |
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.
👍
I suspect if we're adding more saved object types to the export (to allow us to deprecate multi-tenancy) we might want to support real streaming imports/exports again and that will maybe allow us to remove the import payload size limit completely. But that's something to revisit once we know this is a requirement.
|
Pinging @elastic/kibana-platform (Team:Platform) |
rudolf
left a comment
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.
We finally have import error messages in the UI 🙌
| export async function createSavedObjectsStreamFromNdJson(ndJsonStream: Readable) { | ||
| const savedObjects = await createPromiseFromStreams([ | ||
| ndJsonStream, | ||
| createSplitStream('\n'), | ||
| createMapStream((str: string) => { | ||
| if (str && str.trim() !== '') { | ||
| return JSON.parse(str); | ||
| } | ||
| }), |
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.
👍
I suspect if we're adding more saved object types to the export (to allow us to deprecate multi-tenancy) we might want to support real streaming imports/exports again and that will maybe allow us to remove the import payload size limit completely. But that's something to revisit once we know this is a requirement.
For exports, probably. For imports, I guess we would still need to collect all SO to perform a single |
| } | ||
| > | ||
| <EuiFilePicker | ||
| accept=".ndjson, .json" |
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.
Thanks 😄
💚 Build SucceededMetrics [docs]async chunks size
History
To update your PR or re-run it, just comment with: |
…lure and avoid invalid file to crash the server (elastic#82406) * display error cause in case of import failure * avoid server crash when importing invalid file * remove unused translations * fix unit tests * change savedObjects.maxImportPayloadBytes default to 25mb * fix types and logic
…lure and avoid invalid file to crash the server (elastic#82406) * display error cause in case of import failure * avoid server crash when importing invalid file * remove unused translations * fix unit tests * change savedObjects.maxImportPayloadBytes default to 25mb * fix types and logic # Conflicts: # test/functional/apps/management/_import_objects.ts
…lure and avoid invalid file to crash the server (#82406) (#82613) * display error cause in case of import failure * avoid server crash when importing invalid file * remove unused translations * fix unit tests * change savedObjects.maxImportPayloadBytes default to 25mb * fix types and logic # Conflicts: # test/functional/apps/management/_import_objects.ts
Summary
Fix #66387 Fix #36126 Fix #82403
Change the default value of
savedObjects.maxImportPayloadBytesto 25mb (26214400) (Ability to import saved object files larger than 10MB #36126)Fix a bug causing the server to crash when importing an invalid file (SavedObjects management: importing an invalid NDJSON files causes the server to crash. #82403)
Display the error message (as returned by the server) when the SO import fails (Saved Object Management: saved objects import errors should be displayed to the user #66387)
Note: this is only displaying the technical error. Ideally, we would have a more user-friendly error, but this is harder to achieve, as there are some informations that we don't have on the client-side (such as the maxBodyPayload). Also, some errors are directly returned from HAPI (413) so it would not be possible to alter their format. I still think this is acceptable, and way better than not displaying any message at all.
Checklist
Release Note
Fix a bug causing Kibana to crash when importing a file with an invalid format from the saved object management section.