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 2022/12/18 04:21:43 UTC
[shardingsphere] branch master updated: Refactor PrometheusPluginBootService (#22949)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 a27051c79a3 Refactor PrometheusPluginBootService (#22949)
a27051c79a3 is described below
commit a27051c79a3e08e88d09163e9cd0b37a2fb61085
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Dec 18 12:21:37 2022 +0800
Refactor PrometheusPluginBootService (#22949)
---
.../metrics/prometheus/PrometheusPluginBootService.java | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/PrometheusPluginBootService.java b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/PrometheusPluginBootService.java
index 22cc44d55be..19b39fc9bef 100644
--- a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/PrometheusPluginBootService.java
+++ b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/PrometheusPluginBootService.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.agent.metrics.prometheus;
-import com.google.common.base.Preconditions;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.exporter.HTTPServer;
import io.prometheus.client.hotspot.DefaultExports;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
+import org.apache.shardingsphere.agent.core.config.validator.RemotePluginConfigurationValidator;
import org.apache.shardingsphere.agent.metrics.core.MetricsPool;
import org.apache.shardingsphere.agent.metrics.prometheus.collector.BuildInfoCollector;
import org.apache.shardingsphere.agent.metrics.prometheus.collector.MetaDataInfoCollector;
@@ -41,20 +41,17 @@ public final class PrometheusPluginBootService implements PluginBootService {
private static final String KEY_JVM_INFORMATION_COLLECTOR_ENABLED = "jvm-information-collector-enabled";
- private boolean isEnhancedForProxy;
-
private HTTPServer httpServer;
@Override
public void start(final PluginConfiguration pluginConfig, final boolean isEnhancedForProxy) {
- Preconditions.checkState(pluginConfig.getPort() > 0, "Prometheus config error, host is null or port is `%s`", pluginConfig.getPort());
- this.isEnhancedForProxy = isEnhancedForProxy;
- startServer(pluginConfig);
+ RemotePluginConfigurationValidator.validate(getType(), pluginConfig);
+ startServer(pluginConfig, isEnhancedForProxy);
MetricsPool.setMetricsFactory(new PrometheusWrapperFactory());
}
- private void startServer(final PluginConfiguration pluginConfig) {
- registerCollector(Boolean.parseBoolean(pluginConfig.getProps().getProperty(KEY_JVM_INFORMATION_COLLECTOR_ENABLED)));
+ private void startServer(final PluginConfiguration pluginConfig, final boolean isEnhancedForProxy) {
+ registerCollector(Boolean.parseBoolean(pluginConfig.getProps().getProperty(KEY_JVM_INFORMATION_COLLECTOR_ENABLED)), isEnhancedForProxy);
InetSocketAddress socketAddress = getSocketAddress(pluginConfig.getHost(), pluginConfig.getPort());
try {
httpServer = new HTTPServer(socketAddress, CollectorRegistry.defaultRegistry, true);
@@ -64,13 +61,13 @@ public final class PrometheusPluginBootService implements PluginBootService {
}
}
- private void registerCollector(final boolean enabled) {
+ private void registerCollector(final boolean isEnableCollectJVMInformation, final boolean isEnhancedForProxy) {
new BuildInfoCollector(isEnhancedForProxy).register();
if (isEnhancedForProxy) {
new ProxyInfoCollector().register();
new MetaDataInfoCollector().register();
}
- if (enabled) {
+ if (isEnableCollectJVMInformation) {
DefaultExports.initialize();
}
}