Hey guys, making a Kibana plugin.
I'm uploading a large-ish (think 100mb) file with HTTP2 multipart/form-data, and streaming the data into a GCP bucket. I was able to do this cleanly with the old plugin, with the following code as a Hapi.js route. I'm not able to do this with the new plugin, because it looks like Kibana is wrapping the Hapi.js a little bit, and some options appear to be different.
Here is the old, pure Hapi.js route definition:
server.route({
path: '/api/myPlugin/file/upload',
method: 'POST',
config: {
validate: { payload: null }, // This was null due to memory issues.
payload: {
maxBytes: 1073741824,
output: 'stream',
parse: true,
},
},
async handler(req: any, h: any): Promise<boolean> {
try {
await fileCon.uploadFile(req.payload);
return true;
} catch (e) {
return h.response('Error updating File: ' + e.message).code(400);
}
},
});
This seemed to work just fine. The request would go through, taking 20ish seconds to upload a binary that was about 100MB.
The new plugin framework has Kibana wrapping the Hapi.js router, and I'm not able to use this, and have to rewrite. I've been able to do this with all of my other routes, but I'm having an issue with this one.
router.post({
path: '/api/myPlugin/file/upload',
validate: {
body: schema.object({
file: schema.stream(),
}),
},
options: {
body: {
output: 'stream',
parse: true,
maxBytes: 1073741824,
},
},
},
async (ctx, req, res) => {
try {
const { file } = req.body;
await fileCon.uploadFile(file);
return res.ok({
body: { success: true },
});
} catch (e) {
return res.internalError({ body: e });
}
});
My client (we browser) uploads for 20-ish seconds, the Kibana rejects the request with a 408 Timeout. This happens before any of my server-side code is called.
Another sidenote, is that my plugin code would be called before the upload finished, whereas here, my code doesn't appear to be called until after the upload finished. I do not believe the router is properly streaming the content.
Is there a way with the new plugin structure that I can give a raw Hapi.js route definition like the first option to the plugin's router? Can i override timeout settings?