parallel-consumer
parallel-consumer copied to clipboard
Feature Request: Unique thread names for PC instances for logging
Parallel consumer assigns names to its internal control threads which look like: pc-broker-poll, pc-control.
We have a scenario with multiple PC instances within one Java application. In that case we can't easily identify to which PC instance a log entry belongs (because even when logging the thread ids, it won't be directly visible which pc-control and pc-broker-poll threads belong together).
As improvement I'd suggest to internally generate an id for each PC instance that is created and put it into the thread names (like pc-1-broker-poll, pc-1-control, pc-2-broker-poll, pc-2-control, ...).
This actually already exists, but isn't used for logging. I'll look at adding to the the loggers MDC.
See AbstractParallelEoSStreamProcessor#setMyId
Ah - this is actually already mapped to the MPD under the id pcId, for example, the test logger uses:
<pattern>%d{mm:ss.SSS} %X{pcId} %highlight(%-5level) %yellow([%thread]) %X{offset} %cyan(\(%file:%line\)#%M) %msg%n</pattern>
However I suspect the MDC isn't being set in all the threads properly.
Also, we should consider moving this to the options class.
Actually the controlTask build in AbstractParallelEoSStreamProcessor#controlTask adds myId to the MDC before starting to run the controlLoop. However processWorkCompleteMailBox which is called from within every run of the controlLoop clears the MDC.
I'm not sure whether it should just call MDC.remove("offset"), keeping potential side effects from wm.handleFutureResult(work) inside the MDC or keep MDC.clear() and re-add myId. In any case that's a quite simple thing to fix.
But I'm with you there are probably more places that require adjustments.