This is an automated email from the ASF dual-hosted git repository. wusheng pushed a commit to branch transform-config in repository https://gitbox.apache.org/repos/asf/skywalking-java.git
commit c41e88653c248cc2f612d7944892a94a53b23af3 Author: Wu Sheng <wu.sh...@foxmail.com> AuthorDate: Fri Oct 27 23:22:47 2023 +0800 Expose `SW_ENABLE_RETRANSFORM_SUPPORT` config to set up the re-transform support explicitly --- CHANGES.md | 3 +++ .../org/apache/skywalking/apm/agent/core/conf/Config.java | 11 +++++++++++ .../java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java | 6 ++++-- apm-sniffer/config/agent.config | 7 +++++++ .../scenarios/retransform-class-scenario/configuration.yml | 1 + .../retransform-class-tomcat-scenario/configuration.yml | 2 ++ 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 96a55eaaa1..876f6a885f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,9 @@ Release Notes. 9.1.0 ------------------ +* **IMPORTANT** Expose `SW_ENABLE_RETRANSFORM_SUPPORT` config to set up the re-transform support explicitly, + and close it by default to keep startup delay low. + This was added and enabled in 9.0.0, and we confirmed it would slow down the service launch. * Fix hbase onConstruct NPE in the file configuration scenario * Fix the issue of createSpan failure caused by invalid request URL in HttpClient 4.x/5.x plugin * Optimize ElasticSearch 6.x 7.x plugin compatibility 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 be7d54a4e4..52ff888e3e 100755 --- 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 @@ -174,6 +174,17 @@ public class Config { * Enable the agent kernel services and instrumentation. */ public static boolean ENABLE = true; + + /** + * Enables the Java agent kernel to run in a mode that supports class re-transformation by other agents. + * It's recommended to use this mode only if the service has more than one SkyWalking agent installed. + * + * Be aware that this mode can slow down class loading. As a result, you might experience a higher + * startup delay (the time it takes for the program to launch and be ready for use). + * + * @since 9.1.0 + */ + public static boolean ENABLE_RETRANSFORM_SUPPORT = false; } public static class OsInfo { 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 8e0c2495b5..d908a36a09 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 @@ -157,8 +157,10 @@ public class SkyWalkingAgent { .with(new SWImplementationContextFactory(NAME_TRAIT)); SWNativeMethodStrategy nativeMethodStrategy = new SWNativeMethodStrategy(NAME_TRAIT); - return new SWAgentBuilderDefault(byteBuddy, nativeMethodStrategy) - .with(AgentBuilder.DescriptionStrategy.Default.POOL_FIRST); + final SWAgentBuilderDefault swAgentBuilder = new SWAgentBuilderDefault(byteBuddy, nativeMethodStrategy); + return Config.Agent.ENABLE_RETRANSFORM_SUPPORT ? + swAgentBuilder.with(AgentBuilder.DescriptionStrategy.Default.POOL_FIRST) + : swAgentBuilder; } private static class Transformer implements AgentBuilder.Transformer { diff --git a/apm-sniffer/config/agent.config b/apm-sniffer/config/agent.config index 1874a77be2..9e26ec8240 100755 --- a/apm-sniffer/config/agent.config +++ b/apm-sniffer/config/agent.config @@ -83,6 +83,13 @@ agent.ssl_cert_chain_path=${SW_AGENT_SSL_CERT_CHAIN_PATH:} # Enable the agent kernel services and instrumentation. agent.enable=${SW_AGENT_ENABLE:true} +# Enables the Java agent kernel to run in a mode that supports class re-transformation by other agents. +# It's recommended to use this mode only if the service has more than one SkyWalking agent installed. +# +# Be aware that this mode can slow down class loading. As a result, you might experience a higher +# startup delay (the time it takes for the program to launch and be ready for use). +agent.enable_retransform_support={SW_ENABLE_RETRANSFORM_SUPPORT:false} + # Limit the length of the ipv4 list size. osinfo.ipv4_list_size=${SW_AGENT_OSINFO_IPV4_LIST_SIZE:10} diff --git a/test/plugin/scenarios/retransform-class-scenario/configuration.yml b/test/plugin/scenarios/retransform-class-scenario/configuration.yml index 47884e13c2..3fed3457f6 100644 --- a/test/plugin/scenarios/retransform-class-scenario/configuration.yml +++ b/test/plugin/scenarios/retransform-class-scenario/configuration.yml @@ -19,5 +19,6 @@ entryService: http://localhost:8080/case/retransform-class-scenario healthCheck: http://localhost:8080/case/healthCheck startScript: ./bin/startup.sh environment: + - SW_ENABLE_RETRANSFORM_SUPPORT="true" dependencies: withPlugins: apm-spring-*.jar, apm-jdk-*.jar diff --git a/test/plugin/scenarios/retransform-class-tomcat-scenario/configuration.yml b/test/plugin/scenarios/retransform-class-tomcat-scenario/configuration.yml index 51a59ec13e..852cb7e547 100644 --- a/test/plugin/scenarios/retransform-class-tomcat-scenario/configuration.yml +++ b/test/plugin/scenarios/retransform-class-tomcat-scenario/configuration.yml @@ -19,3 +19,5 @@ entryService: http://localhost:8080/retransform-class-tomcat-scenario/case/retra healthCheck: http://localhost:8080/retransform-class-tomcat-scenario/case/healthCheck dependencies: withPlugins: apm-spring-*.jar, apm-jdk-*.jar +environment: + - CATALINA_OPTS="-Dskywalking.agent.enable_retransform_support=true" \ No newline at end of file