This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit c060b0c60385833f73fef3335793bfa552482a72
Author: Alex Heneveld <[email protected]>
AuthorDate: Mon Sep 13 22:30:37 2021 +0100

    skip extra MDC task logging
---
 .../brooklyn/util/core/task/BasicExecutionManager.java      | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
 
b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
index d7af2c0..706edeb 100644
--- 
a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
+++ 
b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
@@ -28,6 +28,7 @@ import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CancellationException;
@@ -135,6 +136,7 @@ public class BasicExecutionManager implements 
ExecutionManager {
             return new BrooklynTaskLoggingMdc().withTask(task);
         }
 
+        boolean isRedundant = false;
         Task task;
         MDC.MDCCloseable taskMdc=null, entityMdc=null;
         String prevTaskMdc, prevEntityMdc;
@@ -155,6 +157,10 @@ public class BasicExecutionManager implements 
ExecutionManager {
             // can misleadingly point point to the task which triggered the 
executor
             if (task!=null) {
                 prevTaskMdc = MDC.get(LOGGING_MDC_KEY_TASK_ID);
+                if (Objects.equals(task.getId(), prevTaskMdc)) {
+                    isRedundant = true;
+                    return this;
+                }
                 taskMdc = MDC.putCloseable(LOGGING_MDC_KEY_TASK_ID, 
task.getId());
             }
             if (entity != null) {
@@ -162,7 +168,7 @@ public class BasicExecutionManager implements 
ExecutionManager {
                 entityMdc = MDC.putCloseable(LOGGING_MDC_KEY_ENTITY_IDS, "[" + 
entity.getApplicationId() + "," + entity.getId() + "]");
             }
 
-            if (BrooklynLoggingCategories.TASK_LIFECYCLE_LOG.isDebugEnabled() 
|| BrooklynLoggingCategories.TASK_LIFECYCLE_LOG.isTraceEnabled()){
+            if (BrooklynLoggingCategories.TASK_LIFECYCLE_LOG.isDebugEnabled() 
|| BrooklynLoggingCategories.TASK_LIFECYCLE_LOG.isTraceEnabled()) {
                 String taskName = task.getDisplayName();
                 String message = "Starting task " + task.getId() +
                         (Strings.isNonBlank(taskName) ? " ("+taskName+")" : 
"") +
@@ -179,6 +185,9 @@ public class BasicExecutionManager implements 
ExecutionManager {
         }
 
         public void finish() {
+            if (isRedundant) {
+                return;
+            }
             if (BrooklynLoggingCategories.TASK_LIFECYCLE_LOG.isDebugEnabled() 
|| BrooklynLoggingCategories.TASK_LIFECYCLE_LOG.isTraceEnabled()){
                 String taskName = task.getDisplayName();
                 
BrooklynLogging.log(BrooklynLoggingCategories.TASK_LIFECYCLE_LOG,
@@ -1088,7 +1097,7 @@ public class BasicExecutionManager implements 
ExecutionManager {
             taskWasSubmittedAndNotYetEnded = 
incompleteTaskIds.remove(task.getId());
             // this method might be called more than once, eg if cancelled, so 
use the above as a guard where single invocation is needed (eg counts)
 
-            if (!skipDecrementCounter && taskWasSubmittedAndNotYetEnded) {
+            if (taskWasSubmittedAndNotYetEnded) {
                 activeTaskCount.decrementAndGet();
             }
 

Reply via email to