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

View File

@@ -68,8 +68,7 @@ public class JpaRolloutHandler implements RolloutHandler {
return; return;
} }
final String tenant = tenantAware.getCurrentTenant(); final String handlerId = createRolloutLockKey(tenantAware.getCurrentTenant());
final String handlerId = createRolloutLockKey(tenant);
final Lock lock = lockRegistry.obtain(handlerId); final Lock lock = lockRegistry.obtain(handlerId);
if (!lock.tryLock()) { if (!lock.tryLock()) {
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
@@ -79,16 +78,14 @@ public class JpaRolloutHandler implements RolloutHandler {
} }
try { try {
log.debug("[{}] Trigger handling {} rollouts.", tenant, rollouts.size()); log.debug("Trigger handling {} rollouts.", rollouts.size());
rollouts.forEach(rolloutId -> { rollouts.forEach(rolloutId -> {
try { try {
log.debug("[{}] Handling rollout {}", tenant, rolloutId);
handleRolloutInNewTransaction(rolloutId, handlerId); handleRolloutInNewTransaction(rolloutId, handlerId);
log.debug("[{}] Rollout {} processed", tenant, rolloutId);
} catch (final Throwable throwable) { } 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 { } finally {
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
log.trace("Unlock lock {}", lock); 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}. * wraps any catchable exception into a {@link RuntimeException}.
* *
* @param <T> the return type * @param <T> the return type
@@ -111,7 +111,6 @@ public class MDCHandler {
final String user = springSecurityAuditorAware final String user = springSecurityAuditorAware
.getCurrentAuditor() .getCurrentAuditor()
.filter(username -> !username.equals("system")) // null and system are the same - system user .filter(username -> !username.equals("system")) // null and system are the same - system user
.map(username -> (securityContext != null && securityContext.isCurrentThreadSystemCode() ? "as " : "") + username)
.orElse(null); .orElse(null);
final String currentUser = MDC.get(MDC_KEY_USER); final String currentUser = MDC.get(MDC_KEY_USER);