You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by xi...@apache.org on 2020/12/01 09:18:33 UTC
[shardingsphere] branch master updated: Add a tracing plugin sample
(#8443)
This is an automated email from the ASF dual-hosted git repository.
xiaoyu 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 c2d2869 Add a tracing plugin sample (#8443)
c2d2869 is described below
commit c2d2869338523a8f9b55aeadce338e253887464d
Author: Daming <zt...@foxmail.com>
AuthorDate: Tue Dec 1 17:16:42 2020 +0800
Add a tracing plugin sample (#8443)
* a tracing plugin sample
* fix typo
* fix license missing
---
shardingsphere-agent/pom.xml | 6 +-
.../shardingsphere-agent-bootstrap/pom.xml | 1 -
.../shardingsphere-agent-core/pom.xml | 23 -------
.../shardingsphere-agent-binary-distribution.xml | 10 +++-
.../shardingsphere-agent-plugins/pom.xml | 40 +++++--------
.../shardingsphere-agent-plugin-tracers/pom.xml | 70 ++++++++++++++++++++++
.../shardingsphere-agent-tracer-sample}/pom.xml | 19 +++---
.../agent/plugin/trace/SampleAdvice.java | 46 ++++++++++++++
.../agent/plugin/trace/SamplePluginDefine.java | 39 ++++++++++++
.../agent/plugin/trace/SampleTracer.java | 42 +++++++++++++
10 files changed, 236 insertions(+), 60 deletions(-)
diff --git a/shardingsphere-agent/pom.xml b/shardingsphere-agent/pom.xml
index 02c989c..64a9d8e 100644
--- a/shardingsphere-agent/pom.xml
+++ b/shardingsphere-agent/pom.xml
@@ -25,9 +25,13 @@
<artifactId>shardingsphere</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
+
<artifactId>shardingsphere-agent</artifactId>
<packaging>pom</packaging>
- <name>${project.artifactId}</name>
+
+ <properties>
+ <shade.package>org.apache.shardingsphere.dependencies</shade.package>
+ </properties>
<modules>
<module>shardingsphere-agent-bootstrap</module>
diff --git a/shardingsphere-agent/shardingsphere-agent-bootstrap/pom.xml b/shardingsphere-agent/shardingsphere-agent-bootstrap/pom.xml
index 495afbc..da6de01 100644
--- a/shardingsphere-agent/shardingsphere-agent-bootstrap/pom.xml
+++ b/shardingsphere-agent/shardingsphere-agent-bootstrap/pom.xml
@@ -29,7 +29,6 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <shade.package>org.apache.shardingsphere.dependencies</shade.package>
<premain.class>org.apache.shardingsphere.agent.bootstrap.ShardingSphereAgent</premain.class>
<can.redefine.classes>true</can.redefine.classes>
<can.retransform.classes>true</can.retransform.classes>
diff --git a/shardingsphere-agent/shardingsphere-agent-core/pom.xml b/shardingsphere-agent/shardingsphere-agent-core/pom.xml
index 26e89e9..26da717 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/pom.xml
+++ b/shardingsphere-agent/shardingsphere-agent-core/pom.xml
@@ -27,10 +27,6 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>shardingsphere-agent-core</artifactId>
-
- <properties>
- <shade.package>org.apache.shardingsphere.dependencies</shade.package>
- </properties>
<dependencies>
<dependency>
@@ -48,25 +44,6 @@
<version>${bytebuddy.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <version>${lombok.version}</version>
- <scope>provided</scope>
- </dependency>
-
</dependencies>
<build>
diff --git a/shardingsphere-agent/shardingsphere-agent-distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml b/shardingsphere-agent/shardingsphere-agent-distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
index 3593876..20293d4 100644
--- a/shardingsphere-agent/shardingsphere-agent-distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
+++ b/shardingsphere-agent/shardingsphere-agent-distribution/src/main/assembly/shardingsphere-agent-binary-distribution.xml
@@ -39,6 +39,14 @@
<outputDirectory>conf</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
+
+ <fileSet>
+ <directory>${project.basedir}/../shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/target/plugins</directory>
+ <outputDirectory>/plugins</outputDirectory>
+ <includes>
+ <include>**-${module.version}.jar</include>
+ </includes>
+ </fileSet>
</fileSets>
<moduleSets>
@@ -63,7 +71,7 @@
</includes>
<binaries>
<unpack>false</unpack>
- <outputDirectory>/plugin</outputDirectory>
+ <outputDirectory>/plugins</outputDirectory>
<includeDependencies>false</includeDependencies>
<outputFileNameMapping>${module.artifactId}-${module.version}.jar</outputFileNameMapping>
</binaries>
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/pom.xml b/shardingsphere-agent/shardingsphere-agent-plugins/pom.xml
index f512098..604ae90 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/pom.xml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/pom.xml
@@ -27,18 +27,26 @@
<artifactId>shardingsphere-agent-plugins</artifactId>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
+
<modules>
<module>shardingsphere-agent-plugin-metrics</module>
+ <module>shardingsphere-agent-plugin-tracers</module>
</modules>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <shade.package>org.apache.shardingsphere.dependencies</shade.package>
- <shade.net.bytebuddy.source>net.bytebuddy</shade.net.bytebuddy.source>
- <shade.net.bytebuddy.target>${shade.package}.${shade.net.bytebuddy.source}</shade.net.bytebuddy.target>
- </properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-agent-core</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<build>
+ <finalName>${project.artifactId}-${project.version}.jar</finalName>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
@@ -50,30 +58,14 @@
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
- <createDependencyReducedPom>false</createDependencyReducedPom>
+ <createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<shadeSourcesContent>true</shadeSourcesContent>
- <artifactSet>
- <excludes>
- <exclude>net.bytebuddy:byte-buddy:jar:</exclude>
- <exclude>com.google.*:*</exclude>
- <exclude>com.google.guava:guava</exclude>
- <exclude>org.checkerframework:checker-compat-qual</exclude>
- <exclude>org.codehaus.mojo:animal-sniffer-annotations</exclude>
- <exclude>io.perfmark:*</exclude>
- <exclude>org.slf4j:*</exclude>
- </excludes>
- </artifactSet>
- <relocations>
- <relocation>
- <pattern>${shade.net.bytebuddy.source}</pattern>
- <shadedPattern>${shade.net.bytebuddy.target}</shadedPattern>
- </relocation>
- </relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
+
</project>
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/pom.xml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/pom.xml
new file mode 100644
index 0000000..ad391db
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-agent-plugins</artifactId>
+ <version>5.0.0-RC1-SNAPSHOT</version>
+ </parent>
+
+ <packaging>pom</packaging>
+ <artifactId>shardingsphere-agent-plugin-tracers</artifactId>
+
+ <properties>
+ <entrypoint.class/>
+ <tracing.target.directory>${project.basedir}/../target/plugins</tracing.target.directory>
+ </properties>
+
+ <modules>
+ <module>shardingsphere-agent-tracer-sample</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-agent-core</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Entrypoint>${entrypoint.class}</Entrypoint>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-shade-plugin</artifactId>
+ <configuration>
+ <outputFile>${tracing.target.directory}/${project.build.finalName}</outputFile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/shardingsphere-agent/pom.xml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/pom.xml
similarity index 75%
copy from shardingsphere-agent/pom.xml
copy to shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/pom.xml
index 02c989c..efcc8b0 100644
--- a/shardingsphere-agent/pom.xml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/pom.xml
@@ -20,19 +20,18 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere</artifactId>
+ <artifactId>shardingsphere-agent-plugin-tracers</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-agent</artifactId>
- <packaging>pom</packaging>
- <name>${project.artifactId}</name>
- <modules>
- <module>shardingsphere-agent-bootstrap</module>
- <module>shardingsphere-agent-core</module>
- <module>shardingsphere-agent-plugins</module>
- <module>shardingsphere-agent-distribution</module>
- </modules>
+ <packaging>jar</packaging>
+ <artifactId>shardingsphere-agent-tracer-sample</artifactId>
+
+ <properties>
+ <entrypoint.class>org.apache.shardingsphere.agent.plugin.trace.SamplePluginDefine</entrypoint.class>
+ </properties>
+
</project>
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleAdvice.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleAdvice.java
new file mode 100644
index 0000000..9e24dbc
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleAdvice.java
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ *
+ */
+
+package org.apache.shardingsphere.agent.plugin.trace;
+
+import org.apache.shardingsphere.agent.core.plugin.advice.MethodAroundAdvice;
+import org.apache.shardingsphere.agent.core.plugin.advice.MethodInvocationResult;
+import org.apache.shardingsphere.agent.core.plugin.advice.TargetObject;
+
+import java.lang.reflect.Method;
+
+/**
+ * Advice sample.
+ */
+public class SampleAdvice implements MethodAroundAdvice {
+
+ @Override
+ public void beforeMethod(final TargetObject target, final Method method, final Object[] args, final MethodInvocationResult result) {
+
+ }
+
+ @Override
+ public void afterMethod(final TargetObject target, final Method method, final Object[] args, final MethodInvocationResult result) {
+
+ }
+
+ @Override
+ public void onThrowing(final TargetObject target, final Method method, final Object[] args, final Throwable throwable) {
+
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefine.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefine.java
new file mode 100644
index 0000000..05fe07d
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefine.java
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ *
+ */
+
+package org.apache.shardingsphere.agent.plugin.trace;
+
+import net.bytebuddy.matcher.ElementMatchers;
+import org.apache.shardingsphere.agent.core.plugin.PluginDefine;
+
+/**
+ * Sample.
+ */
+public class SamplePluginDefine extends PluginDefine {
+
+ @Override
+ protected void define() {
+ intercept("org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask")
+ .aroundInstanceMethod(ElementMatchers.named("run"))
+ .implement("org.apache.shardingsphere.agent.plugin.trace.SampleAdvice")
+ .build();
+
+ registerService(SampleTracer.class);
+ }
+
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleTracer.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleTracer.java
new file mode 100644
index 0000000..ceae189
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SampleTracer.java
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ *
+ */
+
+package org.apache.shardingsphere.agent.plugin.trace;
+
+import org.apache.shardingsphere.agent.core.plugin.Service;
+
+/**
+ * Tracer Sample.
+ */
+public class SampleTracer implements Service {
+
+ @Override
+ public void setup() {
+
+ }
+
+ @Override
+ public void start() {
+
+ }
+
+ @Override
+ public void cleanup() {
+
+ }
+}