-
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
Merged
pgayvallet
merged 7 commits into
elastic:master
from
pgayvallet:kbn-66387-display-import-error
Nov 4, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
de34060
display error cause in case of import failure
pgayvallet cd0e3db
avoid server crash when importing invalid file
pgayvallet e2e38a6
remove unused translations
pgayvallet 7ff6126
fix unit tests
pgayvallet d769ae4
change savedObjects.maxImportPayloadBytes default to 25mb
pgayvallet 7dda1b8
fix types and logic
pgayvallet 26dd44a
Merge remote-tracking branch 'upstream/master' into kbn-66387-display…
pgayvallet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
...ent/public/management_section/objects_table/components/__snapshots__/flyout.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,6 +107,17 @@ interface ConflictingRecord { | |
| done: (result: [boolean, string | undefined]) => void; | ||
| } | ||
|
|
||
| const getErrorMessage = (e: any) => { | ||
| const errorMessage = | ||
| e.body?.error && e.body?.message ? `${e.body.error}: ${e.body.message}` : e.message; | ||
| return i18n.translate('savedObjectsManagement.objectsTable.flyout.importFileErrorMessage', { | ||
| defaultMessage: 'The file could not be processed due to error: "{error}"', | ||
| values: { | ||
| error: errorMessage, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| export class Flyout extends Component<FlyoutProps, FlyoutState> { | ||
| constructor(props: FlyoutProps) { | ||
| super(props); | ||
|
|
@@ -183,9 +194,7 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> { | |
| } catch (e) { | ||
| this.setState({ | ||
| status: 'error', | ||
| error: i18n.translate('savedObjectsManagement.objectsTable.flyout.importFileErrorMessage', { | ||
| defaultMessage: 'The file could not be processed.', | ||
| }), | ||
| error: getErrorMessage(e), | ||
| }); | ||
| return; | ||
| } | ||
|
|
@@ -241,10 +250,7 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> { | |
| } catch (e) { | ||
| this.setState({ | ||
| status: 'error', | ||
| error: i18n.translate( | ||
| 'savedObjectsManagement.objectsTable.flyout.resolveImportErrorsFileErrorMessage', | ||
| { defaultMessage: 'The file could not be processed.' } | ||
| ), | ||
| error: getErrorMessage(e), | ||
| }); | ||
| } | ||
| }; | ||
|
|
@@ -437,8 +443,8 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> { | |
| ); | ||
| } catch (e) { | ||
| this.setState({ | ||
| error: e.message, | ||
| status: 'error', | ||
| error: getErrorMessage(e), | ||
| loadingMessage: undefined, | ||
| }); | ||
| return; | ||
|
|
@@ -605,7 +611,7 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> { | |
| } | ||
| color="danger" | ||
| > | ||
| <p>{error}</p> | ||
| <p data-test-subj="importSavedObjectsErrorText">{error}</p> | ||
| </EuiCallOut> | ||
| <EuiSpacer size="s" /> | ||
| </Fragment> | ||
|
|
@@ -759,6 +765,7 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> { | |
| } | ||
| > | ||
| <EuiFilePicker | ||
| accept=".ndjson, .json" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks 😄 |
||
| fullWidth | ||
| initialPromptText={ | ||
| <FormattedMessage | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/functional/apps/management/exports/_import_higher_version.ndjson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"attributes":{"description":"","kibanaSavedObjectMeta":{"searchSourceJSON":"{\"filter\":[],\"query\":{\"query\":\"\",\"language\":\"lucene\"},\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"},"title":"Log Agents","uiStateJSON":"{}","visState":"{\"title\":\"Log Agents\",\"type\":\"area\",\"params\":{\"type\":\"area\",\"grid\":{\"categoryLines\":false,\"style\":{\"color\":\"#eee\"}},\"categoryAxes\":[{\"id\":\"CategoryAxis-1\",\"type\":\"category\",\"position\":\"bottom\",\"show\":true,\"style\":{},\"scale\":{\"type\":\"linear\"},\"labels\":{\"show\":true,\"truncate\":100},\"title\":{\"text\":\"agent.raw: Descending\"}}],\"valueAxes\":[{\"id\":\"ValueAxis-1\",\"name\":\"LeftAxis-1\",\"type\":\"value\",\"position\":\"left\",\"show\":true,\"style\":{},\"scale\":{\"type\":\"linear\",\"mode\":\"normal\"},\"labels\":{\"show\":true,\"rotate\":0,\"filter\":false,\"truncate\":100},\"title\":{\"text\":\"Count\"}}],\"seriesParams\":[{\"show\":\"true\",\"type\":\"area\",\"mode\":\"stacked\",\"data\":{\"label\":\"Count\",\"id\":\"1\"},\"drawLinesBetweenPoints\":true,\"showCircles\":true,\"interpolate\":\"linear\",\"valueAxis\":\"ValueAxis-1\"}],\"addTooltip\":true,\"addLegend\":true,\"legendPosition\":\"right\",\"times\":[],\"addTimeMarker\":false},\"aggs\":[{\"id\":\"1\",\"enabled\":true,\"type\":\"count\",\"schema\":\"metric\",\"params\":{}},{\"id\":\"2\",\"enabled\":true,\"type\":\"terms\",\"schema\":\"segment\",\"params\":{\"field\":\"agent.raw\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\"}}]}"},"id":"082f1d60-a2e7-11e7-bb30-233be9be6a15","migrationVersion":{"visualization":"9.15.82"},"references":[],"type":"visualization","version":1} |
1 change: 1 addition & 0 deletions
1
test/functional/apps/management/exports/_import_invalid_format.ndjson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| This is NOT a ndjson file! |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
createPromiseFromStreamsthat is used herekibana/src/core/server/saved_objects/import/collect_saved_objects.ts
Lines 49 to 50 in cd86b81
relies on
stream.pipelineunder the hood, that is supposed to intercept errors occurring during the stream/transform chain, however errors that occurred within apipeof the argument observable are not.The direct consequence is that any error thrown from the piping chain that is done in
createSavedObjectsStreamFromNdJsonwas 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
collectSavedObjectsis 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 insidecreateSavedObjectsStreamFromNdJsonand recreate a stream from that. That way, errors during thecreateSavedObjectsStreamFromNdJsonstream chain are properly thrown via the addedawait 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:
kibana/src/core/server/saved_objects/import/collect_saved_objects.ts
Line 49 in cd86b81
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.