Skip to content

Commit

Permalink
set MDC so that one can route minion task logs to separate files clea…
Browse files Browse the repository at this point in the history
…nly (#9400)
  • Loading branch information
klsince authored Sep 15, 2022
1 parent c9587df commit 41c4aca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.pinot.minion.executor.TaskExecutorFactoryRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;


/**
Expand Down Expand Up @@ -85,6 +86,8 @@ public TaskResult run() {
.addPhaseTiming(taskType, MinionQueryPhase.TASK_QUEUEING, jobDequeueTimeMs - jobInQueueTimeMs,
TimeUnit.MILLISECONDS);
try {
// Set taskId in MDC so that one may config logger to route task logs to separate file.
MDC.put("taskId", _taskConfig.getId());
_minionMetrics.addValueToGlobalGauge(MinionGauge.NUMBER_OF_TASKS, 1L);
return runInternal();
} finally {
Expand All @@ -93,6 +96,8 @@ public TaskResult run() {
_minionMetrics
.addPhaseTiming(taskType, MinionQueryPhase.TASK_EXECUTION, executionTimeMs, TimeUnit.MILLISECONDS);
LOGGER.info("Task: {} completed in: {}ms", _taskConfig.getId(), executionTimeMs);
// Clear taskId from MDC to reset it.
MDC.remove("taskId");
}
}

Expand Down
19 changes: 19 additions & 0 deletions pinot-tools/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<Routing name="taskLogs" ignoreExceptions="false">
<Routes pattern="${ctx:taskId}">
<Route>
<RollingFile
name="minionTaskLogs-${ctx:taskId}"
fileName="${env:LOG_ROOT}/minionTaskLogs-${ctx:taskId:-default}.log"
filePattern="${env:LOG_ROOT}/minionTaskLogs-%d{yyyy-MM-dd}-%i.log"
immediateFlush="true">
<PatternLayout pattern="${env:LOG_PATTERN}"/>
<Policies>
<SizeBasedTriggeringPolicy size="19500KB"/>
</Policies>
<DefaultRolloverStrategy max="50"/>
</RollingFile>
</Route>
</Routes>
<!-- Created appender TTL -->
<IdlePurgePolicy timeToLive="15" timeUnit="minutes"/>
</Routing>
</Appenders>
<Loggers>
<Root level="info" additivity="false">
Expand Down

0 comments on commit 41c4aca

Please sign in to comment.