This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new c69edc71ec0 Refactor agent bootstrap (#23111)
c69edc71ec0 is described below
commit c69edc71ec09cc77c30eda6184e53fb984c646e8
Author: 孙念君 Nianjun Sun <[email protected]>
AuthorDate: Fri Dec 30 00:41:42 2022 +0800
Refactor agent bootstrap (#23111)
* Refactor : refactor the agent distribution shaded dependencies (#23049)
* Refactor : refactor the shade plugin for plugins module into a release
profile (#23049)
* Refactor : upadte the proxy retry time from 30 to 60 to ensure the
waiting time (#23049)
* Refactor : update the opentelemetry precondition (#23118)
* Fix : fix an error command (#23118)
* Refactor : increate the retry time to avoid local test failure
* Add : package lib folder for external library
* Add : support lib directory for agent classloader (#23118)
* Fix : fix the failed junit test (#23118)
* Revert : revert the changes in AgentPathBuilder (#23118)
* Refactor : rename the plugins path name (#23118)
* Refactor : refactor the classloader get the jar files from multiple path
(#23118)
* Fix : fix a checkstyle issue (#23118)
* Refactor : add new line to seperate the different type of dependencies
(#23118)
* Refactor : revert the prevous change for agent plugins module shade
plugin (#23118)
* Refactor : remove useless exclude and add minimizeJar for shade plugin
(#23118)
* Refactor : refactor the docker related files (#23118)
* Refactor : remove useless dependency from bootstrap (#23118)
* Refactor : remove useless relocation from shade plugin (#23118)
* Refactor : refactor the resource (#23118)
---
.../agent/advice/type/ConstructorAdvice.java | 2 +-
agent/bootstrap/pom.xml | 11 ++++++-----
.../agent/bootstrap/path/AgentPathBuilder.java | 10 ++++++----
.../agent/bootstrap/plugin/loader/AgentPluginLoader.java | 12 ++++++++++--
.../assembly/shardingsphere-agent-binary-distribution.xml | 10 ++++++++++
agent/plugins/metrics/core/pom.xml | 15 +++++++++++++++
agent/plugins/pom.xml | 5 +++++
agent/plugins/tracing/pom.xml | 1 +
.../metrics/src/test/resources/env/engine-env.properties | 2 +-
.../src/test/resources/env/engine-env.properties | 2 +-
10 files changed, 56 insertions(+), 14 deletions(-)
diff --git
a/agent/api/src/main/java/org/apache/shardingsphere/agent/advice/type/ConstructorAdvice.java
b/agent/api/src/main/java/org/apache/shardingsphere/agent/advice/type/ConstructorAdvice.java
index 1c22c393e3f..7d291356cca 100644
---
a/agent/api/src/main/java/org/apache/shardingsphere/agent/advice/type/ConstructorAdvice.java
+++
b/agent/api/src/main/java/org/apache/shardingsphere/agent/advice/type/ConstructorAdvice.java
@@ -27,7 +27,7 @@ public interface ConstructorAdvice extends AgentAdvice {
/**
* Intercept the target's constructor.
- * This method is weaved after the constructor execution.
+ * This method is woven after the constructor execution.
*
* @param target intercepted target object
* @param args all arguments of the intercepted constructor
diff --git a/agent/bootstrap/pom.xml b/agent/bootstrap/pom.xml
index 6ddc357baa3..e8560da451f 100644
--- a/agent/bootstrap/pom.xml
+++ b/agent/bootstrap/pom.xml
@@ -37,6 +37,12 @@
<artifactId>shardingsphere-agent-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-agent-plugin-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
@@ -46,11 +52,6 @@
<artifactId>logback-classic</artifactId>
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-agent-plugin-core</artifactId>
- <version>${project.version}</version>
- </dependency>
</dependencies>
<build>
diff --git
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/path/AgentPathBuilder.java
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/path/AgentPathBuilder.java
index e17a8fbadd2..d5d26781353 100644
---
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/path/AgentPathBuilder.java
+++
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/path/AgentPathBuilder.java
@@ -26,6 +26,8 @@ import java.io.File;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Objects;
/**
@@ -38,11 +40,11 @@ public final class AgentPathBuilder {
private static File agentPath;
@Getter
- private static File pluginPath;
+ private static Collection<File> pluginClassPaths;
static {
agentPath = buildAgentPath();
- pluginPath = buildAgentPluginPath();
+ pluginClassPaths = buildAgentPluginClassPaths();
}
private static File buildAgentPath() {
@@ -71,7 +73,7 @@ public final class AgentPathBuilder {
return new File(classLocation);
}
- private static File buildAgentPluginPath() {
- return new File(String.join("/", agentPath.getPath(), "plugins"));
+ private static Collection<File> buildAgentPluginClassPaths() {
+ return Arrays.asList(new File(String.join("/", agentPath.getPath(),
"lib")), new File(String.join("/", agentPath.getPath(), "plugins")));
}
}
diff --git
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/plugin/loader/AgentPluginLoader.java
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/plugin/loader/AgentPluginLoader.java
index 9c488c238fa..80d2f2e04d3 100644
---
a/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/plugin/loader/AgentPluginLoader.java
+++
b/agent/bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/plugin/loader/AgentPluginLoader.java
@@ -26,9 +26,11 @@ import
org.apache.shardingsphere.agent.bootstrap.plugin.PluginJar;
import java.io.File;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
+import java.util.List;
import java.util.jar.JarFile;
/**
@@ -46,8 +48,9 @@ public final class AgentPluginLoader {
* @throws IOException IO exception
*/
public static Collection<PluginJar> load() throws IOException {
- File[] jarFiles = AgentPathBuilder.getPluginPath().listFiles(each ->
each.getName().endsWith(".jar"));
- if (null == jarFiles) {
+ List<File> jarFiles = new LinkedList<>();
+ AgentPathBuilder.getPluginClassPaths().forEach(each ->
jarFiles.addAll(collectJarFiles(each)));
+ if (jarFiles.isEmpty()) {
return Collections.emptyList();
}
Collection<PluginJar> result = new LinkedList<>();
@@ -57,4 +60,9 @@ public final class AgentPluginLoader {
}
return result;
}
+
+ private static List<File> collectJarFiles(final File path) {
+ File[] jarFiles = path.listFiles(each ->
each.getName().endsWith(".jar"));
+ return (null == jarFiles || jarFiles.length == 0) ?
Collections.emptyList() : Arrays.asList(jarFiles);
+ }
}
diff --git
a/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
b/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
index 7d6031fc801..2810ba2c02d 100644
---
a/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
+++
b/agent/distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
@@ -53,6 +53,9 @@
<includes>
<include>**.jar</include>
</includes>
+ <excludes>
+
<exclude>shardingsphere-agent-tracing-test-${project.version}.jar</exclude>
+ </excludes>
</fileSet>
<fileSet>
<directory>../plugins/metrics/target/plugins</directory>
@@ -61,6 +64,13 @@
<include>**.jar</include>
</includes>
</fileSet>
+ <fileSet>
+ <directory>../plugins/metrics/target/lib</directory>
+ <outputDirectory>./lib</outputDirectory>
+ <includes>
+ <include>**.jar</include>
+ </includes>
+ </fileSet>
</fileSets>
<moduleSets>
diff --git a/agent/plugins/metrics/core/pom.xml
b/agent/plugins/metrics/core/pom.xml
index b85e90379a3..b4ec8969a2f 100644
--- a/agent/plugins/metrics/core/pom.xml
+++ b/agent/plugins/metrics/core/pom.xml
@@ -27,6 +27,10 @@
<artifactId>shardingsphere-agent-metrics-core</artifactId>
<name>${project.artifactId}</name>
+ <properties>
+ <target.directory>${project.basedir}/../target/lib</target.directory>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
@@ -47,4 +51,15 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-shade-plugin</artifactId>
+ <configuration>
+
<outputFile>${target.directory}/${project.build.finalName}.jar</outputFile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/agent/plugins/pom.xml b/agent/plugins/pom.xml
index 2c664bdcdc2..980fc3d5c86 100644
--- a/agent/plugins/pom.xml
+++ b/agent/plugins/pom.xml
@@ -55,6 +55,7 @@
</goals>
<phase>package</phase>
<configuration>
+ <minimizeJar>true</minimizeJar>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadeSourcesContent>true</shadeSourcesContent>
@@ -87,6 +88,10 @@
<pattern>org.apache.commons</pattern>
<shadedPattern>${shade.package}.org.apache.commons</shadedPattern>
</relocation>
+ <relocation>
+ <pattern>io.netty</pattern>
+
<shadedPattern>${shade.package}.io.netty</shadedPattern>
+ </relocation>
</relocations>
<filters>
<filter>
diff --git a/agent/plugins/tracing/pom.xml b/agent/plugins/tracing/pom.xml
index 05e732a95a3..6665ee29a9c 100644
--- a/agent/plugins/tracing/pom.xml
+++ b/agent/plugins/tracing/pom.xml
@@ -59,6 +59,7 @@
</dependency>
</dependencies>
</dependencyManagement>
+
<build>
<plugins>
<plugin>
diff --git
a/test/e2e/agent/plugins/metrics/src/test/resources/env/engine-env.properties
b/test/e2e/agent/plugins/metrics/src/test/resources/env/engine-env.properties
index 90a38f7b0ce..f96292cda77 100644
---
a/test/e2e/agent/plugins/metrics/src/test/resources/env/engine-env.properties
+++
b/test/e2e/agent/plugins/metrics/src/test/resources/env/engine-env.properties
@@ -21,7 +21,7 @@ it.env.value=metrics
proxy.url=jdbc:mysql://127.0.0.1:43070/agent-metrics-db?serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8
proxy.username=root
proxy.password=root
-proxy.retry=30
+proxy.retry=60
proxy.waitMs=1000
prometheus.waitMs=60000
diff --git
a/test/e2e/agent/plugins/opentelemetry/src/test/resources/env/engine-env.properties
b/test/e2e/agent/plugins/opentelemetry/src/test/resources/env/engine-env.properties
index e7444615ed7..ac2d5d11262 100644
---
a/test/e2e/agent/plugins/opentelemetry/src/test/resources/env/engine-env.properties
+++
b/test/e2e/agent/plugins/opentelemetry/src/test/resources/env/engine-env.properties
@@ -21,7 +21,7 @@ it.env.value=opentelemetry
proxy.url=jdbc:mysql://127.0.0.1:43071/agent-tracing-opentelemetry-db?serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8
proxy.username=root
proxy.password=root
-proxy.retry=30
+proxy.retry=60
proxy.waitMs=1000
opentelemetry.waitMs=60000