You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/06/21 14:35:19 UTC

[skywalking] branch boorstrap-enhance created (now d8bbf9a)

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

wusheng pushed a change to branch boorstrap-enhance
in repository https://gitbox.apache.org/repos/asf/skywalking.git.


      at d8bbf9a  Support bootstrap class enhance and fix OOM by empty stack of exception.

This branch includes the following new commits:

     new d8bbf9a  Support bootstrap class enhance and fix OOM by empty stack of exception.

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.



[skywalking] 01/01: Support bootstrap class enhance and fix OOM by empty stack of exception.

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

wusheng pushed a commit to branch boorstrap-enhance
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit d8bbf9a708987db81b4fbdeee8dc70e98598703b
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Fri Jun 21 22:34:48 2019 +0800

    Support bootstrap class enhance and fix OOM by empty stack of exception.
---
 .../skywalking/apm/agent/core/conf/Config.java     | 10 +++++++
 .../core/context/util/ThrowableTransformer.java    | 19 ++++++++++--
 .../skywalking/apm/agent/SkyWalkingAgent.java      | 34 +++++++++++++++-------
 3 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
index 1c12100..901b9c5 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
@@ -88,6 +88,16 @@ public class Config {
          * The identify of the instance
          */
         public static String INSTANCE_UUID = "";
+
+        /**
+         *  The folder in which jar files of the injected classes are to be stored.
+         */
+        public static String BOOTSTRAP_CLASS_JAR_FOLDER = "";
+
+        /**
+         * How depth the agent goes, when log all cause exceptions.
+         */
+        public static int CAUSE_EXCEPTION_DEPTH = 5;
     }
 
     public static class Collector {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java
index b5f4ef1..757db44 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java
@@ -19,6 +19,8 @@
 
 package org.apache.skywalking.apm.agent.core.context.util;
 
+import static org.apache.skywalking.apm.agent.core.conf.Config.Agent.CAUSE_EXCEPTION_DEPTH;
+
 /**
  * {@link ThrowableTransformer} is responsible for transferring stack trace of throwable.
  */
@@ -30,10 +32,12 @@ public enum ThrowableTransformer {
     public String convert2String(Throwable throwable, final int maxLength) {
         final StringBuilder stackMessage = new StringBuilder();
         Throwable causeException = throwable;
-        while (causeException != null) {
+
+        int depth = CAUSE_EXCEPTION_DEPTH;
+        while (causeException != null || depth == 0) {
             stackMessage.append(printExceptionInfo(causeException));
 
-            boolean overMaxLength = printStackElement(throwable.getStackTrace(), new AppendListener() {
+            boolean isLookDeeper = printStackElement(throwable.getStackTrace(), new AppendListener() {
                 public void append(String value) {
                     stackMessage.append(value);
                 }
@@ -43,11 +47,12 @@ public enum ThrowableTransformer {
                 }
             });
 
-            if (overMaxLength) {
+            if (isLookDeeper) {
                 break;
             }
 
             causeException = throwable.getCause();
+            depth--;
         }
 
         return stackMessage.toString();
@@ -58,6 +63,14 @@ public enum ThrowableTransformer {
     }
 
     private boolean printStackElement(StackTraceElement[] stackTrace, AppendListener printListener) {
+        if (stackTrace.length == 0) {
+            /**
+             * In some cases, people would fill empty stackTrace intentionally.
+             * This is a quick stop.
+             */
+            return true;
+        }
+
         for (StackTraceElement traceElement : stackTrace) {
             printListener.append("at " + traceElement + LINE_SEPARATOR);
             if (printListener.overMaxLength()) {
diff --git a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
index 516c1cd..84faa84 100644
--- a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
+++ b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
@@ -18,6 +18,7 @@
 
 package org.apache.skywalking.apm.agent;
 
+import java.io.File;
 import net.bytebuddy.ByteBuddy;
 import net.bytebuddy.agent.builder.AgentBuilder;
 import net.bytebuddy.description.NamedElement;
@@ -38,8 +39,10 @@ import org.apache.skywalking.apm.agent.core.plugin.*;
 
 import java.lang.instrument.Instrumentation;
 import java.util.List;
+import org.apache.skywalking.apm.util.StringUtil;
 
 import static net.bytebuddy.matcher.ElementMatchers.*;
+import static org.apache.skywalking.apm.agent.core.conf.Config.Agent.BOOTSTRAP_CLASS_JAR_FOLDER;
 
 /**
  * The main entrance of sky-walking agent, based on javaagent mechanism.
@@ -77,18 +80,29 @@ public class SkyWalkingAgent {
         final ByteBuddy byteBuddy = new ByteBuddy()
             .with(TypeValidation.of(Config.Agent.IS_OPEN_DEBUGGING_CLASS));
 
-        new AgentBuilder.Default(byteBuddy)
+        AgentBuilder agentBuilder = new AgentBuilder.Default(byteBuddy);
+        agentBuilder = agentBuilder
             .ignore(
                 nameStartsWith("net.bytebuddy.")
-                .or(nameStartsWith("org.slf4j."))
-                .or(nameStartsWith("org.apache.logging."))
-                .or(nameStartsWith("org.groovy."))
-                .or(nameContains("javassist"))
-                .or(nameContains(".asm."))
-                .or(nameStartsWith("sun.reflect"))
-                .or(allSkyWalkingAgentExcludeToolkit())
-                .or(ElementMatchers.<TypeDescription>isSynthetic()))
-            .type(pluginFinder.buildMatch())
+                    .or(nameStartsWith("org.slf4j."))
+                    .or(nameStartsWith("org.apache.logging."))
+                    .or(nameStartsWith("org.groovy."))
+                    .or(nameContains("javassist"))
+                    .or(nameContains(".asm."))
+                    .or(nameStartsWith("sun.reflect"))
+                    .or(allSkyWalkingAgentExcludeToolkit())
+                    .or(ElementMatchers.<TypeDescription>isSynthetic()));
+
+        if (!StringUtil.isEmpty(BOOTSTRAP_CLASS_JAR_FOLDER)) {
+            File jarFolder = new File(BOOTSTRAP_CLASS_JAR_FOLDER);
+            if (jarFolder.exists() && jarFolder.isDirectory()) {
+                agentBuilder = agentBuilder.enableBootstrapInjection(instrumentation, jarFolder);
+            } else {
+                logger.warn("Bootstrap class jar folder [{}] can't be found.", BOOTSTRAP_CLASS_JAR_FOLDER);
+            }
+        }
+
+        agentBuilder.type(pluginFinder.buildMatch())
             .transform(new Transformer(pluginFinder))
             .with(new Listener())
             .installOn(instrumentation);