Skip to content

Commit

Permalink
Fix/jparolloutshandlerlogging (#1819)
Browse files Browse the repository at this point in the history
Fix JpaExecutorHandler logging MDC context

Signed-off-by: Marinov Avgustin <[email protected]>
  • Loading branch information
avgustinmm authored Aug 13, 2024
1 parent 9bb61fd commit 12928a5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public JpaRolloutExecutor(

@Override
public void execute(final Rollout rollout) {
log.debug("handle rollout {}", rollout.getId());
log.debug("Processing rollout {}", rollout.getId());

switch (rollout.getStatus()) {
case CREATING:
Expand Down Expand Up @@ -201,6 +201,8 @@ public void execute(final Rollout rollout) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public void handleAll() {
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()) {
Expand All @@ -79,16 +78,14 @@ public void handleAll() {
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public <T> T withLogging(final Callable<T> callable) throws Exception {
}

/**
* 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
Expand All @@ -111,7 +111,6 @@ private <T> T putUserAndCall(final Callable<T> callable) throws Exception {
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);
Expand Down

0 comments on commit 12928a5

Please sign in to comment.