You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by mg...@apache.org on 2023/07/10 14:54:38 UTC

[camel] branch tryingToFixLeak updated (12bf21c5a19 -> 52c58f993dd)

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

mgrzejszczak pushed a change to branch tryingToFixLeak
in repository https://gitbox.apache.org/repos/asf/camel.git


 discard 12bf21c5a19 Adding additional logging to scope creation and closing
     new 52c58f993dd Adding additional logging to scope creation and closing

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (12bf21c5a19)
            \
             N -- N -- N   refs/heads/tryingToFixLeak (52c58f993dd)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/test/java/org/apache/camel/observation/MulticastRouteTest.java  | 2 --
 1 file changed, 2 deletions(-)


[camel] 01/01: Adding additional logging to scope creation and closing

Posted by mg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mgrzejszczak pushed a commit to branch tryingToFixLeak
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 52c58f993dd0ecfed12f3945d147d8b017b22ba6
Author: Marcin Grzejszczak <mg...@vmware.com>
AuthorDate: Mon Jul 10 16:50:59 2023 +0200

    Adding additional logging to scope creation and closing
    
    the problem we have is that one of the spans in one of the tests (most probably MulticastRouteTest) is not being closed and the span is left in the test thread. Due to this other tests are failing.
    
    This commit adds a after test check that there is no leaking span (for OTel and Micrometer Observation modules). Also it adds some additional logging on trace level that will store the stacktrace of each scope and when on close the scope is trying to get closed in a wrong thread we can recreate where it was created and where it's being closed.
    
    related to pr gh-10539
---
 .../observation/CamelMicrometerObservationTestSupport.java  |  8 ++++++++
 .../camel-observation/src/test/resources/log4j2.properties  |  2 ++
 .../camel/opentelemetry/CamelOpenTelemetryTestSupport.java  |  7 +++++++
 .../src/test/resources/log4j2.properties                    |  2 ++
 .../java/org/apache/camel/tracing/ActiveSpanManager.java    | 13 +++++++++++++
 5 files changed, 32 insertions(+)

diff --git a/components/camel-observation/src/test/java/org/apache/camel/observation/CamelMicrometerObservationTestSupport.java b/components/camel-observation/src/test/java/org/apache/camel/observation/CamelMicrometerObservationTestSupport.java
index 4022b6f186a..bf660230733 100644
--- a/components/camel-observation/src/test/java/org/apache/camel/observation/CamelMicrometerObservationTestSupport.java
+++ b/components/camel-observation/src/test/java/org/apache/camel/observation/CamelMicrometerObservationTestSupport.java
@@ -57,7 +57,10 @@ import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
 import org.apache.camel.CamelContext;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.apache.camel.tracing.SpanDecorator;
+import org.assertj.core.api.Assertions;
 import org.awaitility.Awaitility;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -87,6 +90,11 @@ class CamelMicrometerObservationTestSupport extends CamelTestSupport {
         this.expected = expected;
     }
 
+    @AfterEach
+    void noLeakingContext() {
+        Assertions.assertThat(Context.current()).as("There must be no leaking span after test").isSameAs(Context.root());
+    }
+
     @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
diff --git a/components/camel-observation/src/test/resources/log4j2.properties b/components/camel-observation/src/test/resources/log4j2.properties
index f54d01bb554..af1e7f203ab 100644
--- a/components/camel-observation/src/test/resources/log4j2.properties
+++ b/components/camel-observation/src/test/resources/log4j2.properties
@@ -25,5 +25,7 @@ appender.out.layout.type=PatternLayout
 appender.out.layout.pattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
 logger.opentelemetry.name=org.apache.camel.observation
 logger.opentelemetry.level=INFO
+logger.tracing.name=org.apache.camel.tracing
+logger.tracing.level=TRACE
 rootLogger.level=INFO
 rootLogger.appenderRef.file.ref=file
diff --git a/components/camel-opentelemetry/src/test/java/org/apache/camel/opentelemetry/CamelOpenTelemetryTestSupport.java b/components/camel-opentelemetry/src/test/java/org/apache/camel/opentelemetry/CamelOpenTelemetryTestSupport.java
index 9555e747dd2..8c8bbf8d867 100644
--- a/components/camel-opentelemetry/src/test/java/org/apache/camel/opentelemetry/CamelOpenTelemetryTestSupport.java
+++ b/components/camel-opentelemetry/src/test/java/org/apache/camel/opentelemetry/CamelOpenTelemetryTestSupport.java
@@ -41,6 +41,8 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.apache.camel.tracing.SpanDecorator;
 import org.awaitility.Awaitility;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,6 +68,11 @@ class CamelOpenTelemetryTestSupport extends CamelTestSupport {
         this.expected = expected;
     }
 
+    @AfterEach
+    void noLeakingContext() {
+        Assertions.assertSame(Context.root(), Context.current(), "There must be no leaking span after test");
+    }
+
     @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
diff --git a/components/camel-opentelemetry/src/test/resources/log4j2.properties b/components/camel-opentelemetry/src/test/resources/log4j2.properties
index 89ff53a8dd5..7db0d5df3cb 100644
--- a/components/camel-opentelemetry/src/test/resources/log4j2.properties
+++ b/components/camel-opentelemetry/src/test/resources/log4j2.properties
@@ -25,5 +25,7 @@ appender.out.layout.type=PatternLayout
 appender.out.layout.pattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
 logger.opentelemetry.name=org.apache.camel.opentelemetry
 logger.opentelemetry.level=INFO
+logger.tracing.name=org.apache.camel.tracing
+logger.tracing.level=TRACE
 rootLogger.level=INFO
 rootLogger.appenderRef.file.ref=file
diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/ActiveSpanManager.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/ActiveSpanManager.java
index b9c502a49f0..392d9880f9c 100644
--- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/ActiveSpanManager.java
+++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/ActiveSpanManager.java
@@ -151,19 +151,32 @@ public final class ActiveSpanManager {
         private final AutoCloseable inner;
         private boolean closed;
 
+        private Throwable exceptionForStacktrace;
+
         public ScopeWrapper(AutoCloseable inner, long startThreadId) {
             this.startThreadId = startThreadId;
             this.inner = inner;
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Created scope {}", inner);
+                this.exceptionForStacktrace = new RuntimeException("To see where this scope got created");
+            }
         }
 
         @Override
         public void close() throws Exception {
             if (!closed && Thread.currentThread().getId() == startThreadId) {
                 closed = true;
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Closing scope {}", inner);
+                }
                 inner.close();
             } else {
                 LOG.debug("not closing scope, closed - {}, started on thread - '{}', current thread - '{}'",
                         closed, startThreadId, Thread.currentThread().getId());
+                if (LOG.isTraceEnabled() && this.exceptionForStacktrace != null) {
+                    LOG.trace("Stacktrace of where we are", new RuntimeException());
+                    LOG.trace("Stacktrace of where the scope was created", this.exceptionForStacktrace);
+                }
             }
         }
     }