You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2020/07/14 08:28:58 UTC

[shardingsphere] branch master updated: add sharding-proxy port in config center metrics path

This is an automated email from the ASF dual-hosted git repository.

menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new a677261  add sharding-proxy port in config center metrics path
     new 5d4d5d4  Merge pull request #6346 from yu199195/metrics-path
a677261 is described below

commit a6772617b115d7bd68694fc053208b07baec4114
Author: yu199195 <54...@qq.com>
AuthorDate: Tue Jul 14 15:18:20 2020 +0800

    add sharding-proxy port in config center metrics path
---
 .../core/configcenter/ConfigCenterNode.java        |  4 ++-
 .../core/configcenter/ConfigCenterTest.java        |  4 ++-
 .../instance/OrchestrationInstance.java            |  7 ++---
 .../shardingsphere/infra/constant/Constants.java   | 35 ++++++++++++++++++++++
 .../org/apache/shardingsphere/proxy/Bootstrap.java | 11 +++----
 5 files changed, 48 insertions(+), 13 deletions(-)

diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterNode.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterNode.java
index 935419f..023fb8b 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterNode.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterNode.java
@@ -26,6 +26,7 @@ import java.util.Collections;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.constant.Constants;
 import org.apache.shardingsphere.orchestration.core.common.utils.IpUtils;
 
 /**
@@ -174,6 +175,7 @@ public final class ConfigCenterNode {
      * @return metrics node path
      */
     public String getMetricsPath() {
-        return Joiner.on(PATH_SEPARATOR).join("", name, ROOT, METRICS_NODE, IpUtils.getIp());
+        String path = String.join(":", IpUtils.getIp(), System.getProperty(Constants.PORT_KEY, String.valueOf(Constants.DEFAULT_PORT)));
+        return Joiner.on(PATH_SEPARATOR).join("", name, ROOT, METRICS_NODE, path);
     }
 }
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java
index ee22134..c6a878d 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java
@@ -30,6 +30,7 @@ import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
+import org.apache.shardingsphere.infra.constant.Constants;
 import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
 import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
 import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
@@ -516,7 +517,8 @@ public final class ConfigCenterTest {
     
     @Test
     public void assertLoadMetricsConfiguration() {
-        when(configCenterRepository.get("/test/config/metrics/" + IpUtils.getIp())).thenReturn(METRICS_YAML);
+        String metricsPath = "/test/config/metrics/" + IpUtils.getIp() + ":" + System.getProperty(Constants.PORT_KEY, String.valueOf(Constants.DEFAULT_PORT));
+        when(configCenterRepository.get(metricsPath)).thenReturn(METRICS_YAML);
         ConfigCenter configurationService = new ConfigCenter("test", configCenterRepository);
         MetricsConfiguration actual = configurationService.loadMetricsConfiguration();
         assertNotNull(actual);
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registrycenter/src/main/java/org/apache/shardingsphere/orchestration/core/registrycenter/instance/OrchestrationInstance.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registrycenter/src/main/java/org/apache/shardingsphere/orchestration/core/registrycenter/instance/Orc [...]
index df51e3f..41b5b41 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registrycenter/src/main/java/org/apache/shardingsphere/orchestration/core/registrycenter/instance/OrchestrationInstance.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registrycenter/src/main/java/org/apache/shardingsphere/orchestration/core/registrycenter/instance/OrchestrationInstance.java
@@ -21,6 +21,7 @@ import java.lang.management.ManagementFactory;
 import java.util.UUID;
 
 import com.google.common.base.Strings;
+import org.apache.shardingsphere.infra.constant.Constants;
 import org.apache.shardingsphere.orchestration.core.common.utils.IpUtils;
 
 /**
@@ -32,13 +33,11 @@ public final class OrchestrationInstance {
 
     private static final OrchestrationInstance INSTANCE = new OrchestrationInstance();
     
-    private static final String PORT_KEY = "shardingsphere.port";
-    
     private String instanceId;
 
     private OrchestrationInstance() {
-        String tag = Strings.isNullOrEmpty(System.getProperty(PORT_KEY))
-                ? ManagementFactory.getRuntimeMXBean().getName().split(DELIMITER)[0] : System.getProperty(PORT_KEY);
+        String tag = Strings.isNullOrEmpty(System.getProperty(Constants.PORT_KEY))
+                ? ManagementFactory.getRuntimeMXBean().getName().split(DELIMITER)[0] : System.getProperty(Constants.PORT_KEY);
         instanceId = IpUtils.getIp() + DELIMITER + tag + DELIMITER + UUID.randomUUID().toString();
     }
 
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/Constants.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/Constants.java
new file mode 100644
index 0000000..dd4858b
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/Constants.java
@@ -0,0 +1,35 @@
+/*
+ * 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.infra.constant;
+
+/**
+ * ShardingSphere of constants.
+ */
+public final class Constants {
+    
+    /**
+     * PORT_KEY.
+     */
+    public static final String PORT_KEY = "shardingsphere.port";
+    
+    /**
+     * DEFAULT_PORT.
+     */
+    public static final int DEFAULT_PORT = 3307;
+}
+
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
index 898cb3c..417f969 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
@@ -31,6 +31,7 @@ import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
 import org.apache.shardingsphere.infra.auth.Authentication;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
+import org.apache.shardingsphere.infra.constant.Constants;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
@@ -71,12 +72,8 @@ import java.util.stream.Collectors;
 @Slf4j
 public final class Bootstrap {
     
-    private static final int DEFAULT_PORT = 3307;
-    
     private static final String DEFAULT_CONFIG_PATH = "/conf/";
     
-    private static final String PORT_KEY = "shardingsphere.port";
-    
     /**
      * Main entrance.
      *
@@ -85,7 +82,7 @@ public final class Bootstrap {
      */
     public static void main(final String[] args) throws Exception {
         int port = getPort(args);
-        System.setProperty(PORT_KEY, String.valueOf(port));
+        System.setProperty(Constants.PORT_KEY, String.valueOf(port));
         ShardingConfiguration shardingConfig = new ShardingConfigurationLoader().load(getConfigPath(args));
         logRuleConfigurationMap(getRuleConfigurations(shardingConfig.getRuleConfigurationMap()).values());
         boolean isOrchestration = null != shardingConfig.getServerConfiguration().getOrchestration();
@@ -97,10 +94,10 @@ public final class Bootstrap {
     
     private static int getPort(final String[] args) {
         if (0 == args.length) {
-            return DEFAULT_PORT;
+            return Constants.DEFAULT_PORT;
         }
         Integer port = Ints.tryParse(args[0]);
-        return port == null ? DEFAULT_PORT : port;
+        return port == null ? Constants.DEFAULT_PORT : port;
     }
     
     private static String getConfigPath(final String[] args) {