Fix/jparolloutshandlerlogging (#1819)

Fix JpaExecutorHandler logging MDC context

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-08-13 09:30:09 +03:00
committed by GitHub
parent 9bb61fd829
commit 12928a5939
3 changed files with 8 additions and 10 deletions

View File

@@ -155,7 +155,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
@Override
public void execute(final Rollout rollout) {
log.debug("handle rollout {}", rollout.getId());
log.debug("Processing rollout {}", rollout.getId());
switch (rollout.getStatus()) {
case CREATING:
@@ -201,6 +201,8 @@ public class JpaRolloutExecutor implements RolloutExecutor {
log.error("Rollout in status {} not supposed to be handled!", rollout.getStatus());
break;
}
log.debug("Rollout {} processed", rollout.getId());
}
private void handleCreateRollout(final JpaRollout rollout) {

View File

@@ -68,8 +68,7 @@ public class JpaRolloutHandler implements RolloutHandler {
return;
}
final String tenant = tenantAware.getCurrentTenant();
final String handlerId = createRolloutLockKey(tenant);
final String handlerId = createRolloutLockKey(tenantAware.getCurrentTenant());
final Lock lock = lockRegistry.obtain(handlerId);
if (!lock.tryLock()) {
if (log.isTraceEnabled()) {
@@ -79,16 +78,14 @@ public class JpaRolloutHandler implements RolloutHandler {
}
try {
log.debug("[{}] Trigger handling {} rollouts.", tenant, rollouts.size());
log.debug("Trigger handling {} rollouts.", rollouts.size());
rollouts.forEach(rolloutId -> {
try {
log.debug("[{}] Handling rollout {}", tenant, rolloutId);
handleRolloutInNewTransaction(rolloutId, handlerId);
log.debug("[{}] Rollout {} processed", tenant, rolloutId);
} catch (final Throwable throwable) {
log.error("[{}] Failed to process rollout with id {}", tenant, rolloutId , throwable);
log.error("Failed to process rollout with id {}", rolloutId , throwable);
}});
log.debug("[{}] Finished handling of the rollouts.", tenant);
log.debug("Finished handling of the rollouts.");
} finally {
if (log.isTraceEnabled()) {
log.trace("Unlock lock {}", lock);

View File

@@ -90,7 +90,7 @@ public class MDCHandler {
}
/**
* With logging throwing Runtime Exception (wihtLoggingRE). Calls the {@link #withLogging(Callable)} method and
* With logging throwing Runtime Exception (withLoggingRE). Calls the {@link #withLogging(Callable)} method and
* wraps any catchable exception into a {@link RuntimeException}.
*
* @param <T> the return type
@@ -111,7 +111,6 @@ public class MDCHandler {
final String user = springSecurityAuditorAware
.getCurrentAuditor()
.filter(username -> !username.equals("system")) // null and system are the same - system user
.map(username -> (securityContext != null && securityContext.isCurrentThreadSystemCode() ? "as " : "") + username)
.orElse(null);
final String currentUser = MDC.get(MDC_KEY_USER);