You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ki...@apache.org on 2020/07/03 08:23:28 UTC
[shardingsphere] branch master updated: OpenTracing spi design in
sharding-proxy (#6254)
This is an automated email from the ASF dual-hosted git repository.
kimmking 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 249c926 OpenTracing spi design in sharding-proxy (#6254)
249c926 is described below
commit 249c9267475c7b1d78654a3fadc0b3d6f3a34c58
Author: xiaoyu <54...@qq.com>
AuthorDate: Fri Jul 3 16:23:19 2020 +0800
OpenTracing spi design in sharding-proxy (#6254)
* sharding-proxy sharding-jdbc-spring-boot use common data source configuration。
* Opentracing spi design in Sharding-proxy
Co-authored-by: kimmking <ki...@163.com>
---
.../spi/opentracing/OpenTracingConfiguration.java | 26 ++++++++++++++
.../shardingsphere-opentracing/pom.xml | 6 +++-
.../shardingsphere/opentracing/ShardingTracer.java | 40 ++++++++++++++++------
...dingsphere.control.panel.spi.ControlPanelFacade | 18 ++++++++++
.../opentracing/ShardingTracerTest.java | 12 +++++++
.../org/apache/shardingsphere/proxy/Bootstrap.java | 13 +++----
6 files changed, 95 insertions(+), 20 deletions(-)
diff --git a/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/main/java/org/apache/shardingsphere/control/panel/spi/opentracing/OpenTracingConfiguration.java b/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/main/java/org/apache/shardingsphere/control/panel/spi/opentracing/OpenTracingConfiguration.java
new file mode 100644
index 0000000..0f2cf1b
--- /dev/null
+++ b/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/main/java/org/apache/shardingsphere/control/panel/spi/opentracing/OpenTracingConfiguration.java
@@ -0,0 +1,26 @@
+/*
+ * 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.control.panel.spi.opentracing;
+
+import org.apache.shardingsphere.control.panel.spi.FacadeConfiguration;
+
+/**
+ * Open tracing configuration.
+ */
+public class OpenTracingConfiguration implements FacadeConfiguration {
+}
diff --git a/shardingsphere-control-panel/shardingsphere-opentracing/pom.xml b/shardingsphere-control-panel/shardingsphere-opentracing/pom.xml
index 07ab3d0..48e81bf 100644
--- a/shardingsphere-control-panel/shardingsphere-opentracing/pom.xml
+++ b/shardingsphere-control-panel/shardingsphere-opentracing/pom.xml
@@ -32,7 +32,11 @@
<artifactId>shardingsphere-infra-executor</artifactId>
<version>${project.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-control-panel-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-util</artifactId>
diff --git a/shardingsphere-control-panel/shardingsphere-opentracing/src/main/java/org/apache/shardingsphere/opentracing/ShardingTracer.java b/shardingsphere-control-panel/shardingsphere-opentracing/src/main/java/org/apache/shardingsphere/opentracing/ShardingTracer.java
index 586fac1..3812e37 100644
--- a/shardingsphere-control-panel/shardingsphere-opentracing/src/main/java/org/apache/shardingsphere/opentracing/ShardingTracer.java
+++ b/shardingsphere-control-panel/shardingsphere-opentracing/src/main/java/org/apache/shardingsphere/opentracing/ShardingTracer.java
@@ -20,29 +20,27 @@ package org.apache.shardingsphere.opentracing;
import com.google.common.base.Preconditions;
import io.opentracing.Tracer;
import io.opentracing.util.GlobalTracer;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.control.panel.spi.ControlPanelFacade;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import org.apache.shardingsphere.control.panel.spi.opentracing.OpenTracingConfiguration;
/**
* Sharding tracer object container.
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShardingTracer {
+public final class ShardingTracer implements ControlPanelFacade<OpenTracingConfiguration> {
private static final String OPENTRACING_TRACER_CLASS_NAME = "org.apache.shardingsphere.opentracing.tracer.class";
+ @Override
+ public void init(final OpenTracingConfiguration configuration) {
+ doInit();
+ }
+
/**
* Initialize sharding tracer.
*/
public static void init() {
- String tracerClassName = System.getProperty(OPENTRACING_TRACER_CLASS_NAME);
- Preconditions.checkNotNull(tracerClassName, "Can not find opentracing tracer implementation class via system property `%s`", OPENTRACING_TRACER_CLASS_NAME);
- try {
- init((Tracer) Class.forName(tracerClassName).newInstance());
- } catch (final ReflectiveOperationException ex) {
- throw new ShardingSphereException("Initialize opentracing tracer class failure.", ex);
- }
+ doInit();
}
/**
@@ -64,4 +62,24 @@ public final class ShardingTracer {
public static Tracer get() {
return GlobalTracer.get();
}
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+
+ @Override
+ public Class<OpenTracingConfiguration> getTypeClass() {
+ return OpenTracingConfiguration.class;
+ }
+
+ private static void doInit() {
+ String tracerClassName = System.getProperty(OPENTRACING_TRACER_CLASS_NAME);
+ Preconditions.checkNotNull(tracerClassName, "Can not find opentracing tracer implementation class via system property `%s`", OPENTRACING_TRACER_CLASS_NAME);
+ try {
+ init((Tracer) Class.forName(tracerClassName).newInstance());
+ } catch (final ReflectiveOperationException ex) {
+ throw new ShardingSphereException("Initialize opentracing tracer class failure.", ex);
+ }
+ }
}
diff --git a/shardingsphere-control-panel/shardingsphere-opentracing/src/main/resources/META-INF/services/org.apache.shardingsphere.control.panel.spi.ControlPanelFacade b/shardingsphere-control-panel/shardingsphere-opentracing/src/main/resources/META-INF/services/org.apache.shardingsphere.control.panel.spi.ControlPanelFacade
new file mode 100644
index 0000000..add9229
--- /dev/null
+++ b/shardingsphere-control-panel/shardingsphere-opentracing/src/main/resources/META-INF/services/org.apache.shardingsphere.control.panel.spi.ControlPanelFacade
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.opentracing.ShardingTracer
diff --git a/shardingsphere-control-panel/shardingsphere-opentracing/src/test/java/org/apache/shardingsphere/opentracing/ShardingTracerTest.java b/shardingsphere-control-panel/shardingsphere-opentracing/src/test/java/org/apache/shardingsphere/opentracing/ShardingTracerTest.java
index 5ad442f..a064998 100644
--- a/shardingsphere-control-panel/shardingsphere-opentracing/src/test/java/org/apache/shardingsphere/opentracing/ShardingTracerTest.java
+++ b/shardingsphere-control-panel/shardingsphere-opentracing/src/test/java/org/apache/shardingsphere/opentracing/ShardingTracerTest.java
@@ -20,8 +20,11 @@ package org.apache.shardingsphere.opentracing;
import io.opentracing.NoopTracerFactory;
import io.opentracing.Tracer;
import io.opentracing.util.GlobalTracer;
+import java.util.Collections;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.control.panel.spi.engine.ControlPanelFacadeEngine;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import org.apache.shardingsphere.control.panel.spi.opentracing.OpenTracingConfiguration;
import org.apache.shardingsphere.opentracing.fixture.FooTracer;
import org.junit.After;
import org.junit.Before;
@@ -66,6 +69,15 @@ public final class ShardingTracerTest {
assertThat(ShardingTracer.get(), is(ShardingTracer.get()));
}
+ @Test
+ public void assertTracerSpiLoad() {
+ OpenTracingConfiguration openTracingConfiguration = new OpenTracingConfiguration();
+ new ControlPanelFacadeEngine().init(Collections.singleton(openTracingConfiguration));
+ assertThat((GlobalTracer) ShardingTracer.get(), isA(GlobalTracer.class));
+ assertTrue(GlobalTracer.isRegistered());
+ assertThat(ShardingTracer.get(), is(ShardingTracer.get()));
+ }
+
@Test(expected = ShardingSphereException.class)
public void assertTracerClassError() {
System.setProperty("org.apache.shardingsphere.opentracing.tracer.class", "com.foo.FooTracer");
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
index 06a1b7c..5142ceb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
@@ -29,6 +29,7 @@ import org.apache.shardingsphere.cluster.configuration.yaml.YamlClusterConfigura
import org.apache.shardingsphere.cluster.facade.ClusterFacade;
import org.apache.shardingsphere.control.panel.spi.engine.ControlPanelFacadeEngine;
import org.apache.shardingsphere.control.panel.spi.FacadeConfiguration;
+import org.apache.shardingsphere.control.panel.spi.opentracing.OpenTracingConfiguration;
import org.apache.shardingsphere.infra.auth.Authentication;
import org.apache.shardingsphere.infra.auth.yaml.config.YamlAuthenticationConfiguration;
import org.apache.shardingsphere.infra.auth.yaml.swapper.AuthenticationYamlSwapper;
@@ -46,7 +47,6 @@ import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
import org.apache.shardingsphere.metrics.configuration.swapper.MetricsConfigurationYamlSwapper;
import org.apache.shardingsphere.metrics.configuration.yaml.YamlMetricsConfiguration;
-import org.apache.shardingsphere.opentracing.ShardingTracer;
import org.apache.shardingsphere.orchestration.center.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.center.yaml.swapper.OrchestrationConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.facade.ShardingOrchestrationFacade;
@@ -155,7 +155,6 @@ public final class Bootstrap {
initProxySchemaContexts(schemaDataSources, schemaRules, authentication, properties, isOrchestration);
log(authentication, properties);
initControlPanelFacade(metricsConfiguration);
- initOpenTracing();
initCluster(cluster);
}
@@ -164,6 +163,10 @@ public final class Bootstrap {
if (null != metricsConfiguration && metricsConfiguration.getEnable()) {
facadeConfigurations.add(metricsConfiguration);
}
+ if (ProxySchemaContexts.getInstance().getSchemaContexts().getProps().<Boolean>getValue(ConfigurationPropertyKey.PROXY_OPENTRACING_ENABLED)) {
+ facadeConfigurations.add(new OpenTracingConfiguration());
+ }
+ // TODO add cluster configuration
new ControlPanelFacadeEngine().init(facadeConfigurations);
}
@@ -220,12 +223,6 @@ public final class Bootstrap {
shardingOrchestrationFacade.initClusterConfiguration(Optional.ofNullable(serverConfig.getCluster()).map(new ClusterConfigurationYamlSwapper()::swapToObject).orElse(null));
}
- private static void initOpenTracing() {
- if (ProxySchemaContexts.getInstance().getSchemaContexts().getProps().<Boolean>getValue(ConfigurationPropertyKey.PROXY_OPENTRACING_ENABLED)) {
- ShardingTracer.init();
- }
- }
-
private static void initCluster(final ClusterConfiguration clusterConfiguration) {
if (null != ClusterFacade.getInstance()
&& ProxySchemaContexts.getInstance().getSchemaContexts().getProps().<Boolean>getValue(ConfigurationPropertyKey.PROXY_CLUSTER_ENABLED)) {