parallel-consumer icon indicating copy to clipboard operation
parallel-consumer copied to clipboard

Feature Request: Unique thread names for PC instances for logging

Open nioertel opened this issue 2 years ago • 4 comments

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, ...).

nioertel avatar Feb 14 '22 09:02 nioertel

This actually already exists, but isn't used for logging. I'll look at adding to the the loggers MDC.

See AbstractParallelEoSStreamProcessor#setMyId

astubbs avatar Feb 15 '22 15:02 astubbs

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>

astubbs avatar Feb 15 '22 15:02 astubbs

However I suspect the MDC isn't being set in all the threads properly.

Also, we should consider moving this to the options class.

astubbs avatar Feb 15 '22 21:02 astubbs

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.

nioertel avatar Feb 18 '22 12:02 nioertel