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 1e5fa98  Refactor code and fix failed build when path has space 
(#11912)
1e5fa98 is described below

commit 1e5fa9833b5511010f8ddc17d7033cd9cdb2b0ec
Author: Dachuan J <[email protected]>
AuthorDate: Mon Aug 23 09:57:02 2021 +0800

    Refactor code and fix failed build when path has space (#11912)
    
    * Refactor code and fix failed build when path has space
    
    * Trigger CI
---
 .../agent/core/config/AgentConfigurationLoaderTest.java  |  4 +++-
 .../metrics/prometheus/collector/ProxyInfoCollector.java | 16 ++++++++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

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 a09f1de..c28d4cc 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
@@ -26,6 +26,8 @@ import org.junit.Test;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.net.URLDecoder;
+
 import static org.junit.Assert.assertNotNull;
 
 public final class AgentConfigurationLoaderTest {
@@ -42,7 +44,7 @@ public final class AgentConfigurationLoaderTest {
     private String getResourceUrl() {
         URL url = 
AgentConfigurationLoader.class.getClassLoader().getResource("");
         if (null != url) {
-            return url.getFile();
+            return URLDecoder.decode(url.getFile());
         }
         return DEFAULT_CONFIG_PATH;
     }
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollector.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollector.java
index 664de21..9bcae1e 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollector.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollector.java
@@ -22,11 +22,13 @@ import io.prometheus.client.GaugeMetricFamily;
 import org.apache.shardingsphere.agent.metrics.api.constant.MetricIds;
 import org.apache.shardingsphere.agent.metrics.api.util.MetricsUtil;
 import 
org.apache.shardingsphere.agent.metrics.prometheus.wrapper.PrometheusWrapperFactory;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Proxy info collector.
@@ -39,6 +41,13 @@ public final class ProxyInfoCollector extends Collector {
     
     private static final PrometheusWrapperFactory FACTORY = new 
PrometheusWrapperFactory();
     
+    private static final ConcurrentHashMap<String, Integer> PROXY_STATE_MAP = 
new ConcurrentHashMap<String, Integer>();
+    
+    static {
+        PROXY_STATE_MAP.put("OK", 1);
+        PROXY_STATE_MAP.put("CIRCUIT_BREAK", 2);
+    }
+    
     @Override
     public List<MetricFamilySamples> collect() {
         List<MetricFamilySamples> result = new LinkedList<>();
@@ -46,10 +55,9 @@ public final class ProxyInfoCollector extends Collector {
             return result;
         }
         Optional<GaugeMetricFamily> proxyInfo = 
FACTORY.createGaugeMetricFamily(MetricIds.PROXY_INFO);
-        // TODO use digital instead of zero 
-//        proxyInfo.ifPresent(m -> 
-//                m.addMetric(Collections.singletonList(PROXY_STATE), 
ProxyContext.getInstance().getStateContext().getCurrentState().ordinal()));
-        proxyInfo.ifPresent(optional -> 
optional.addMetric(Collections.singletonList(PROXY_STATE), 0));
+        String currentState = 
ProxyContext.getInstance().getStateContext().getCurrentState();
+        proxyInfo.ifPresent(m -> 
+                m.addMetric(Collections.singletonList(PROXY_STATE), 
PROXY_STATE_MAP.get(currentState)));
         proxyInfo.ifPresent(result::add);
         return result;
     }

Reply via email to