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 2020/12/23 11:22:52 UTC
[shardingsphere] branch master updated: refactor agent plugin boot
service spi (#8737)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new aa0ba61 refactor agent plugin boot service spi (#8737)
aa0ba61 is described below
commit aa0ba616298b75034ac62776e43b066a57d97731
Author: xiaoyu <54...@qq.com>
AuthorDate: Wed Dec 23 19:22:09 2020 +0800
refactor agent plugin boot service spi (#8737)
---
.../agent/bootstrap/ShardingSphereAgent.java | 18 +++--
.../agent/core/config/AgentConfiguration.java | 42 +++--------
.../JaegerPluginConfiguration.java} | 35 +++++----
.../PluginConfiguration.java} | 22 ++----
.../PrometheusPluginConfiguration.java} | 31 ++++----
.../ZipkinPluginConfiguration.java} | 33 +++++----
.../{ => loader}/AgentConfigurationLoader.java | 12 ++--
.../yaml/YamlAgentConfiguration.java} | 33 +++++----
.../yaml/YamlJaegerPluginConfiguration.java} | 34 +++++----
.../yaml/YamlPrometheusPluginConfiguration.java} | 32 +++++----
.../yaml/YamlZipkinPluginConfiguration.java} | 34 +++++----
.../JaegerPluginConfigurationYamlSwapper.java | 47 ++++++++++++
.../PrometheusPluginConfigurationYamlSwapper.java | 47 ++++++++++++
.../swapper/YamlAgentConfigurationSwapper.java | 46 ++++++++++++
.../ZipkinPluginConfigurationYamlSwapper.java | 47 ++++++++++++
.../core/plugin/loader/AgentPluginLoader.java | 31 +-------
.../agent/core/plugin/service/BootService.java | 16 ++++-
.../core/plugin/service/ServiceSupervisor.java | 72 +++++++++++--------
.../agent/core/spi/AgentTypedSPIRegistry.java | 32 +++++++++
.../shardingsphere/agent/core/yaml/YamlEngine.java | 7 +-
.../config/YamlConfiguration.java} | 21 +-----
.../config/YamlPluginConfiguration.java} | 22 ++----
.../constructor/AgentYamlConstructor.java} | 28 +++-----
.../swapper/YamlPluginConfigurationSwapper.java} | 29 ++++----
.../YamlPluginConfigurationSwapperEngine.java | 79 ++++++++++++++++++++
.../swapper/YamlSwapper.java} | 28 ++++----
...re.yaml.swapper.YamlPluginConfigurationSwapper} | 10 +--
.../core/config/AgentConfigurationLoaderTest.java | 1 +
.../src/test/resources/conf/agent.yaml | 22 +++++-
.../agent/metrics/api/MetricsProvider.java | 4 +-
.../api/prometheus/PrometheusMetricsRegister.java | 50 -------------
.../prometheus/service/PrometheusBootService.java | 84 ++++++++++++++++++++++
...ngsphere.agent.core.plugin.service.bootService} | 6 +-
.../shardingsphere/agent/metrics/api/BaseTest.java | 2 +-
.../src/test/resources/conf/agent.yaml | 7 +-
.../jaeger/definition/JaegerPluginDefinition.java | 2 -
...tService.java => JaegerTracingBootService.java} | 22 +++---
...ngsphere.agent.core.plugin.service.bootService} | 6 +-
.../zipkin/definition/ZipkinPluginDefinition.java | 2 -
...tService.java => ZipkinTracingBootService.java} | 24 ++++---
...ngsphere.agent.core.plugin.service.bootService} | 6 +-
41 files changed, 708 insertions(+), 418 deletions(-)
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 7d76319..e81de27 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
@@ -17,13 +17,16 @@
package org.apache.shardingsphere.agent.bootstrap;
+import java.util.Collection;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.dynamic.scaffold.TypeValidation;
import net.bytebuddy.matcher.ElementMatchers;
+import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
+import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
import org.apache.shardingsphere.agent.core.listener.LoggingListener;
import org.apache.shardingsphere.agent.core.transformer.ShardingSphereTransformer;
-import org.apache.shardingsphere.agent.core.config.AgentConfigurationLoader;
+import org.apache.shardingsphere.agent.core.config.loader.AgentConfigurationLoader;
import org.apache.shardingsphere.agent.core.plugin.loader.AgentPluginLoader;
import org.apache.shardingsphere.agent.core.plugin.service.ServiceSupervisor;
import org.apache.shardingsphere.agent.core.cache.AgentObjectPool;
@@ -44,10 +47,11 @@ public final class ShardingSphereAgent {
* @throws IOException IO exception
*/
public static void premain(final String arguments, final Instrumentation instrumentation) throws IOException {
- AgentObjectPool.INSTANCE.put(AgentConfigurationLoader.load());
+ AgentConfiguration agentConfiguration = AgentConfigurationLoader.load();
+ AgentObjectPool.INSTANCE.put(agentConfiguration);
AgentPluginLoader agentPluginLoader = createAgentPluginLoader();
setUpAgentBuilder(instrumentation, agentPluginLoader);
- superviseServices(agentPluginLoader.getBootServices());
+ setupPluginBootService(agentConfiguration.getPluginConfigurations());
}
private static AgentPluginLoader createAgentPluginLoader() throws IOException {
@@ -56,10 +60,10 @@ public final class ShardingSphereAgent {
return result;
}
- private static void superviseServices(final ServiceSupervisor serviceSupervisor) {
- serviceSupervisor.setUpAllServices();
- serviceSupervisor.startAllServices();
- Runtime.getRuntime().addShutdownHook(new Thread(serviceSupervisor::cleanUpAllServices));
+ private static void setupPluginBootService(final Collection<PluginConfiguration> pluginConfigurations) {
+ ServiceSupervisor.setupAllService(pluginConfigurations);
+ ServiceSupervisor.startAllService(pluginConfigurations);
+ Runtime.getRuntime().addShutdownHook(new Thread(ServiceSupervisor::clernAllService));
}
private static void setUpAgentBuilder(final Instrumentation instrumentation, final AgentPluginLoader agentPluginLoader) {
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java
index 5fdc8e9..49f9978 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java
@@ -17,46 +17,26 @@
package org.apache.shardingsphere.agent.core.config;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.LinkedList;
-import lombok.Data;
-
-import java.util.List;
-import java.util.Map;
+import java.util.Set;
+import lombok.Getter;
+import lombok.Setter;
/**
* Agent configuration.
*/
-@Data
-public class AgentConfiguration {
+@Getter
+@Setter
+public final class AgentConfiguration {
private String applicationName;
- private MetricsConfiguration metrics;
-
- private TracingConfiguration tracing;
+ private String metricsType = "prometheus";
- private List<String> activatedPlugins = new LinkedList<>();
+ private Set<String> ignorePlugins = new HashSet<>();
- @Data
- public static class MetricsConfiguration {
-
- private String type = "prometheus";
-
- private String host;
-
- private int port = 9090;
-
- private boolean jvmInformationCollectorEnabled;
- }
+ private Collection<PluginConfiguration> pluginConfigurations = new LinkedList<>();
- @Data
- public static class TracingConfiguration {
-
- private String agentHost = "localhost";
-
- private int agentPort = 5775;
-
- private Map<String, String> extra;
-
- }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/JaegerPluginConfiguration.java
similarity index 60%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/JaegerPluginConfiguration.java
index 16c7db7..e4c139c 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/JaegerPluginConfiguration.java
@@ -15,25 +15,30 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.config;
+
+import java.util.HashMap;
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * Jaeger plugin configuration.
*/
-public interface BootService {
+@Getter
+@Setter
+public final class JaegerPluginConfiguration implements PluginConfiguration {
+
+ private String applicationName = "shardingsphere-jaeger";
+
+ private String host = "localhost";
- /**
- * Setup the boot service, like to configure or to initial.
- */
- void setup();
+ private int port = 5775;
- /**
- * Start up the boot service.
- */
- void start();
+ private Map<String, String> extra = new HashMap<>();
- /**
- * Cleanup the boot service.
- */
- void cleanup();
+ @Override
+ public String getPluginName() {
+ return "Jaeger";
+ }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PluginConfiguration.java
similarity index 67%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PluginConfiguration.java
index 16c7db7..8c88145 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PluginConfiguration.java
@@ -15,25 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.config;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * Plugin configuration.
*/
-public interface BootService {
+public interface PluginConfiguration {
/**
- * Setup the boot service, like to configure or to initial.
+ * Get plugin name.
+ *
+ * @return plugin name
*/
- void setup();
-
- /**
- * Start up the boot service.
- */
- void start();
-
- /**
- * Cleanup the boot service.
- */
- void cleanup();
+ String getPluginName();
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PrometheusPluginConfiguration.java
similarity index 65%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PrometheusPluginConfiguration.java
index 16c7db7..2799969 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PrometheusPluginConfiguration.java
@@ -15,25 +15,26 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.config;
+
+import lombok.Getter;
+import lombok.Setter;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * Prometheus plugin configuration.
*/
-public interface BootService {
+@Getter
+@Setter
+public final class PrometheusPluginConfiguration implements PluginConfiguration {
+
+ private String host = "localhost";
- /**
- * Setup the boot service, like to configure or to initial.
- */
- void setup();
+ private int port = 9090;
- /**
- * Start up the boot service.
- */
- void start();
+ private boolean jvmInformationCollectorEnabled;
- /**
- * Cleanup the boot service.
- */
- void cleanup();
+ @Override
+ public String getPluginName() {
+ return "Prometheus";
+ }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/ZipkinPluginConfiguration.java
similarity index 63%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/ZipkinPluginConfiguration.java
index 16c7db7..5fbc684 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/ZipkinPluginConfiguration.java
@@ -15,25 +15,28 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.config;
+
+import java.util.HashMap;
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * Zipkin plugin configuration.
*/
-public interface BootService {
+@Getter
+@Setter
+public final class ZipkinPluginConfiguration implements PluginConfiguration {
+
+ private String host = "localhost";
- /**
- * Setup the boot service, like to configure or to initial.
- */
- void setup();
+ private int port = 15775;
- /**
- * Start up the boot service.
- */
- void start();
+ private Map<String, String> extra = new HashMap<>();
- /**
- * Cleanup the boot service.
- */
- void cleanup();
+ @Override
+ public String getPluginName() {
+ return "Zipkin";
+ }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfigurationLoader.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/loader/AgentConfigurationLoader.java
similarity index 74%
rename from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfigurationLoader.java
rename to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/loader/AgentConfigurationLoader.java
index 72e5674..fd34f7a 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfigurationLoader.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/loader/AgentConfigurationLoader.java
@@ -15,13 +15,16 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.config;
+package org.apache.shardingsphere.agent.core.config.loader;
import com.google.common.base.Preconditions;
import java.io.File;
import java.io.IOException;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.YamlAgentConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.swapper.YamlAgentConfigurationSwapper;
import org.apache.shardingsphere.agent.core.path.AgentPathBuilder;
import org.apache.shardingsphere.agent.core.yaml.YamlEngine;
@@ -44,11 +47,12 @@ public final class AgentConfigurationLoader {
public static AgentConfiguration load() throws IOException {
String specifiedConfigPath = System.getProperty(SPECIFIED_CONFIG_PATH);
File configFile = null == specifiedConfigPath ? new File(AgentPathBuilder.getAgentPath(), DEFAULT_CONFIG_PATH) : new File(specifiedConfigPath);
- return loadAgentConfiguration(configFile);
+ YamlAgentConfiguration yamlAgentConfiguration = loadAgentConfiguration(configFile);
+ return new YamlAgentConfigurationSwapper().swap(yamlAgentConfiguration);
}
- private static AgentConfiguration loadAgentConfiguration(final File yamlFile) throws IOException {
- AgentConfiguration result = YamlEngine.unmarshal(yamlFile, AgentConfiguration.class);
+ private static YamlAgentConfiguration loadAgentConfiguration(final File yamlFile) throws IOException {
+ YamlAgentConfiguration result = YamlEngine.unmarshal(yamlFile, YamlAgentConfiguration.class);
Preconditions.checkNotNull(result, "Agent configuration file `%s` is invalid.", yamlFile.getName());
return result;
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
similarity index 56%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
index 16c7db7..681bdfe 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
@@ -15,25 +15,28 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.config.yaml;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Set;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * YAML agent configuration.
*/
-public interface BootService {
+@Getter
+@Setter
+public final class YamlAgentConfiguration {
+
+ private String applicationName = "shardingsphere-agent";
- /**
- * Setup the boot service, like to configure or to initial.
- */
- void setup();
+ private String metricsType = "prometheus";
- /**
- * Start up the boot service.
- */
- void start();
+ private Set<String> ignorePlugins = new HashSet<>();
- /**
- * Cleanup the boot service.
- */
- void cleanup();
+ private Collection<YamlPluginConfiguration> plugins = new LinkedList<>();
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlJaegerPluginConfiguration.java
similarity index 58%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlJaegerPluginConfiguration.java
index 16c7db7..29c883d 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlJaegerPluginConfiguration.java
@@ -15,25 +15,29 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.config.yaml;
+
+import java.util.HashMap;
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * Jaeger plugin configuration for YAML.
*/
-public interface BootService {
+@Getter
+@Setter
+public final class YamlJaegerPluginConfiguration implements YamlPluginConfiguration {
+
+ private String host = "localhost";
- /**
- * Setup the boot service, like to configure or to initial.
- */
- void setup();
+ private int port = 5775;
- /**
- * Start up the boot service.
- */
- void start();
+ private Map<String, String> extra = new HashMap<>();
- /**
- * Cleanup the boot service.
- */
- void cleanup();
+ @Override
+ public String getPluginName() {
+ return "Jaeger";
+ }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPrometheusPluginConfiguration.java
similarity index 60%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPrometheusPluginConfiguration.java
index 16c7db7..2f1930f 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPrometheusPluginConfiguration.java
@@ -15,25 +15,27 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.config.yaml;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * Prometheus plugin configuration for YAML.
*/
-public interface BootService {
+@Getter
+@Setter
+public class YamlPrometheusPluginConfiguration implements YamlPluginConfiguration {
+
+ private String host = "localhost";
- /**
- * Setup the boot service, like to configure or to initial.
- */
- void setup();
+ private int port = 9090;
- /**
- * Start up the boot service.
- */
- void start();
+ private boolean jvmInformationCollectorEnabled;
- /**
- * Cleanup the boot service.
- */
- void cleanup();
+ @Override
+ public String getPluginName() {
+ return "Prometheus";
+ }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlZipkinPluginConfiguration.java
similarity index 58%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlZipkinPluginConfiguration.java
index 16c7db7..aa2f7e4 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlZipkinPluginConfiguration.java
@@ -15,25 +15,29 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.config.yaml;
+
+import java.util.HashMap;
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * Jaeger plugin configuration for YAML.
*/
-public interface BootService {
+@Getter
+@Setter
+public class YamlZipkinPluginConfiguration implements YamlPluginConfiguration {
+
+ private String host = "localhost";
- /**
- * Setup the boot service, like to configure or to initial.
- */
- void setup();
+ private int port = 15775;
- /**
- * Start up the boot service.
- */
- void start();
+ private Map<String, String> extra = new HashMap<>();
- /**
- * Cleanup the boot service.
- */
- void cleanup();
+ @Override
+ public String getPluginName() {
+ return "Zipkin";
+ }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/JaegerPluginConfigurationYamlSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/JaegerPluginConfigurationYamlSwapper.java
new file mode 100644
index 0000000..10080ec
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/JaegerPluginConfigurationYamlSwapper.java
@@ -0,0 +1,47 @@
+/*
+ * 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.swapper;
+
+import org.apache.shardingsphere.agent.core.config.JaegerPluginConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.YamlJaegerPluginConfiguration;
+import org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper;
+
+/**
+ * Jaeger plugin configuration YAML swapper.
+ */
+public final class JaegerPluginConfigurationYamlSwapper implements YamlPluginConfigurationSwapper<YamlJaegerPluginConfiguration, JaegerPluginConfiguration> {
+
+ @Override
+ public JaegerPluginConfiguration swapToObject(final YamlJaegerPluginConfiguration yamlConfig) {
+ JaegerPluginConfiguration result = new JaegerPluginConfiguration();
+ result.setHost(yamlConfig.getHost());
+ result.setPort(yamlConfig.getPort());
+ result.setExtra(yamlConfig.getExtra());
+ return result;
+ }
+
+ @Override
+ public String getPluginTagName() {
+ return "JAEGER";
+ }
+
+ @Override
+ public String getType() {
+ return "Jaeger";
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/PrometheusPluginConfigurationYamlSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/PrometheusPluginConfigurationYamlSwapper.java
new file mode 100644
index 0000000..e8b3d2d
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/PrometheusPluginConfigurationYamlSwapper.java
@@ -0,0 +1,47 @@
+/*
+ * 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.swapper;
+
+import org.apache.shardingsphere.agent.core.config.PrometheusPluginConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.YamlPrometheusPluginConfiguration;
+import org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper;
+
+/**
+ * Prometheus plugin configuration YAML swapper.
+ */
+public final class PrometheusPluginConfigurationYamlSwapper implements YamlPluginConfigurationSwapper<YamlPrometheusPluginConfiguration, PrometheusPluginConfiguration> {
+
+ @Override
+ public PrometheusPluginConfiguration swapToObject(final YamlPrometheusPluginConfiguration yamlConfig) {
+ PrometheusPluginConfiguration result = new PrometheusPluginConfiguration();
+ result.setHost(yamlConfig.getHost());
+ result.setPort(yamlConfig.getPort());
+ result.setJvmInformationCollectorEnabled(yamlConfig.isJvmInformationCollectorEnabled());
+ return result;
+ }
+
+ @Override
+ public String getPluginTagName() {
+ return "PROMETHEUS";
+ }
+
+ @Override
+ public String getType() {
+ return "Prometheus";
+ }
+}
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
new file mode 100644
index 0000000..0436a48
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.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.core.config.yaml.swapper;
+
+import java.util.Collection;
+import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
+import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.YamlAgentConfiguration;
+import org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapperEngine;
+
+/**
+ * YAML agent configuration swapper.
+ */
+public final class YamlAgentConfigurationSwapper {
+
+ /**
+ * Swap YAML agent configuration to agent configuration.
+ *
+ * @param yamlConfig YAML agent configuration
+ * @return agent configuration
+ */
+ public AgentConfiguration swap(final YamlAgentConfiguration yamlConfig) {
+ AgentConfiguration result = new AgentConfiguration();
+ result.setApplicationName(yamlConfig.getApplicationName());
+ result.setMetricsType(yamlConfig.getMetricsType());
+ result.setIgnorePlugins(yamlConfig.getIgnorePlugins());
+ Collection<PluginConfiguration> pluginConfigurations = YamlPluginConfigurationSwapperEngine.swapToPluginConfigurations(yamlConfig.getPlugins());
+ result.setPluginConfigurations(pluginConfigurations);
+ return result;
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/ZipkinPluginConfigurationYamlSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/ZipkinPluginConfigurationYamlSwapper.java
new file mode 100644
index 0000000..a7d2d02
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/ZipkinPluginConfigurationYamlSwapper.java
@@ -0,0 +1,47 @@
+/*
+ * 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.swapper;
+
+import org.apache.shardingsphere.agent.core.config.ZipkinPluginConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.YamlZipkinPluginConfiguration;
+import org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper;
+
+/**
+ * Zipkin plugin configuration YAML swapper.
+ */
+public final class ZipkinPluginConfigurationYamlSwapper implements YamlPluginConfigurationSwapper<YamlZipkinPluginConfiguration, ZipkinPluginConfiguration> {
+
+ @Override
+ public ZipkinPluginConfiguration swapToObject(final YamlZipkinPluginConfiguration yamlConfig) {
+ ZipkinPluginConfiguration result = new ZipkinPluginConfiguration();
+ result.setHost(yamlConfig.getHost());
+ result.setPort(yamlConfig.getPort());
+ result.setExtra(yamlConfig.getExtra());
+ return result;
+ }
+
+ @Override
+ public String getPluginTagName() {
+ return "ZIPKIN";
+ }
+
+ @Override
+ public String getType() {
+ return "Zipkin";
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoader.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoader.java
index 2f7fd30..5b500c5 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoader.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoader.java
@@ -18,11 +18,9 @@
package org.apache.shardingsphere.agent.core.plugin.loader;
import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
import com.google.common.io.ByteStreams;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
@@ -34,8 +32,6 @@ import org.apache.shardingsphere.agent.core.path.AgentPathBuilder;
import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
import org.apache.shardingsphere.agent.core.plugin.point.PluginInterceptorPoint;
import org.apache.shardingsphere.agent.core.plugin.definition.PluginDefinition;
-import org.apache.shardingsphere.agent.core.plugin.service.BootService;
-import org.apache.shardingsphere.agent.core.plugin.service.ServiceSupervisor;
import org.apache.shardingsphere.agent.core.cache.AgentObjectPool;
import java.io.ByteArrayOutputStream;
@@ -75,8 +71,6 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable {
private final List<PluginJar> jars = Lists.newArrayList();
- private final List<BootService> bootServices = Lists.newArrayList();
-
private Map<String, PluginInterceptorPoint> interceptorPointMap;
private AgentPluginLoader() {
@@ -110,8 +104,7 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable {
return;
}
Map<String, PluginInterceptorPoint> pointMap = Maps.newHashMap();
- List<String> activatedLists = AgentObjectPool.INSTANCE.get(AgentConfiguration.class).getActivatedPlugins();
- Set<String> activatedPlugins = Sets.newHashSet(activatedLists);
+ Set<String> activatedPlugins = AgentObjectPool.INSTANCE.get(AgentConfiguration.class).getIgnorePlugins();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
for (File jarFile : jarFiles) {
outputStream.reset();
@@ -131,7 +124,6 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable {
continue;
}
buildPluginInterceptorPointMap(pluginDefinition, pointMap);
- buildBootServices(pluginDefinition);
// CHECKSTYLE:OFF
} catch (final Throwable ex) {
// CHECKSTYLE:ON
@@ -187,15 +179,6 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable {
}
/**
- * Get the supervisor of boot services.
- *
- * @return service supervisor
- */
- public ServiceSupervisor getBootServices() {
- return new ServiceSupervisor(ImmutableList.<BootService>builder().addAll(bootServices).build());
- }
-
- /**
* To get or create instance of the advice class. Create new one and caching when it is not exist.
*
* @param classNameOfAdvice class name of advice
@@ -296,18 +279,6 @@ public final class AgentPluginLoader extends ClassLoader implements Closeable {
});
}
- private void buildBootServices(final PluginDefinition pluginDefinition) {
- pluginDefinition.getAllServices().forEach(each -> {
- try {
- bootServices.add(each.newInstance());
- // CHECKSTYLE:OFF
- } catch (final Throwable ex) {
- // CHECKSTYLE:ON
- log.error("Failed to create service instance, {}.", each, ex);
- }
- });
- }
-
@RequiredArgsConstructor
private static class PluginJar {
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
index 16c7db7..a958cfd 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
@@ -17,20 +17,30 @@
package org.apache.shardingsphere.agent.core.plugin.service;
+import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
+import org.apache.shardingsphere.agent.core.spi.AgentTypedSPI;
+
/**
* Boot service that the lifecycle is from the agent startup to shutdown.
+ *
+ * @param <T> plugin configuration
*/
-public interface BootService {
+public interface BootService<T extends PluginConfiguration> extends AgentTypedSPI {
/**
* Setup the boot service, like to configure or to initial.
+ *
+ * @param configuration configuration
*/
- void setup();
+ void setup(T configuration);
/**
* Start up the boot service.
+ *
+ * @param configuration configuration
*/
- void start();
+ default void start(T configuration) {
+ }
/**
* Cleanup the boot service.
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/ServiceSupervisor.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/ServiceSupervisor.java
index 10f66ec..a548478 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/ServiceSupervisor.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/ServiceSupervisor.java
@@ -17,55 +17,69 @@
package org.apache.shardingsphere.agent.core.plugin.service;
-import lombok.RequiredArgsConstructor;
+import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
-
-import java.util.List;
+import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
+import org.apache.shardingsphere.agent.core.spi.AgentTypedSPIRegistry;
/**
* Service supervisor.
*/
@Slf4j
-@RequiredArgsConstructor
+@SuppressWarnings("ALL")
public final class ServiceSupervisor {
- private final List<BootService> bootServices;
-
/**
- * Set up services.
+ * Set up all service.
+ *
+ * @param pluginConfigurations plugin configurations
*/
- public void setUpAllServices() {
- bootServices.forEach(each -> {
- try {
- each.setup();
- // CHECKSTYLE:OFF
- } catch (final Throwable ex) {
- // CHECKSTYLE:ON
- log.error("Failed to initial service.", ex);
+ public static void setupAllService(final Collection<PluginConfiguration> pluginConfigurations) {
+ Collection<String> pluginNames = pluginConfigurations.stream().map(PluginConfiguration::getPluginName).collect(Collectors.toList());
+ for (Map.Entry<String, BootService> entry : AgentTypedSPIRegistry.getRegisteredServices(pluginNames, BootService.class).entrySet()) {
+ for (PluginConfiguration each : pluginConfigurations) {
+ if (each.getPluginName().equals(entry.getKey())) {
+ try {
+ entry.getValue().setup(each);
+ // CHECKSTYLE:OFF
+ } catch (final Throwable ex) {
+ // CHECKSTYLE:ON
+ log.error("Failed to setup service.", ex);
+ }
+ }
}
- });
+ }
}
/**
- * Start all services.
+ * Start all service.
+ *
+ * @param pluginConfigurations plugin configurations
*/
- public void startAllServices() {
- bootServices.forEach(each -> {
- try {
- each.start();
- // CHECKSTYLE:OFF
- } catch (final Throwable ex) {
- // CHECKSTYLE:ON
- log.error("Failed to start service.", ex);
+ public static void startAllService(final Collection<PluginConfiguration> pluginConfigurations) {
+ Collection<String> pluginNames = pluginConfigurations.stream().map(PluginConfiguration::getPluginName).collect(Collectors.toList());
+ for (Map.Entry<String, BootService> entry : AgentTypedSPIRegistry.getRegisteredServices(pluginNames, BootService.class).entrySet()) {
+ for (PluginConfiguration each : pluginConfigurations) {
+ if (each.getPluginName().equals(entry.getKey())) {
+ try {
+ entry.getValue().start(each);
+ // CHECKSTYLE:OFF
+ } catch (final Throwable ex) {
+ // CHECKSTYLE:ON
+ log.error("Failed to start service.", ex);
+ }
+ }
}
- });
+ }
}
/**
- * Clean up all services.
+ * Clern all service.
*/
- public void cleanUpAllServices() {
- bootServices.forEach(each -> {
+ public static void clernAllService() {
+ AgentTypedSPIRegistry.getAllRegisteredService(BootService.class).forEach(each -> {
try {
each.cleanup();
// CHECKSTYLE:OFF
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentTypedSPIRegistry.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentTypedSPIRegistry.java
index 60d2d52..6cd60e2 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentTypedSPIRegistry.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentTypedSPIRegistry.java
@@ -17,6 +17,10 @@
package org.apache.shardingsphere.agent.core.spi;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -43,4 +47,32 @@ public final class AgentTypedSPIRegistry {
}
throw new AgentServiceProviderNotFoundException(typedSPIClass, type);
}
+
+ /**
+ * Get all registered service.
+ *
+ * @param typedSPIClass typed SPI class
+ * @param <T> type
+ * @return registered service
+ */
+ public static <T extends AgentTypedSPI> Collection<T> getAllRegisteredService(final Class<T> typedSPIClass) {
+ return AgentServiceLoader.getServiceLoader(typedSPIClass).newServiceInstances();
+ }
+
+ /**
+ * Get registered services.
+ *
+ * @param types types
+ * @param typedSPIClass typed SPI class
+ * @param <V> type of typed SPI class
+ * @return registered services
+ */
+ public static <V extends AgentTypedSPI> Map<String, V> getRegisteredServices(final Collection<String> types, final Class<V> typedSPIClass) {
+ Collection<V> registeredServices = AgentServiceLoader.getServiceLoader(typedSPIClass).newServiceInstances();
+ Map<String, V> result = new LinkedHashMap<>(registeredServices.size(), 1);
+ for (V each : registeredServices) {
+ types.stream().filter(type -> Objects.equals(each.getType(), type)).forEach(type -> result.put(type, each));
+ }
+ return result;
+ }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/YamlEngine.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/YamlEngine.java
index 2521d07..dc3e358 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/YamlEngine.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/YamlEngine.java
@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Properties;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.agent.core.yaml.constructor.AgentYamlConstructor;
import org.yaml.snakeyaml.Yaml;
/**
@@ -51,7 +52,7 @@ public final class YamlEngine {
FileInputStream fileInputStream = new FileInputStream(yamlFile);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream)
) {
- return new Yaml().loadAs(inputStreamReader, classType);
+ return new Yaml(new AgentYamlConstructor(classType)).loadAs(inputStreamReader, classType);
}
}
@@ -66,7 +67,7 @@ public final class YamlEngine {
*/
public static <T> T unmarshal(final byte[] yamlBytes, final Class<T> classType) throws IOException {
try (InputStream inputStream = new ByteArrayInputStream(yamlBytes)) {
- return new Yaml().loadAs(inputStream, classType);
+ return new Yaml(new AgentYamlConstructor(classType)).loadAs(inputStream, classType);
}
}
@@ -79,7 +80,7 @@ public final class YamlEngine {
* @return object from YAML
*/
public static <T> T unmarshal(final String yamlContent, final Class<T> classType) {
- return new Yaml().loadAs(yamlContent, classType);
+ return new Yaml(new AgentYamlConstructor(classType)).loadAs(yamlContent, classType);
}
/**
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlConfiguration.java
similarity index 66%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlConfiguration.java
index 16c7db7..3c1303e 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlConfiguration.java
@@ -15,25 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.yaml.config;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * YAML configuration.
*/
-public interface BootService {
-
- /**
- * Setup the boot service, like to configure or to initial.
- */
- void setup();
-
- /**
- * Start up the boot service.
- */
- void start();
-
- /**
- * Cleanup the boot service.
- */
- void cleanup();
+public interface YamlConfiguration {
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlPluginConfiguration.java
similarity index 67%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlPluginConfiguration.java
index 16c7db7..7a4d47a 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlPluginConfiguration.java
@@ -15,25 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.yaml.config;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * YAML plugin configuration.
*/
-public interface BootService {
+public interface YamlPluginConfiguration extends YamlConfiguration {
/**
- * Setup the boot service, like to configure or to initial.
+ * Get plugin name.
+ *
+ * @return plugin name
*/
- void setup();
-
- /**
- * Start up the boot service.
- */
- void start();
-
- /**
- * Cleanup the boot service.
- */
- void cleanup();
+ String getPluginName();
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/constructor/AgentYamlConstructor.java
similarity index 58%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/constructor/AgentYamlConstructor.java
index 16c7db7..fbf921e 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/constructor/AgentYamlConstructor.java
@@ -15,25 +15,19 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.yaml.constructor;
+
+import org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapperEngine;
+import org.yaml.snakeyaml.TypeDescription;
+import org.yaml.snakeyaml.constructor.Constructor;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * Agent YAML constructor.
*/
-public interface BootService {
-
- /**
- * Setup the boot service, like to configure or to initial.
- */
- void setup();
-
- /**
- * Start up the boot service.
- */
- void start();
+public final class AgentYamlConstructor extends Constructor {
- /**
- * Cleanup the boot service.
- */
- void cleanup();
+ public AgentYamlConstructor(final Class<?> rootClass) {
+ super(rootClass);
+ YamlPluginConfigurationSwapperEngine.getYamlShortcuts().forEach((key, value) -> addTypeDescription(new TypeDescription(value, key)));
+ }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapper.java
similarity index 55%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapper.java
index 16c7db7..297b1ce 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapper.java
@@ -15,25 +15,24 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.yaml.swapper;
+
+import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
+import org.apache.shardingsphere.agent.core.spi.AgentTypedSPI;
+import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * YAML plugin configuration swapper.
+ *
+ * @param <Y> type of YAML plugin configuration
+ * @param <T> type of plugin configuration
*/
-public interface BootService {
-
- /**
- * Setup the boot service, like to configure or to initial.
- */
- void setup();
-
- /**
- * Start up the boot service.
- */
- void start();
+public interface YamlPluginConfigurationSwapper<Y extends YamlPluginConfiguration, T extends PluginConfiguration> extends YamlSwapper<Y, T>, AgentTypedSPI {
/**
- * Cleanup the boot service.
+ * Get YAML plugin tag name.
+ *
+ * @return YAML plugin tag name
*/
- void cleanup();
+ String getPluginTagName();
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapperEngine.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapperEngine.java
new file mode 100644
index 0000000..dd8889c
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapperEngine.java
@@ -0,0 +1,79 @@
+/*
+ * 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.yaml.swapper;
+
+import java.lang.reflect.ParameterizedType;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
+import org.apache.shardingsphere.agent.core.spi.AgentServiceLoader;
+import org.apache.shardingsphere.agent.core.spi.AgentTypedSPIRegistry;
+import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
+
+/**
+ * YAML plugin configuration swapper engine.
+ */
+@SuppressWarnings("ALL")
+public final class YamlPluginConfigurationSwapperEngine {
+
+ /**
+ * Swap from YAML plugin configurations to plugin configurations.
+ *
+ * @param yamlPluginConfigurations YAML plugin configurations
+ * @return plugin configurations
+ */
+ public static Collection<PluginConfiguration> swapToPluginConfigurations(final Collection<YamlPluginConfiguration> yamlPluginConfigurations) {
+ Collection<PluginConfiguration> result = new LinkedList<>();
+ Collection<String> ruleConfigurationTypes = yamlPluginConfigurations.stream().map(YamlPluginConfiguration::getPluginName).collect(Collectors.toList());
+ for (Entry<String, YamlPluginConfigurationSwapper> entry : AgentTypedSPIRegistry.getRegisteredServices(ruleConfigurationTypes, YamlPluginConfigurationSwapper.class).entrySet()) {
+ result.addAll(swapToRuleConfigurations(yamlPluginConfigurations, entry.getKey(), entry.getValue()));
+ }
+ return result;
+ }
+
+ private static Collection<PluginConfiguration> swapToRuleConfigurations(final Collection<YamlPluginConfiguration> yamlPluginConfigurations,
+ final String type, final YamlPluginConfigurationSwapper swapper) {
+ Collection<PluginConfiguration> result = new LinkedList<>();
+ for (YamlPluginConfiguration each : yamlPluginConfigurations) {
+ if (each.getPluginName().equals(type)) {
+ result.add((PluginConfiguration) swapper.swapToObject(each));
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get YAML shortcuts.
+ *
+ * @return YAML shortcuts
+ */
+ @SneakyThrows(ReflectiveOperationException.class)
+ public static Map<String, Class<?>> getYamlShortcuts() {
+ Map<String, Class<?>> result = new HashMap<>();
+ for (YamlPluginConfigurationSwapper each : AgentServiceLoader.getServiceLoader(YamlPluginConfigurationSwapper.class).newServiceInstances()) {
+ Class<?> yamlRuleConfigurationClass = Class.forName(((ParameterizedType) each.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0].getTypeName());
+ result.put("!" + each.getPluginTagName(), yamlRuleConfigurationClass);
+ }
+ return result;
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlSwapper.java
similarity index 63%
copy from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlSwapper.java
index 16c7db7..c877ad0 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/BootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlSwapper.java
@@ -15,25 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.plugin.service;
+package org.apache.shardingsphere.agent.core.yaml.swapper;
+
+import org.apache.shardingsphere.agent.core.yaml.config.YamlConfiguration;
/**
- * Boot service that the lifecycle is from the agent startup to shutdown.
+ * YAML configuration swapper.
+ *
+ * @param <Y> type of YAML configuration
+ * @param <T> type of swapped object
*/
-public interface BootService {
-
- /**
- * Setup the boot service, like to configure or to initial.
- */
- void setup();
-
- /**
- * Start up the boot service.
- */
- void start();
+public interface YamlSwapper<Y extends YamlConfiguration, T> {
/**
- * Cleanup the boot service.
+ * Swap from YAML configuration to object.
+ *
+ * @param yamlConfig YAML configuration
+ * @return swapped object
*/
- void cleanup();
+ T swapToObject(Y yamlConfig);
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-core/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper
similarity index 73%
copy from shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml
copy to shardingsphere-agent/shardingsphere-agent-core/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper
index 90e5c3f..85fd8a7 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper
@@ -15,10 +15,6 @@
# limitations under the License.
#
-applicationName: shardingsphere-agent
-
-metrics:
- host: localhost
- port: 8090
- type: fixture
-
+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/config/AgentConfigurationLoaderTest.java b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/config/AgentConfigurationLoaderTest.java
index e3276de..12580fc 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/config/AgentConfigurationLoaderTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/config/AgentConfigurationLoaderTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.agent.core.config;
import java.io.IOException;
import java.net.URL;
+import org.apache.shardingsphere.agent.core.config.loader.AgentConfigurationLoader;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
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 d4b2635..81a9076 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
@@ -16,7 +16,23 @@
#
applicationName: shardingsphere-agent
+metricsType : prometheus
+ignorePlugins:
+ - test
+ - metrics
-metrics:
- host: localhost
- port: 8090
+plugins:
+ - !PROMETHEUS
+ host: "localhost"
+ port: 9090
+ jvmInformationCollectorEnabled : true
+ - !JAEGER
+ host: "localhost"
+ port: 5775
+ extra:
+ name: jaeger
+ - !ZIPKIN
+ host: "localhost"
+ port: 15775
+ extra:
+ name: zipkin
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsProvider.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsProvider.java
index d401a7b..395fc9e 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsProvider.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/MetricsProvider.java
@@ -34,8 +34,8 @@ public enum MetricsProvider {
private static MetricsRegisterFactory metricRegisterFactory;
static {
- AgentConfiguration.MetricsConfiguration metricsConfiguration = AgentObjectPool.INSTANCE.get(AgentConfiguration.class).getMetrics();
- metricRegisterFactory = AgentTypedSPIRegistry.getRegisteredService(MetricsRegisterFactory.class, metricsConfiguration.getType());
+ AgentConfiguration agentConfiguration = AgentObjectPool.INSTANCE.get(AgentConfiguration.class);
+ metricRegisterFactory = AgentTypedSPIRegistry.getRegisteredService(MetricsRegisterFactory.class, agentConfiguration.getMetricsType());
}
/**
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/prometheus/PrometheusMetricsRegister.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/prometheus/PrometheusMetricsRegister.java
index 9c54508..514b1f9 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/prometheus/PrometheusMetricsRegister.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/prometheus/PrometheusMetricsRegister.java
@@ -17,19 +17,12 @@
package org.apache.shardingsphere.agent.metrics.api.prometheus;
-import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import io.prometheus.client.Gauge;
import io.prometheus.client.Histogram;
-import io.prometheus.client.exporter.HTTPServer;
-import io.prometheus.client.hotspot.DefaultExports;
-import java.io.IOException;
-import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
-import org.apache.shardingsphere.agent.core.cache.AgentObjectPool;
import org.apache.shardingsphere.agent.metrics.api.MetricsRegister;
/**
@@ -44,16 +37,6 @@ public final class PrometheusMetricsRegister implements MetricsRegister {
private static final Map<String, Histogram> HISTOGRAM_MAP = new ConcurrentHashMap<>();
- private final AgentConfiguration.MetricsConfiguration metricsConfiguration = AgentObjectPool.INSTANCE.get(AgentConfiguration.class).getMetrics();
-
- private HTTPServer httpServer;
-
- private PrometheusMetricsRegister() {
- registerJvm();
- startServer();
- registerClose();
- }
-
/**
* Get instance prometheus metrics register.
*
@@ -146,39 +129,6 @@ public final class PrometheusMetricsRegister implements MetricsRegister {
}
}
- private void startServer() {
- int port = metricsConfiguration.getPort();
- String host = metricsConfiguration.getHost();
- InetSocketAddress inetSocketAddress;
- if ("".equals(host) || null == host) {
- inetSocketAddress = new InetSocketAddress(port);
- } else {
- inetSocketAddress = new InetSocketAddress(host, port);
- }
- try {
- httpServer = new HTTPServer(inetSocketAddress, CollectorRegistry.defaultRegistry, true);
- log.info(String.format("you start prometheus metrics http server host is: %s , port is: %s", inetSocketAddress.getHostString(), inetSocketAddress.getPort()));
- } catch (final IOException exception) {
- log.error("you start prometheus metrics http server is error", exception);
- }
- }
-
- private void registerJvm() {
- boolean enabled = metricsConfiguration.isJvmInformationCollectorEnabled();
- if (enabled) {
- new BuildInfoCollector().register();
- DefaultExports.initialize();
- }
- }
-
- private void registerClose() {
- Runtime.getRuntime().addShutdownHook(new Thread(() -> {
- if (null != httpServer) {
- httpServer.stop();
- }
- }));
- }
-
private static class PrometheusMetricsRegisterHolder {
private static final PrometheusMetricsRegister INSTANCE = new PrometheusMetricsRegister();
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/prometheus/service/PrometheusBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/prometheus/service/PrometheusBootService.java
new file mode 100644
index 0000000..e23ac7d
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/prometheus/service/PrometheusBootService.java
@@ -0,0 +1,84 @@
+/*
+ * 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.metrics.api.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.core.config.PrometheusPluginConfiguration;
+import org.apache.shardingsphere.agent.core.plugin.service.BootService;
+import org.apache.shardingsphere.agent.metrics.api.prometheus.BuildInfoCollector;
+
+/**
+ * Prometheus boot service.
+ */
+@Slf4j
+public class PrometheusBootService implements BootService<PrometheusPluginConfiguration> {
+
+ private HTTPServer httpServer;
+
+ @Override
+ public void setup(final PrometheusPluginConfiguration configuration) {
+ registerJvm(configuration);
+ }
+
+ @Override
+ public void start(final PrometheusPluginConfiguration configuration) {
+ startServer(configuration);
+ }
+
+ @Override
+ public void cleanup() {
+ if (null != httpServer) {
+ httpServer.stop();
+ }
+ }
+
+ @Override
+ public String getType() {
+ return "Prometheus";
+ }
+
+ private void registerJvm(final PrometheusPluginConfiguration configuration) {
+ boolean enabled = configuration.isJvmInformationCollectorEnabled();
+ if (enabled) {
+ new BuildInfoCollector().register();
+ DefaultExports.initialize();
+ }
+ }
+
+ private void startServer(final PrometheusPluginConfiguration configuration) {
+ int port = configuration.getPort();
+ String host = configuration.getHost();
+ InetSocketAddress inetSocketAddress;
+ if ("".equals(host) || null == host) {
+ inetSocketAddress = new InetSocketAddress(port);
+ } else {
+ inetSocketAddress = new InetSocketAddress(host, port);
+ }
+ try {
+ httpServer = new HTTPServer(inetSocketAddress, CollectorRegistry.defaultRegistry, true);
+ log.info(String.format("you start prometheus metrics http server host is: %s , port is: %s", inetSocketAddress.getHostString(), inetSocketAddress.getPort()));
+ } catch (final IOException exception) {
+ log.error("you start prometheus metrics http server is error", exception);
+ }
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.plugin.service.bootService
similarity index 90%
copy from shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
copy to shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.plugin.service.bootService
index d4b2635..667582c 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.plugin.service.bootService
@@ -15,8 +15,4 @@
# limitations under the License.
#
-applicationName: shardingsphere-agent
-
-metrics:
- host: localhost
- port: 8090
+org.apache.shardingsphere.agent.metrics.api.prometheus.service.PrometheusBootService
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 08e19c8..5e3257a 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
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.agent.metrics.api;
import java.io.IOException;
import java.net.URL;
import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
-import org.apache.shardingsphere.agent.core.config.AgentConfigurationLoader;
+import org.apache.shardingsphere.agent.core.config.loader.AgentConfigurationLoader;
import org.apache.shardingsphere.agent.core.cache.AgentObjectPool;
import org.junit.Before;
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml
index 90e5c3f..e501cda 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/resources/conf/agent.yaml
@@ -16,9 +16,4 @@
#
applicationName: shardingsphere-agent
-
-metrics:
- host: localhost
- port: 8090
- type: fixture
-
+metricsType: fixture
\ No newline at end of file
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/definition/JaegerPluginDefinition.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/definition/JaegerPluginDefinition.java
index 76a1826..4413398 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/definition/JaegerPluginDefinition.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/definition/JaegerPluginDefinition.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.agent.plugin.tracing.jaeger.definition;
import net.bytebuddy.matcher.ElementMatchers;
import org.apache.shardingsphere.agent.core.plugin.definition.PluginDefinition;
-import org.apache.shardingsphere.agent.plugin.tracing.jaeger.service.JaegerTracerBootService;
/**
* Jaeger plugin definition.
@@ -52,7 +51,6 @@ public final class JaegerPluginDefinition extends PluginDefinition {
@Override
protected void define() {
- registerService(JaegerTracerBootService.class);
intercept(COMMAND_EXECUTOR_TASK_ENHANCE_CLASS)
.aroundInstanceMethod(ElementMatchers.named(COMMAND_EXECUTOR_METHOD_NAME))
.implement(COMMAND_EXECUTOR_TASK_ADVICE_CLASS)
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/JaegerTracerBootService.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/JaegerTracingBootService.java
similarity index 70%
rename from shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracerBootService.java
rename to shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingBootService.java
index ab8983b..6955972 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/JaegerTracerBootService.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/JaegerTracingBootService.java
@@ -19,26 +19,23 @@ package org.apache.shardingsphere.agent.plugin.tracing.jaeger.service;
import io.jaegertracing.Configuration;
import io.opentracing.util.GlobalTracer;
-import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
+import org.apache.shardingsphere.agent.core.config.JaegerPluginConfiguration;
import org.apache.shardingsphere.agent.core.plugin.service.BootService;
-import org.apache.shardingsphere.agent.core.cache.AgentObjectPool;
/**
- * Jaeger tracer boot service.
+ * Jaeger tracing boot service.
*/
-public final class JaegerTracerBootService implements BootService {
+public final class JaegerTracingBootService implements BootService<JaegerPluginConfiguration> {
@Override
- public void setup() {
- AgentConfiguration configuration = AgentObjectPool.INSTANCE.get(AgentConfiguration.class);
- AgentConfiguration.TracingConfiguration tracingConfiguration = configuration.getTracing();
- tracingConfiguration.getExtra().forEach(System::setProperty);
+ public void setup(final JaegerPluginConfiguration configuration) {
+ configuration.getExtra().forEach(System::setProperty);
Configuration.SamplerConfiguration samplerConfig = Configuration.SamplerConfiguration.fromEnv();
Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv()
.withSender(
Configuration.SenderConfiguration.fromEnv()
- .withAgentHost(tracingConfiguration.getAgentHost())
- .withAgentPort(tracingConfiguration.getAgentPort())
+ .withAgentHost(configuration.getHost())
+ .withAgentPort(configuration.getPort())
);
Configuration config = new Configuration(configuration.getApplicationName())
.withSampler(samplerConfig)
@@ -47,10 +44,11 @@ public final class JaegerTracerBootService implements BootService {
}
@Override
- public void start() {
+ public void cleanup() {
}
@Override
- public void cleanup() {
+ public String getType() {
+ return "Jaeger";
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.plugin.service.bootService
similarity index 90%
copy from shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
copy to shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.plugin.service.bootService
index d4b2635..b93c361 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.plugin.service.bootService
@@ -15,8 +15,4 @@
# limitations under the License.
#
-applicationName: shardingsphere-agent
-
-metrics:
- host: localhost
- port: 8090
+org.apache.shardingsphere.agent.plugin.tracing.jaeger.service.JaegerTracingBootService
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/definition/ZipkinPluginDefinition.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/definition/ZipkinPluginDefinition.java
index f067ad1..1176315 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/definition/ZipkinPluginDefinition.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/definition/ZipkinPluginDefinition.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.agent.plugin.tracing.zipkin.definition;
import net.bytebuddy.matcher.ElementMatchers;
import org.apache.shardingsphere.agent.core.plugin.definition.PluginDefinition;
-import org.apache.shardingsphere.agent.plugin.tracing.zipkin.service.ZipkinTracerBootService;
/**
* Zipkin plugin definition.
@@ -52,7 +51,6 @@ public final class ZipkinPluginDefinition extends PluginDefinition {
@Override
protected void define() {
- registerService(ZipkinTracerBootService.class);
intercept(COMMAND_EXECUTOR_TASK_ENHANCE_CLASS)
.aroundInstanceMethod(ElementMatchers.named(COMMAND_EXECUTOR_METHOD_NAME))
.implement(COMMAND_EXECUTOR_TASK_ADVICE_CLASS)
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/ZipkinTracerBootService.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/ZipkinTracingBootService.java
similarity index 67%
rename from shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracerBootService.java
rename to shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingBootService.java
index 338ef70..f483ced 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/ZipkinTracerBootService.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/ZipkinTracingBootService.java
@@ -18,16 +18,15 @@
package org.apache.shardingsphere.agent.plugin.tracing.zipkin.service;
import brave.Tracing;
-import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
+import org.apache.shardingsphere.agent.core.config.ZipkinPluginConfiguration;
import org.apache.shardingsphere.agent.core.plugin.service.BootService;
-import org.apache.shardingsphere.agent.core.cache.AgentObjectPool;
import zipkin2.reporter.brave.AsyncZipkinSpanHandler;
import zipkin2.reporter.okhttp3.OkHttpSender;
/**
- * Zipkin tracer boot service.
+ * Zipkin tracing boot service.
*/
-public final class ZipkinTracerBootService implements BootService {
+public final class ZipkinTracingBootService implements BootService<ZipkinPluginConfiguration> {
private AsyncZipkinSpanHandler zipkinSpanHandler;
@@ -36,15 +35,13 @@ public final class ZipkinTracerBootService implements BootService {
private Tracing tracing;
@Override
- public void setup() {
- AgentConfiguration configuration = AgentObjectPool.INSTANCE.get(AgentConfiguration.class);
- AgentConfiguration.TracingConfiguration tracingConfiguration = configuration.getTracing();
- sender = OkHttpSender.create(buildHttpPath(tracingConfiguration));
+ public void setup(final ZipkinPluginConfiguration configuration) {
+ sender = OkHttpSender.create(buildHttpPath(configuration));
zipkinSpanHandler = AsyncZipkinSpanHandler.create(sender);
}
@Override
- public void start() {
+ public void start(final ZipkinPluginConfiguration configuration) {
tracing = Tracing.newBuilder().localServiceName("shardingsphere-agent").addSpanHandler(zipkinSpanHandler).build();
}
@@ -55,7 +52,12 @@ public final class ZipkinTracerBootService implements BootService {
sender.close();
}
- private String buildHttpPath(final AgentConfiguration.TracingConfiguration tracingConfiguration) {
- return "http://" + tracingConfiguration.getAgentHost() + ":" + tracingConfiguration.getAgentPort();
+ private String buildHttpPath(final ZipkinPluginConfiguration configuration) {
+ return "http://" + configuration.getHost() + ":" + configuration.getPort();
+ }
+
+ @Override
+ public String getType() {
+ return "Zipkin";
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.plugin.service.bootService
similarity index 90%
copy from shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
copy to shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.plugin.service.bootService
index d4b2635..7e13d19 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.core.plugin.service.bootService
@@ -15,8 +15,4 @@
# limitations under the License.
#
-applicationName: shardingsphere-agent
-
-metrics:
- host: localhost
- port: 8090
+org.apache.shardingsphere.agent.plugin.tracing.zipkin.service.ZipkinTracingBootService