-
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
Saved Objects - make import/export stream based #39674
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75f344c
transform ndjson within route handlers for SO import/export APIs
legrego 6bb07c9
convert export saved objects to return a stream
legrego ee99983
fix stream creation
legrego 074a7a6
Merge branch 'master' of github.com:elastic/kibana into so/import-exp…
legrego aa31c21
Merge branch 'master' of github.com:elastic/kibana into so/import-exp…
legrego 3c731df
Merge branch 'master' of github.com:elastic/kibana into so/import-exp…
legrego b76baeb
Merge branch 'master' of github.com:elastic/kibana into so/import-exp…
legrego 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 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 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 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 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 |
---|---|---|
|
@@ -23,6 +23,7 @@ import { collectSavedObjects } from './collect_saved_objects'; | |
describe('collectSavedObjects()', () => { | ||
test('collects nothing when stream is empty', async () => { | ||
const readStream = new Readable({ | ||
objectMode: true, | ||
read() { | ||
this.push(null); | ||
}, | ||
|
@@ -38,34 +39,9 @@ Object { | |
|
||
test('collects objects from stream', async () => { | ||
const readStream = new Readable({ | ||
objectMode: true, | ||
read() { | ||
this.push('{"foo":true,"type":"a"}'); | ||
this.push(null); | ||
}, | ||
}); | ||
const result = await collectSavedObjects({ | ||
readStream, | ||
objectLimit: 1, | ||
supportedTypes: ['a'], | ||
}); | ||
expect(result).toMatchInlineSnapshot(` | ||
Object { | ||
"collectedObjects": Array [ | ||
Object { | ||
"foo": true, | ||
"migrationVersion": Object {}, | ||
"type": "a", | ||
}, | ||
], | ||
"errors": Array [], | ||
} | ||
`); | ||
}); | ||
|
||
test('filters out empty lines', async () => { | ||
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. This diff is hard to read. The |
||
const readStream = new Readable({ | ||
read() { | ||
this.push('{"foo":true,"type":"a"}\n\n'); | ||
this.push({ foo: true, type: 'a' }); | ||
this.push(null); | ||
}, | ||
}); | ||
|
@@ -90,9 +66,10 @@ Object { | |
|
||
test('throws error when object limit is reached', async () => { | ||
const readStream = new Readable({ | ||
objectMode: true, | ||
read() { | ||
this.push('{"foo":true,"type":"a"}\n'); | ||
this.push('{"bar":true,"type":"a"}\n'); | ||
this.push({ foo: true, type: 'a' }); | ||
this.push({ bar: true, type: 'a' }); | ||
this.push(null); | ||
}, | ||
}); | ||
|
@@ -107,9 +84,10 @@ Object { | |
|
||
test('unsupported types return as import errors', async () => { | ||
const readStream = new Readable({ | ||
objectMode: true, | ||
read() { | ||
this.push('{"id":"1","type":"a","attributes":{"title":"my title"}}\n'); | ||
this.push('{"id":"2","type":"b","attributes":{"title":"my title 2"}}\n'); | ||
this.push({ id: '1', type: 'a', attributes: { title: 'my title' } }); | ||
this.push({ id: '2', type: 'b', attributes: { title: 'my title 2' } }); | ||
this.push(null); | ||
}, | ||
}); | ||
|
@@ -141,9 +119,10 @@ Object { | |
|
||
test('unsupported types still count towards object limit', async () => { | ||
const readStream = new Readable({ | ||
objectMode: true, | ||
read() { | ||
this.push('{"foo":true,"type":"a"}\n'); | ||
this.push('{"bar":true,"type":"b"}\n'); | ||
this.push({ foo: true, type: 'a' }); | ||
this.push({ bar: true, type: 'b' }); | ||
this.push(null); | ||
}, | ||
}); | ||
|
This file contains 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 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
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.
a bit concern with importing utils from legacy, but we haven't discuss this inside the team.
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 left these utilities in legacy when I moved Saved Objects to Core, so it's a todo for the Saved Objects migration. There are stable NPM packages for many of these so I'm hoping we can replace the utilities with dedicated npm dependencies.