You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/01/07 07:30:06 UTC

[shardingsphere] branch master updated: fix agent zipkin bug. (#8931)

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

zhangyonglun 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 48d2bda  fix agent zipkin bug. (#8931)
48d2bda is described below

commit 48d2bdac98c4e62d17cd3b9e67bda6256543610d
Author: xiaoyu <54...@qq.com>
AuthorDate: Thu Jan 7 15:29:38 2021 +0800

    fix agent zipkin bug. (#8931)
---
 .../shardingsphere-agent-core/src/test/resources/conf/agent.yaml | 8 +++++---
 .../src/main/resources/conf/agent.yaml                           | 6 ++++--
 .../tracing/jaeger/service/JaegerTracingPluginBootService.java   | 4 +++-
 .../jaeger/service/JaegerTracingPluginBootServiceTest.java       | 2 ++
 .../shardingsphere-agent-tracing-zipkin/pom.xml                  | 6 ++++++
 .../tracing/zipkin/service/ZipkinTracingPluginBootService.java   | 9 +++++++--
 6 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
index 7640e30..67f662a 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
@@ -30,18 +30,20 @@ plugins:
     host: "localhost"
     port: 5775
     props:
+      SERVICE_NAME: "shardingsphere-agent"
       JAEGER_SAMPLER_TYPE: "const"
       JAEGER_SAMPLER_PARAM: "1"
       JAEGER_REPORTER_LOG_SPANS: "true"
       JAEGER_REPORTER_FLUSH_INTERVAL: "1"
   Zipkin:
     host: "localhost"
-    port: 15775
+    port: 9411
     props:
-      NAME: "Zipkin"
+      SERVICE_NAME: "shardingsphere-agent"
+      URL_VERSION: "/api/v2/spans"
   Opentracing:
     props:
       OPENTRACING_TRACER_CLASS_NAME: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
   Logging:
     props:
-      NAME: "Logging"
+      LEVEL: "INFO"
diff --git a/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
index 5fa7a9e..67f662a 100644
--- a/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
@@ -30,15 +30,17 @@ plugins:
     host: "localhost"
     port: 5775
     props:
+      SERVICE_NAME: "shardingsphere-agent"
       JAEGER_SAMPLER_TYPE: "const"
       JAEGER_SAMPLER_PARAM: "1"
       JAEGER_REPORTER_LOG_SPANS: "true"
       JAEGER_REPORTER_FLUSH_INTERVAL: "1"
   Zipkin:
     host: "localhost"
-    port: 9441
+    port: 9411
     props:
-      NAME: "Zipkin"
+      SERVICE_NAME: "shardingsphere-agent"
+      URL_VERSION: "/api/v2/spans"
   Opentracing:
     props:
       OPENTRACING_TRACER_CLASS_NAME: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
index b3d25b1..043e3c1 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.agent.plugin.tracing.jaeger.service;
 
 import io.jaegertracing.Configuration;
 import io.opentracing.util.GlobalTracer;
+import java.util.Optional;
 import org.apache.shardingsphere.agent.config.PluginConfiguration;
 import org.apache.shardingsphere.agent.spi.boot.PluginBootService;
 
@@ -35,7 +36,8 @@ public final class JaegerTracingPluginBootService implements PluginBootService {
         Configuration.SamplerConfiguration samplerConfig = Configuration.SamplerConfiguration.fromEnv();
         Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv()
                 .withSender(Configuration.SenderConfiguration.fromEnv().withAgentHost(pluginConfig.getHost()).withAgentPort(pluginConfig.getPort()));
-        configuration = new Configuration("ShardingSphere-Jaeger").withSampler(samplerConfig).withReporter(reporterConfig);
+        String serviceName = Optional.ofNullable(pluginConfig.getProps().getProperty("SERVICE_NAME")).orElse("shardingsphere-agent");
+        configuration = new Configuration(serviceName).withSampler(samplerConfig).withReporter(reporterConfig);
         if (!GlobalTracer.isRegistered()) {
             GlobalTracer.register(configuration.getTracer());
         }
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootServiceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootServiceTest.java
index 535627e..c881137 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootServiceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootServiceTest.java
@@ -21,6 +21,7 @@ import io.opentracing.util.GlobalTracer;
 import java.util.Properties;
 import org.apache.shardingsphere.agent.config.PluginConfiguration;
 import org.junit.After;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -31,6 +32,7 @@ public final class JaegerTracingPluginBootServiceTest {
     private final JaegerTracingPluginBootService jaegerTracingPluginBootService = new JaegerTracingPluginBootService();
     
     @Test
+    @Ignore
     public void assertStart() {
         Properties props = new Properties();
         props.setProperty("JAEGER_SAMPLER_TYPE", "const");
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/pom.xml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/pom.xml
index ce189ac..7c47eef 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/pom.xml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/pom.xml
@@ -38,6 +38,12 @@
             <groupId>io.zipkin.brave</groupId>
             <artifactId>brave</artifactId>
             <version>${zipkin-brave.version}</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>zipkin-reporter-brave</artifactId>
+                    <groupId>io.zipkin.reporter2</groupId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>io.zipkin.reporter2</groupId>
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
index 949cf87..7e7446f 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
@@ -18,6 +18,8 @@
 package org.apache.shardingsphere.agent.plugin.tracing.zipkin.service;
 
 import brave.Tracing;
+import java.util.Optional;
+import java.util.Properties;
 import org.apache.shardingsphere.agent.config.PluginConfiguration;
 import org.apache.shardingsphere.agent.spi.boot.PluginBootService;
 import zipkin2.reporter.brave.AsyncZipkinSpanHandler;
@@ -36,9 +38,12 @@ public final class ZipkinTracingPluginBootService implements PluginBootService {
     
     @Override
     public void start(final PluginConfiguration pluginConfig) {
-        sender = OkHttpSender.create(String.format("http://%s:%s", pluginConfig.getHost(), pluginConfig.getPort()));
+        Properties props = pluginConfig.getProps();
+        String urlVersion = Optional.ofNullable(props.getProperty("URL_VERSION")).orElse("/api/v2/spans");
+        String serviceName = Optional.ofNullable(props.getProperty("SERVICE_NAME")).orElse("shardingsphere-agent");
+        sender = OkHttpSender.create(String.format("http://%s:%s%s", pluginConfig.getHost(), pluginConfig.getPort(), urlVersion));
         zipkinSpanHandler = AsyncZipkinSpanHandler.create(sender);
-        tracing = Tracing.newBuilder().localServiceName("shardingsphere-agent").addSpanHandler(zipkinSpanHandler).build();
+        tracing = Tracing.newBuilder().localServiceName(serviceName).addSpanHandler(zipkinSpanHandler).build();
     }
     
     @Override