You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/01/12 06:26:35 UTC
[shardingsphere] branch master updated: agent code review (#8991)
This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 989579d agent code review (#8991)
989579d is described below
commit 989579dc7aad74ae98951ef4cd2057a6e07e2bd2
Author: xiaoyu <54...@qq.com>
AuthorDate: Tue Jan 12 14:25:05 2021 +0800
agent code review (#8991)
---
.../agent/config/AgentConfiguration.java | 12 +++---
.../agent/config/PluginConfiguration.java | 14 ++++---
.../agent/config/RemotePluginConfiguration.java | 33 ----------------
.../exception/PluginConfigurationException.java} | 9 ++---
.../agent/bootstrap/ShardingSphereAgent.java | 4 +-
.../ShardingSphereTransformationPoint.java | 4 +-
.../transformer/ShardingSphereTransformer.java | 42 +++++++++-----------
.../ComposeClassStaticMethodAroundAdvice.java | 4 +-
.../advice/ComposeConstructorAdvice.java | 3 ++
.../advice/ComposeInstanceMethodAroundAdvice.java | 7 +++-
.../AgentConfigurationRegistry.java} | 6 +--
.../core/config/yaml/YamlPluginConfiguration.java | 6 ++-
.../config/yaml/YamlRemotePluginConfiguration.java | 33 ----------------
.../swapper/YamlAgentConfigurationSwapper.java | 13 +------
.../AgentServiceProviderNotFoundException.java | 4 --
.../core/plugin/PluginBootServiceManager.java | 4 +-
.../agent/core/plugin/PluginLoader.java | 26 ++++++-------
...ore.yaml.swapper.YamlPluginConfigurationSwapper | 20 ----------
.../MockInstanceMethodAroundRepeatedAdvice.java | 3 +-
.../core/mock/material/RepeatedAdviceMaterial.java | 1 -
.../shardingsphere/agent/metrics/api/BaseTest.java | 4 +-
.../service/PrometheusPluginBootService.java | 45 +++++++++++++---------
.../service/PrometheusPluginBootServiceTest.java | 4 +-
.../service/JaegerTracingPluginBootService.java | 10 +++++
.../JaegerTracingPluginBootServiceTest.java | 3 +-
.../service/OpenTracingPluginBootServiceTest.java | 3 +-
.../service/ZipkinTracingPluginBootService.java | 10 +++++
.../ZipkinTracingPluginBootServiceTest.java | 4 +-
28 files changed, 132 insertions(+), 199 deletions(-)
diff --git a/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/AgentConfiguration.java b/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/AgentConfiguration.java
index 498efc3..e90a568 100644
--- a/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/AgentConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/AgentConfiguration.java
@@ -17,23 +17,21 @@
package org.apache.shardingsphere.agent.config;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import lombok.Getter;
-import lombok.Setter;
+import lombok.RequiredArgsConstructor;
/**
* Agent configuration.
*/
@Getter
-@Setter
+@RequiredArgsConstructor
public final class AgentConfiguration {
- private String applicationName;
+ private final String applicationName;
- private Set<String> ignoredPluginNames = new HashSet<>();
+ private final Set<String> ignoredPluginNames;
- private Map<String, PluginConfiguration> plugins = new HashMap<>();
+ private final Map<String, PluginConfiguration> plugins;
}
diff --git a/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/PluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/PluginConfiguration.java
index af61b31..c3c9257 100644
--- a/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/PluginConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/PluginConfiguration.java
@@ -19,16 +19,20 @@ package org.apache.shardingsphere.agent.config;
import java.util.Properties;
import lombok.Getter;
-import lombok.Setter;
+import lombok.RequiredArgsConstructor;
/**
* Plugin configuration.
*/
@Getter
-@Setter
-public final class PluginConfiguration extends RemotePluginConfiguration {
+@RequiredArgsConstructor
+public final class PluginConfiguration {
- private String password;
+ private final String host;
- private Properties props = new Properties();
+ private final int port;
+
+ private final String password;
+
+ private final Properties props;
}
diff --git a/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/RemotePluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/RemotePluginConfiguration.java
deleted file mode 100644
index 426e2b5..0000000
--- a/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/config/RemotePluginConfiguration.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.config;
-
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * Remote plugin configuration.
- */
-@Getter
-@Setter
-public class RemotePluginConfiguration {
-
- private String host = "localhost";
-
- private int port = 5775;
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/PluginDefinitionNotFoundException.java b/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/exception/PluginConfigurationException.java
similarity index 79%
rename from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/PluginDefinitionNotFoundException.java
rename to shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/exception/PluginConfigurationException.java
index 3c0f977..5abf8d1 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/PluginDefinitionNotFoundException.java
+++ b/shardingsphere-agent/shardingsphere-agent-api/src/main/java/org/apache/shardingsphere/agent/exception/PluginConfigurationException.java
@@ -13,15 +13,14 @@
* 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.core.exception;
+package org.apache.shardingsphere.agent.exception;
/**
- * Plugin definition not found exception.
+ * Plugin configuration exception.
*/
-public final class PluginDefinitionNotFoundException extends RuntimeException {
+public final class PluginConfigurationException extends RuntimeException {
/**
* Constructs an exception with formatted error message and arguments.
@@ -29,7 +28,7 @@ public final class PluginDefinitionNotFoundException extends RuntimeException {
* @param errorMessage formatted error message
* @param args arguments of error message
*/
- public PluginDefinitionNotFoundException(final String errorMessage, final Object... args) {
+ public PluginConfigurationException(final String errorMessage, final Object... args) {
super(String.format(errorMessage, args));
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java b/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
index 34ed77e..8e8671c 100644
--- a/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
+++ b/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.agent.config.AgentConfiguration;
import org.apache.shardingsphere.agent.config.PluginConfiguration;
import org.apache.shardingsphere.agent.core.bytebuddy.listener.LoggingListener;
import org.apache.shardingsphere.agent.core.bytebuddy.transformer.ShardingSphereTransformer;
-import org.apache.shardingsphere.agent.core.config.cache.AgentObjectPool;
+import org.apache.shardingsphere.agent.core.config.registry.AgentConfigurationRegistry;
import org.apache.shardingsphere.agent.core.config.loader.AgentConfigurationLoader;
import org.apache.shardingsphere.agent.core.plugin.PluginBootServiceManager;
import org.apache.shardingsphere.agent.core.plugin.PluginLoader;
@@ -51,7 +51,7 @@ public final class ShardingSphereAgent {
*/
public static void premain(final String arguments, final Instrumentation instrumentation) throws IOException {
AgentConfiguration agentConfiguration = AgentConfigurationLoader.load();
- AgentObjectPool.INSTANCE.put(agentConfiguration);
+ AgentConfigurationRegistry.INSTANCE.put(agentConfiguration);
PluginLoader pluginLoader = createPluginLoader();
setUpAgentBuilder(instrumentation, pluginLoader);
setupPluginBootService(agentConfiguration.getPlugins());
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformationPoint.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformationPoint.java
index f198a3b..bd46156 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformationPoint.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformationPoint.java
@@ -21,6 +21,9 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.bytebuddy.description.method.MethodDescription;
+/**
+ * ShardingSphere transformer point.
+ */
@Getter
@RequiredArgsConstructor
public class ShardingSphereTransformationPoint<T> {
@@ -28,5 +31,4 @@ public class ShardingSphereTransformationPoint<T> {
private final MethodDescription description;
private final T interceptor;
-
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformer.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformer.java
index 1dfc39d..f1c0cb0 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformer.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformer.java
@@ -80,20 +80,18 @@ public final class ShardingSphereTransformer implements Transformer {
List<ShardingSphereTransformationPoint<? extends ConstructorInterceptor>> constructorAdviceComposePoints = description.getDeclaredMethods().stream()
.filter(MethodDescription::isConstructor)
.map(md -> {
- List<ConstructorPoint> advices = constructorPoints.stream()
- .filter(point -> point.getMatcher().matches(md))
- .collect(Collectors.toList());
- if (advices.isEmpty()) {
+ List<ConstructorPoint> constructorPointList = constructorPoints.stream().filter(point -> point.getMatcher().matches(md)).collect(Collectors.toList());
+ if (constructorPointList.isEmpty()) {
return null;
}
- if (advices.size() == 1) {
- return new ShardingSphereTransformationPoint<>(md, new ConstructorInterceptor(pluginLoader.getOrCreateInstance(advices.get(0).getAdvice())));
+ if (constructorPointList.size() == 1) {
+ return new ShardingSphereTransformationPoint<>(md, new ConstructorInterceptor(pluginLoader.getOrCreateInstance(constructorPointList.get(0).getAdvice())));
} else {
- List<ConstructorAdvice> collect = advices.stream()
+ List<ConstructorAdvice> constructorAdvices = constructorPointList.stream()
.map(ConstructorPoint::getAdvice)
.map(advice -> (ConstructorAdvice) pluginLoader.getOrCreateInstance(advice))
.collect(Collectors.toList());
- return new ShardingSphereTransformationPoint<>(md, new ComposeConstructorInterceptor(collect));
+ return new ShardingSphereTransformationPoint<>(md, new ComposeConstructorInterceptor(constructorAdvices));
}
})
.filter(Objects::nonNull)
@@ -116,20 +114,18 @@ public final class ShardingSphereTransformer implements Transformer {
List<ShardingSphereTransformationPoint<? extends ClassStaticMethodAroundInterceptor>> classStaticMethodAdvicePoints = description.getDeclaredMethods().stream()
.filter(md -> md.isStatic() && !(md.isAbstract() || md.isSynthetic()))
.map(md -> {
- List<ClassStaticMethodPoint> advices = classStaticMethodAroundPoints.stream()
- .filter(point -> point.getMatcher().matches(md))
- .collect(Collectors.toList());
- if (advices.isEmpty()) {
+ List<ClassStaticMethodPoint> classStaticMethodPoints = classStaticMethodAroundPoints.stream().filter(point -> point.getMatcher().matches(md)).collect(Collectors.toList());
+ if (classStaticMethodPoints.isEmpty()) {
return null;
}
- if (advices.size() == 1) {
- return new ShardingSphereTransformationPoint<>(md, new ClassStaticMethodAroundInterceptor(pluginLoader.getOrCreateInstance(advices.get(0).getAdvice())));
+ if (classStaticMethodPoints.size() == 1) {
+ return new ShardingSphereTransformationPoint<>(md, new ClassStaticMethodAroundInterceptor(pluginLoader.getOrCreateInstance(classStaticMethodPoints.get(0).getAdvice())));
} else {
- List<ClassStaticMethodAroundAdvice> collect = advices.stream()
+ List<ClassStaticMethodAroundAdvice> classStaticMethodAroundAdvices = classStaticMethodPoints.stream()
.map(ClassStaticMethodPoint::getAdvice)
.map(advice -> (ClassStaticMethodAroundAdvice) pluginLoader.getOrCreateInstance(advice))
.collect(Collectors.toList());
- return new ShardingSphereTransformationPoint<>(md, new ComposeClassStaticMethodAroundInterceptor(collect));
+ return new ShardingSphereTransformationPoint<>(md, new ComposeClassStaticMethodAroundInterceptor(classStaticMethodAroundAdvices));
}
})
.filter(Objects::nonNull)
@@ -152,20 +148,18 @@ public final class ShardingSphereTransformer implements Transformer {
List<ShardingSphereTransformationPoint<? extends InstanceMethodAroundInterceptor>> instanceMethodAdviceComposePoints = description.getDeclaredMethods().stream()
.filter(md -> !(md.isAbstract() || md.isSynthetic()))
.map(md -> {
- List<InstanceMethodPoint> advices = instanceMethodAroundPoints.stream()
- .filter(point -> point.getMatcher().matches(md))
- .collect(Collectors.toList());
- if (advices.isEmpty()) {
+ List<InstanceMethodPoint> instanceMethodPoints = instanceMethodAroundPoints.stream().filter(point -> point.getMatcher().matches(md)).collect(Collectors.toList());
+ if (instanceMethodPoints.isEmpty()) {
return null;
}
- if (advices.size() == 1) {
- return new ShardingSphereTransformationPoint<>(md, new InstanceMethodAroundInterceptor(pluginLoader.getOrCreateInstance(advices.get(0).getAdvice())));
+ if (instanceMethodPoints.size() == 1) {
+ return new ShardingSphereTransformationPoint<>(md, new InstanceMethodAroundInterceptor(pluginLoader.getOrCreateInstance(instanceMethodPoints.get(0).getAdvice())));
} else {
- List<InstanceMethodAroundAdvice> collect = advices.stream()
+ List<InstanceMethodAroundAdvice> instanceMethodAroundAdvices = instanceMethodPoints.stream()
.map(InstanceMethodPoint::getAdvice)
.map(advice -> (InstanceMethodAroundAdvice) pluginLoader.getOrCreateInstance(advice))
.collect(Collectors.toList());
- return new ShardingSphereTransformationPoint<>(md, new ComposeInstanceMethodAroundInterceptor(collect));
+ return new ShardingSphereTransformationPoint<>(md, new ComposeInstanceMethodAroundInterceptor(instanceMethodAroundAdvices));
}
})
.filter(Objects::nonNull)
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeClassStaticMethodAroundAdvice.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeClassStaticMethodAroundAdvice.java
index 0ad6cd1..3bc3228 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeClassStaticMethodAroundAdvice.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeClassStaticMethodAroundAdvice.java
@@ -29,9 +29,9 @@ import java.util.List;
* Compose class static method around advice.
*/
@RequiredArgsConstructor
-public class ComposeClassStaticMethodAroundAdvice implements ClassStaticMethodAroundAdvice {
+public final class ComposeClassStaticMethodAroundAdvice implements ClassStaticMethodAroundAdvice {
- private @NonNull List<ClassStaticMethodAroundAdvice> adviceList;
+ private final @NonNull List<ClassStaticMethodAroundAdvice> adviceList;
@Override
public void beforeMethod(final Class<?> clazz, final Method method, final Object[] args, final MethodInvocationResult result) {
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdvice.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdvice.java
index 23d4b3b..9869cb3 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdvice.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdvice.java
@@ -24,6 +24,9 @@ import org.apache.shardingsphere.agent.api.advice.ConstructorAdvice;
import java.util.List;
+/**
+ * Compose Constructor advice.
+ */
@RequiredArgsConstructor
public final class ComposeConstructorAdvice implements ConstructorAdvice {
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeInstanceMethodAroundAdvice.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeInstanceMethodAroundAdvice.java
index 5c4b849..42fdb04 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeInstanceMethodAroundAdvice.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeInstanceMethodAroundAdvice.java
@@ -26,10 +26,13 @@ import org.apache.shardingsphere.agent.api.result.MethodInvocationResult;
import java.lang.reflect.Method;
import java.util.List;
+/**
+ * Compose instance method around advice.
+ */
@RequiredArgsConstructor
-public class ComposeInstanceMethodAroundAdvice implements InstanceMethodAroundAdvice {
+public final class ComposeInstanceMethodAroundAdvice implements InstanceMethodAroundAdvice {
- private @NonNull List<InstanceMethodAroundAdvice> adviceList;
+ private final @NonNull List<InstanceMethodAroundAdvice> adviceList;
@Override
public void beforeMethod(final AdviceTargetObject target, final Method method, final Object[] args, final MethodInvocationResult result) {
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/cache/AgentObjectPool.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/registry/AgentConfigurationRegistry.java
similarity index 91%
rename from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/cache/AgentObjectPool.java
rename to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/registry/AgentConfigurationRegistry.java
index bbf7689..04437ae 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/cache/AgentObjectPool.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/registry/AgentConfigurationRegistry.java
@@ -15,15 +15,15 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.config.cache;
+package org.apache.shardingsphere.agent.core.config.registry;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
- * Agent object pool.
+ * Agent configuration registry.
*/
-public enum AgentObjectPool {
+public enum AgentConfigurationRegistry {
/**
* Instance singleton.
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginConfiguration.java
index 73ad460..c802cab 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginConfiguration.java
@@ -26,7 +26,11 @@ import lombok.Setter;
*/
@Getter
@Setter
-public final class YamlPluginConfiguration extends YamlRemotePluginConfiguration {
+public final class YamlPluginConfiguration {
+
+ private String host = "localhost";
+
+ private int port = 5775;
private String password;
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlRemotePluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlRemotePluginConfiguration.java
deleted file mode 100644
index 96a237b..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlRemotePluginConfiguration.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.core.config.yaml;
-
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * YAML Remote plugin configuration.
- */
-@Getter
-@Setter
-public class YamlRemotePluginConfiguration {
-
- private String host = "localhost";
-
- private int port = 5775;
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
index 0d897c9..ea7c1dc 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
@@ -36,20 +36,11 @@ public final class YamlAgentConfigurationSwapper {
* @return agent configuration
*/
public static AgentConfiguration swap(final YamlAgentConfiguration yamlConfig) {
- AgentConfiguration result = new AgentConfiguration();
- result.setApplicationName(yamlConfig.getApplicationName());
- result.setIgnoredPluginNames(yamlConfig.getIgnoredPluginNames());
Map<String, PluginConfiguration> configurationMap = yamlConfig.getPlugins().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> transform(entry.getValue())));
- result.setPlugins(configurationMap);
- return result;
+ return new AgentConfiguration(yamlConfig.getApplicationName(), yamlConfig.getIgnoredPluginNames(), configurationMap);
}
private static PluginConfiguration transform(final YamlPluginConfiguration yamlConfig) {
- PluginConfiguration result = new PluginConfiguration();
- result.setHost(yamlConfig.getHost());
- result.setPort(yamlConfig.getPort());
- result.setProps(yamlConfig.getProps());
- result.setPassword(yamlConfig.getPassword());
- return result;
+ return new PluginConfiguration(yamlConfig.getHost(), yamlConfig.getPort(), yamlConfig.getPassword(), yamlConfig.getProps());
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/AgentServiceProviderNotFoundException.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/AgentServiceProviderNotFoundException.java
index 08dd483..5e2c93d 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/AgentServiceProviderNotFoundException.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/AgentServiceProviderNotFoundException.java
@@ -24,10 +24,6 @@ public final class AgentServiceProviderNotFoundException extends RuntimeExceptio
private static final long serialVersionUID = -3730257541332863235L;
- public AgentServiceProviderNotFoundException(final Class<?> clazz) {
- super(String.format("No implementation class load from SPI `%s`.", clazz.getName()));
- }
-
public AgentServiceProviderNotFoundException(final Class<?> clazz, final String type) {
super(String.format("No implementation class load from SPI `%s` with type `%s`.", clazz.getName(), type));
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
index 34fa40c..024040c 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.agent.core.plugin;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.agent.config.AgentConfiguration;
import org.apache.shardingsphere.agent.config.PluginConfiguration;
-import org.apache.shardingsphere.agent.core.config.cache.AgentObjectPool;
+import org.apache.shardingsphere.agent.core.config.registry.AgentConfigurationRegistry;
import org.apache.shardingsphere.agent.core.spi.AgentTypedSPIRegistry;
import org.apache.shardingsphere.agent.spi.boot.PluginBootService;
@@ -39,7 +39,7 @@ public final class PluginBootServiceManager {
* @param pluginConfigurationMap plugin configuration map
*/
public static void startAllServices(final Map<String, PluginConfiguration> pluginConfigurationMap) {
- Set<String> ignoredPluginNames = AgentObjectPool.INSTANCE.get(AgentConfiguration.class).getIgnoredPluginNames();
+ Set<String> ignoredPluginNames = AgentConfigurationRegistry.INSTANCE.get(AgentConfiguration.class).getIgnoredPluginNames();
for (Map.Entry<String, PluginConfiguration> entry: pluginConfigurationMap.entrySet()) {
AgentTypedSPIRegistry.getRegisteredServiceOptional(PluginBootService.class, entry.getKey()).ifPresent(pluginBootService -> {
try {
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java
index dc12e4e..80cd766 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java
@@ -29,7 +29,7 @@ import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatcher.Junction;
import org.apache.shardingsphere.agent.api.point.PluginInterceptorPoint;
import org.apache.shardingsphere.agent.config.AgentConfiguration;
-import org.apache.shardingsphere.agent.core.config.cache.AgentObjectPool;
+import org.apache.shardingsphere.agent.core.config.registry.AgentConfigurationRegistry;
import org.apache.shardingsphere.agent.core.config.path.AgentPathBuilder;
import org.apache.shardingsphere.agent.core.spi.PluginServiceLoader;
import org.apache.shardingsphere.agent.spi.definition.PluginDefinitionService;
@@ -106,7 +106,7 @@ public final class PluginLoader extends ClassLoader implements Closeable {
return;
}
Map<String, PluginInterceptorPoint> pointMap = Maps.newHashMap();
- Set<String> ignoredPluginNames = AgentObjectPool.INSTANCE.get(AgentConfiguration.class).getIgnoredPluginNames();
+ Set<String> ignoredPluginNames = AgentConfigurationRegistry.INSTANCE.get(AgentConfiguration.class).getIgnoredPluginNames();
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
for (File each : jarFiles) {
outputStream.reset();
@@ -270,13 +270,13 @@ public final class PluginLoader extends ClassLoader implements Closeable {
if (null != getPackage(packageName)) {
return;
}
- Attributes attr = manifest.getMainAttributes();
- String specTitle = attr.getValue(Attributes.Name.SPECIFICATION_TITLE);
- String specVersion = attr.getValue(Attributes.Name.SPECIFICATION_VERSION);
- String specVendor = attr.getValue(Attributes.Name.SPECIFICATION_VENDOR);
- String implTitle = attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
- String implVersion = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
- String implVendor = attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
+ Attributes attributes = manifest.getMainAttributes();
+ String specTitle = attributes.getValue(Attributes.Name.SPECIFICATION_TITLE);
+ String specVersion = attributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
+ String specVendor = attributes.getValue(Attributes.Name.SPECIFICATION_VENDOR);
+ String implTitle = attributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
+ String implVersion = attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
+ String implVendor = attributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
definePackage(packageName, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, null);
}
@@ -284,10 +284,10 @@ public final class PluginLoader extends ClassLoader implements Closeable {
pluginDefinitionService.build().forEach(each -> {
String target = each.getClassNameOfTarget();
if (pointMap.containsKey(target)) {
- PluginInterceptorPoint definition = pointMap.get(target);
- definition.getConstructorPoints().addAll(each.getConstructorPoints());
- definition.getInstanceMethodPoints().addAll(each.getInstanceMethodPoints());
- definition.getClassStaticMethodPoints().addAll(each.getClassStaticMethodPoints());
+ PluginInterceptorPoint pluginInterceptorPoint = pointMap.get(target);
+ pluginInterceptorPoint.getConstructorPoints().addAll(each.getConstructorPoints());
+ pluginInterceptorPoint.getInstanceMethodPoints().addAll(each.getInstanceMethodPoints());
+ pluginInterceptorPoint.getClassStaticMethodPoints().addAll(each.getClassStaticMethodPoints());
} else {
pointMap.put(target, each);
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper b/shardingsphere-agent/shardingsphere-agent-core/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper
deleted file mode 100644
index 85fd8a7..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# 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.agent.core.config.yaml.swapper.JaegerPluginConfigurationYamlSwapper
-org.apache.shardingsphere.agent.core.config.yaml.swapper.ZipkinPluginConfigurationYamlSwapper
-org.apache.shardingsphere.agent.core.config.yaml.swapper.PrometheusPluginConfigurationYamlSwapper
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/mock/advice/MockInstanceMethodAroundRepeatedAdvice.java b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/mock/advice/MockInstanceMethodAroundRepeatedAdvice.java
index c002e7c..24b9d51 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/mock/advice/MockInstanceMethodAroundRepeatedAdvice.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/mock/advice/MockInstanceMethodAroundRepeatedAdvice.java
@@ -24,7 +24,8 @@ import org.apache.shardingsphere.agent.api.result.MethodInvocationResult;
import java.lang.reflect.Method;
import java.util.List;
-public class MockInstanceMethodAroundRepeatedAdvice implements InstanceMethodAroundAdvice {
+@SuppressWarnings("unchecked")
+public final class MockInstanceMethodAroundRepeatedAdvice implements InstanceMethodAroundAdvice {
@Override
public void beforeMethod(final AdviceTargetObject target, final Method method, final Object[] args, final MethodInvocationResult result) {
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/mock/material/RepeatedAdviceMaterial.java b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/mock/material/RepeatedAdviceMaterial.java
index 01a3276..eefdc94 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/mock/material/RepeatedAdviceMaterial.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/mock/material/RepeatedAdviceMaterial.java
@@ -37,5 +37,4 @@ public class RepeatedAdviceMaterial {
queues.add("on");
return "invocation";
}
-
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/BaseTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/BaseTest.java
index de0ef7b..aee55f5 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/BaseTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/BaseTest.java
@@ -22,7 +22,7 @@ import java.io.IOException;
import java.net.URL;
import org.apache.shardingsphere.agent.config.AgentConfiguration;
import org.apache.shardingsphere.agent.core.config.loader.AgentConfigurationLoader;
-import org.apache.shardingsphere.agent.core.config.cache.AgentObjectPool;
+import org.apache.shardingsphere.agent.core.config.registry.AgentConfigurationRegistry;
import org.apache.shardingsphere.agent.core.config.path.AgentPathBuilder;
import org.apache.shardingsphere.agent.metrics.api.util.ReflectiveUtil;
import org.junit.Before;
@@ -35,7 +35,7 @@ public class BaseTest {
public void assertLoad() throws IOException {
ReflectiveUtil.setStaticField(AgentPathBuilder.class, "agentPath", new File(getResourceUrl()));
AgentConfiguration configuration = AgentConfigurationLoader.load();
- AgentObjectPool.INSTANCE.put(configuration);
+ AgentConfigurationRegistry.INSTANCE.put(configuration);
}
private static String getResourceUrl() {
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java
index de8b089..aa9c5fb 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java
@@ -20,15 +20,15 @@ package org.apache.shardingsphere.agent.metrics.prometheus.service;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.exporter.HTTPServer;
import io.prometheus.client.hotspot.DefaultExports;
+import java.io.IOException;
+import java.net.InetSocketAddress;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.agent.config.PluginConfiguration;
+import org.apache.shardingsphere.agent.exception.PluginConfigurationException;
import org.apache.shardingsphere.agent.metrics.api.reporter.MetricsReporter;
+import org.apache.shardingsphere.agent.metrics.prometheus.collector.BuildInfoCollector;
import org.apache.shardingsphere.agent.metrics.prometheus.register.PrometheusMetricsRegister;
import org.apache.shardingsphere.agent.spi.boot.PluginBootService;
-import org.apache.shardingsphere.agent.metrics.prometheus.collector.BuildInfoCollector;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
/**
* Prometheus plugin boot service.
@@ -39,11 +39,32 @@ public final class PrometheusPluginBootService implements PluginBootService {
private HTTPServer httpServer;
@Override
- public void start(final PluginConfiguration pluginConfig) {
- startServer(pluginConfig);
+ public void start(final PluginConfiguration pluginConfiguration) {
+ if (!checkConfig(pluginConfiguration)) {
+ throw new PluginConfigurationException("prometheus config error, host is null or port is %s", pluginConfiguration.getPort());
+ }
+ startServer(pluginConfiguration);
MetricsReporter.register(PrometheusMetricsRegister.getInstance());
}
+ @Override
+ public void close() {
+ if (null != httpServer) {
+ httpServer.stop();
+ }
+ }
+
+ @Override
+ public String getType() {
+ return "Prometheus";
+ }
+
+ private boolean checkConfig(final PluginConfiguration pluginConfiguration) {
+ String host = pluginConfiguration.getHost();
+ int port = pluginConfiguration.getPort();
+ return null != host && !"".equalsIgnoreCase(host) && port > 0;
+ }
+
private void startServer(final PluginConfiguration configuration) {
boolean enabled = Boolean.parseBoolean(configuration.getProps().getProperty("JVM_INFORMATION_COLLECTOR_ENABLED"));
registerJvm(enabled);
@@ -64,16 +85,4 @@ public final class PrometheusPluginBootService implements PluginBootService {
DefaultExports.initialize();
}
}
-
- @Override
- public void close() {
- if (null != httpServer) {
- httpServer.stop();
- }
- }
-
- @Override
- public String getType() {
- return "Prometheus";
- }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
index c290380..8d3d3de 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
@@ -38,9 +38,7 @@ public final class PrometheusPluginBootServiceTest {
public void assertStart() {
Properties props = new Properties();
props.setProperty("JVM_INFORMATION_COLLECTOR_ENABLED", "true");
- PluginConfiguration configuration = new PluginConfiguration();
- configuration.setPort(8090);
- configuration.setProps(props);
+ PluginConfiguration configuration = new PluginConfiguration("localhost", 8090, "", props);
prometheusPluginBootService.start(configuration);
Field field = PrometheusPluginBootService.class.getDeclaredField("httpServer");
field.setAccessible(true);
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 5e198f2..aa4c4d8 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
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.agent.plugin.tracing.jaeger.service;
import io.jaegertracing.Configuration;
import io.opentracing.util.GlobalTracer;
import org.apache.shardingsphere.agent.config.PluginConfiguration;
+import org.apache.shardingsphere.agent.exception.PluginConfigurationException;
import org.apache.shardingsphere.agent.spi.boot.PluginBootService;
import java.util.Optional;
@@ -34,6 +35,9 @@ public final class JaegerTracingPluginBootService implements PluginBootService {
@SuppressWarnings("AccessOfSystemProperties")
@Override
public void start(final PluginConfiguration pluginConfig) {
+ if (!checkConfig(pluginConfig)) {
+ throw new PluginConfigurationException("jaeger config error, host is null or port is %s", pluginConfig.getPort());
+ }
pluginConfig.getProps().forEach((key, value) -> System.setProperty(String.valueOf(key), String.valueOf(value)));
Configuration.SamplerConfiguration samplerConfig = Configuration.SamplerConfiguration.fromEnv();
Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv()
@@ -56,4 +60,10 @@ public final class JaegerTracingPluginBootService implements PluginBootService {
public String getType() {
return "Jaeger";
}
+
+ private boolean checkConfig(final PluginConfiguration pluginConfiguration) {
+ String host = pluginConfiguration.getHost();
+ int port = pluginConfiguration.getPort();
+ return null != host && !"".equalsIgnoreCase(host) && port > 0;
+ }
}
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 c881137..4463b71 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
@@ -39,8 +39,7 @@ public final class JaegerTracingPluginBootServiceTest {
props.setProperty("JAEGER_SAMPLER_PARAM", "1");
props.setProperty("JAEGER_REPORTER_LOG_SPANS", "true");
props.setProperty("JAEGER_REPORTER_FLUSH_INTERVAL", "1");
- PluginConfiguration configuration = new PluginConfiguration();
- configuration.setProps(props);
+ PluginConfiguration configuration = new PluginConfiguration("localhost", 5775, "", props);
jaegerTracingPluginBootService.start(configuration);
assertThat(GlobalTracer.isRegistered(), is(true));
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootServiceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootSer [...]
index ff6e672..553dddc 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootServiceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/service/OpenTracingPluginBootServiceTest.java
@@ -34,8 +34,7 @@ public final class OpenTracingPluginBootServiceTest {
public void assertStart() {
Properties props = new Properties();
props.setProperty("OPENTRACING_TRACER_CLASS_NAME", "io.opentracing.mock.MockTracer");
- PluginConfiguration configuration = new PluginConfiguration();
- configuration.setProps(props);
+ PluginConfiguration configuration = new PluginConfiguration("localhost", 8090, "", props);
openTracingPluginBootService.start(configuration);
assertThat(GlobalTracer.isRegistered(), is(true));
}
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 7e7446f..ccfa58d 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
@@ -21,6 +21,7 @@ import brave.Tracing;
import java.util.Optional;
import java.util.Properties;
import org.apache.shardingsphere.agent.config.PluginConfiguration;
+import org.apache.shardingsphere.agent.exception.PluginConfigurationException;
import org.apache.shardingsphere.agent.spi.boot.PluginBootService;
import zipkin2.reporter.brave.AsyncZipkinSpanHandler;
import zipkin2.reporter.okhttp3.OkHttpSender;
@@ -38,6 +39,9 @@ public final class ZipkinTracingPluginBootService implements PluginBootService {
@Override
public void start(final PluginConfiguration pluginConfig) {
+ if (!checkConfig(pluginConfig)) {
+ throw new PluginConfigurationException("zipkin config error, host is null or port is %s", 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");
@@ -57,4 +61,10 @@ public final class ZipkinTracingPluginBootService implements PluginBootService {
public String getType() {
return "Zipkin";
}
+
+ private boolean checkConfig(final PluginConfiguration pluginConfiguration) {
+ String host = pluginConfiguration.getHost();
+ int port = pluginConfiguration.getPort();
+ return null != host && !"".equalsIgnoreCase(host) && port > 0;
+ }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootServiceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootServiceTest.java
index 8aa63c7..a991789 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootServiceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootServiceTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.agent.plugin.tracing.zipkin.service;
import brave.Tracing;
import java.lang.reflect.Field;
+import java.util.Properties;
import lombok.SneakyThrows;
import org.apache.shardingsphere.agent.config.PluginConfiguration;
@@ -36,8 +37,7 @@ public final class ZipkinTracingPluginBootServiceTest {
@SneakyThrows
@Test
public void assertStart() {
- PluginConfiguration configuration = new PluginConfiguration();
- configuration.setPort(9441);
+ PluginConfiguration configuration = new PluginConfiguration("localhost", 9441, "", new Properties());
zipkinTracingPluginBootService.start(configuration);
Field field = ZipkinTracingPluginBootService.class.getDeclaredField("tracing");
field.setAccessible(true);