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' });
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.