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

Saved Objects - make import/export stream based #39674

Merged
merged 7 commits into from
Jul 1, 2019

Conversation

legrego
Copy link
Member

@legrego legrego commented Jun 26, 2019

Summary

A prerequisite to #37286, this converts the import/export server APIs to be stream based.

Prior to this PR, the import API accepted a stream containing an NDJSON file, and the export API produced an array of saved objects. Now, the import API accepts a stream of saved objects, and the export API produces a stream of saved objects. The HTTP routes were updated accordingly to handle the streams.

The motivation is to allow the result of the export operation to be directly used in the import operation server-side, similar to:
importSavedObjects(exportSavedObjects(...));.

As a result, the transformation to/from NDJSON has been moved to the http route handlers, so that server-side consumers (such as #38014) do not need to concern themselves with this file format, but can instead use the streams directly.

Why streams instead of simple lists?

At one point, we had talked about updating the import/export APIs to accept lists of objects, but @mikecote mentioned that we were considering going stream based to eventually get relax the export/import size limit that exists today. The import API already accepted a stream, so it wasn't much of a lift to finish the conversion.

This does not change the public API

The public api remains unchanged by this PR. The request/response are not streamed as a result of this change.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

`);
});

test('filters out empty lines', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This diff is hard to read. The filters out empty lines test was removed from here, but added here

@legrego legrego added Feature:Saved Objects release_note:skip Skip the PR/issue when compiling release notes labels Jun 27, 2019
@legrego legrego marked this pull request as ready for review June 27, 2019 15:49
@legrego legrego requested a review from a team as a code owner June 27, 2019 15:49
@legrego legrego requested a review from mikecote June 27, 2019 15:49
@elasticmachine

This comment has been minimized.

@legrego legrego added the review label Jun 27, 2019
Copy link
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

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

Code changes LGTM.

@elasticmachine
Copy link
Contributor

💔 Build Failed

return h
.response(docsToExport.map(doc => stringify(doc)).join('\n'))
.response(docsToExport.join('\n'))
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we response with Stream? should reduce memory & CPU footprint as well

Copy link
Member Author

Choose a reason for hiding this comment

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

I intentionally left this as a normal, non-streamed response. I didn't feel comfortable changing that as part of this PR. Maybe that's something we can investigate when we migrate these routes to the NP. Does the NP allow for streaming responses?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Awesome!

@@ -19,6 +19,12 @@

import { getSortedObjectsForExport } from './get_sorted_objects_for_export';
import { SavedObjectsClientMock } from '../service/saved_objects_client.mock';
import { Readable } from 'stream';
import { createPromiseFromStreams, createConcatStream } from '../../../../legacy/utils/streams';
Copy link
Contributor

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.

Copy link
Contributor

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.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

legrego added a commit to legrego/kibana that referenced this pull request Jul 1, 2019
* transform ndjson within route handlers for SO import/export APIs

* convert export saved objects to return a stream

* fix stream creation
legrego added a commit that referenced this pull request Jul 1, 2019
* transform ndjson within route handlers for SO import/export APIs

* convert export saved objects to return a stream

* fix stream creation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Saved Objects release_note:skip Skip the PR/issue when compiling release notes review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants