elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.76k stars 8.17k forks source link

[Screenshotting/PDF Worker Thread] Find a way to send log messages from the worker to the main thread #194493

Open tsullivan opened 3 days ago

tsullivan commented 3 days ago

Kibana Screenshotting uses a worker thread to generate a PDF file by embedding a PNG buffer into a PDF template. This worker thread has the function to send buffer data back to the main thread for storage.

Today, the worker thread doesn't create any log messages, because it doesn't have any context from Kibana and doesn't have a reference to any dependencies. This issue creates a situation where it's hard to understand any potential failure, such as the generic "Worker did not generate a PDF" error.

The worker thread should be able to send different types of messages to the parent thread: a type for the buffer data and a type for the log messages. This can be done by adding a type property to the payloads sent from the worker thread.

// Send log message to the main thread
port.postMessage({ type: 'log', message: 'Worker started generating buffer data' });

// Send the buffer data back to the main thread
port.postMessage({ type: 'data', response: successResponse }, [buffer.buffer /* transfer ownership of the data to the main thread instead of copying it */]);

// Keep sending status logs
port.postMessage({ type: 'log', message: 'Worker completed' });
elasticmachine commented 3 days ago

Pinging @elastic/appex-sharedux (Team:SharedUX)