This is an automated email from the ASF dual-hosted git repository.
yui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new d19239d support spi in javaagent (#2334)
d19239d is described below
commit d19239d3b216b98c736e03921c6191ec896411c1
Author: YuDong Tang <[email protected]>
AuthorDate: Thu Nov 11 11:00:25 2021 +0800
support spi in javaagent (#2334)
* agent run
* support spi in shenyu agent
---
shenyu-agent/shenyu-agent-api/pom.xml | 8 ++++++++
.../org/apache/shenyu/agent/spi/PluginAdviceDef.java | 3 +++
shenyu-agent/shenyu-agent-core/pom.xml | 5 -----
.../java/org/apache/shenyu/agent/AgentInstaller.java | 8 +++-----
.../agent/tracing/jaeger/JaegerPluginAdviceDef.java | 2 ++
.../shenyu/org.apache.shenyu.agent.spi.PluginAdviceDef | 17 +++++++++++++++++
6 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/shenyu-agent/shenyu-agent-api/pom.xml
b/shenyu-agent/shenyu-agent-api/pom.xml
index 8a595ba..ca0ac36 100644
--- a/shenyu-agent/shenyu-agent-api/pom.xml
+++ b/shenyu-agent/shenyu-agent-api/pom.xml
@@ -26,5 +26,13 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-agent-api</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
diff --git
a/shenyu-agent/shenyu-agent-api/src/main/java/org/apache/shenyu/agent/spi/PluginAdviceDef.java
b/shenyu-agent/shenyu-agent-api/src/main/java/org/apache/shenyu/agent/spi/PluginAdviceDef.java
index 37b82df..157255b 100644
---
a/shenyu-agent/shenyu-agent-api/src/main/java/org/apache/shenyu/agent/spi/PluginAdviceDef.java
+++
b/shenyu-agent/shenyu-agent-api/src/main/java/org/apache/shenyu/agent/spi/PluginAdviceDef.java
@@ -17,9 +17,12 @@
package org.apache.shenyu.agent.spi;
+import org.apache.shenyu.spi.SPI;
+
/**
* PluginAdviceDef.
*/
+@SPI
public interface PluginAdviceDef {
/**
diff --git a/shenyu-agent/shenyu-agent-core/pom.xml
b/shenyu-agent/shenyu-agent-core/pom.xml
index c7688d9..61dc893 100644
--- a/shenyu-agent/shenyu-agent-core/pom.xml
+++ b/shenyu-agent/shenyu-agent-core/pom.xml
@@ -56,7 +56,6 @@
<configuration>
<artifactSet>
<excludes>
- <exclude>org.slf4j:*</exclude>
<exclude>net.bytebuddy:*</exclude>
<exclude>com.google.errorprone:error_prone_annotations:jar:</exclude>
<exclude>com.google.code.findbugs:jsr305:jar:</exclude>
@@ -67,10 +66,6 @@
</artifactSet>
<relocations>
<relocation>
- <pattern>com.google</pattern>
-
<shadedPattern>${shade.package}.com.google</shadedPattern>
- </relocation>
- <relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>${shade.package}.org.apache.commons</shadedPattern>
</relocation>
diff --git
a/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/AgentInstaller.java
b/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/AgentInstaller.java
index 18dde34..1e1e21a 100644
---
a/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/AgentInstaller.java
+++
b/shenyu-agent/shenyu-agent-core/src/main/java/org/apache/shenyu/agent/AgentInstaller.java
@@ -24,7 +24,7 @@ import net.bytebuddy.matcher.ElementMatchers;
import org.apache.shenyu.agent.matcher.SafeErasureMatcher;
import org.apache.shenyu.agent.matcher.HasParentTypeMatcher;
import org.apache.shenyu.agent.spi.PluginAdviceDef;
-import org.apache.shenyu.agent.tracing.jaeger.JaegerPluginAdviceDef;
+import org.apache.shenyu.spi.ExtensionLoader;
import java.lang.instrument.Instrumentation;
@@ -46,11 +46,9 @@ public class AgentInstaller {
* @param inst the instrumentation.
*/
public static void installBytebuddyAgent(final Instrumentation inst) {
- // todo load config from file or cmd args
- // todo choose trace type according to config
// todo start trace exporter according to traceType
- // todo start instrument(use spi to get advice class name)
- PluginAdviceDef pluginAdviceDef = new JaegerPluginAdviceDef();
+ String traceType = System.getProperty("shenyu.agent.trace", "jaeger");
+ PluginAdviceDef pluginAdviceDef =
ExtensionLoader.getExtensionLoader(PluginAdviceDef.class).getJoin(traceType);
AgentBuilder agent = new AgentBuilder.Default()
.disableClassFormatChanges()
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
diff --git
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/tracing/jaeger/JaegerPluginAdviceDef.java
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/tracing/jaeger/JaegerPluginAdviceDef.java
index 0f9db5f..474b816 100644
---
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/tracing/jaeger/JaegerPluginAdviceDef.java
+++
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/java/org/apache/shenyu/agent/tracing/jaeger/JaegerPluginAdviceDef.java
@@ -18,10 +18,12 @@
package org.apache.shenyu.agent.tracing.jaeger;
import org.apache.shenyu.agent.spi.PluginAdviceDef;
+import org.apache.shenyu.spi.Join;
/**
* JaegerPluginAdviceDef.
*/
+@Join
public class JaegerPluginAdviceDef implements PluginAdviceDef {
@Override
diff --git
a/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/resources/META-INF/shenyu/org.apache.shenyu.agent.spi.PluginAdviceDef
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/resources/META-INF/shenyu/org.apache.shenyu.agent.spi.PluginAdviceDef
new file mode 100644
index 0000000..463b91b
--- /dev/null
+++
b/shenyu-agent/shenyu-agent-plugins/shenyu-agent-plugin-tracing/shenyu-agent-plugin-tracing-jaeger/src/main/resources/META-INF/shenyu/org.apache.shenyu.agent.spi.PluginAdviceDef
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+jaeger=org.apache.shenyu.agent.tracing.jaeger.JaegerPluginAdviceDef