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

[shardingsphere] branch master updated: Support metrics for jdbc with spring namespace (#6956)

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

kimmking 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 8433cca  Support metrics for jdbc with spring namespace (#6956)
8433cca is described below

commit 8433cca946e63d309713e16862d94e1102b6ae1c
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Thu Aug 20 22:29:01 2020 +0800

    Support metrics for jdbc with spring namespace (#6956)
---
 .../configuration/config/MetricsConfiguration.java |  2 +
 .../OrchestrationShardingSphereDataSource.java     | 44 +++++++++++++
 .../constants/DataSourceBeanDefinitionTag.java     |  2 +
 ...itionTag.java => MetricsBeanDefinitionTag.java} | 20 +++---
 .../MetricsNamespaceHandler.java}                  | 30 +++------
 .../parser/DataSourceBeanDefinitionParser.java     |  4 ++
 .../parser/MetricsBeanDefinitionParser.java        | 75 ++++++++++++++++++++++
 .../namespace/{orchestration.xsd => metrics.xsd}   | 36 +++--------
 .../resources/META-INF/namespace/orchestration.xsd |  1 +
 .../src/main/resources/META-INF/spring.handlers    |  1 +
 .../src/main/resources/META-INF/spring.schemas     |  1 +
 .../orchestration/MetricsNamespaceTest.java        | 46 +++++++++++++
 .../META-INF/rdb/namespace/metricsNamespace.xml    | 32 +++++++++
 13 files changed, 238 insertions(+), 56 deletions(-)

diff --git a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-configuration/src/main/java/org/apache/shardingsphere/metrics/configuration/config/MetricsConfiguration.java b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-configuration/src/main/java/org/apache/shardingsphere/metrics/configuration/config/MetricsConfiguration.java
index 97c465a..06f5f35 100644
--- a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-configuration/src/main/java/org/apache/shardingsphere/metrics/configuration/config/MetricsConfiguration.java
+++ b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-configuration/src/main/java/org/apache/shardingsphere/metrics/configuration/config/MetricsConfiguration.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.metrics.configuration.config;
 
 import lombok.AllArgsConstructor;
 import lombok.Getter;
+import lombok.NoArgsConstructor;
 import lombok.Setter;
 
 import java.util.Properties;
@@ -30,6 +31,7 @@ import org.apache.shardingsphere.control.panel.spi.ControlPanelConfiguration;
 @Getter
 @Setter
 @AllArgsConstructor
+@NoArgsConstructor
 public final class MetricsConfiguration implements ControlPanelConfiguration {
     
     public static final int DEFAULT_PORT = 9190;
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/main/java/org/apache/shardingsphere/driver/orchestration/internal/datasource/OrchestrationShardingSphereDataSource.java b/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/main/java/org/apache/shardingsphere/driver/orchestration/internal/datasource/OrchestrationShardingSphereDataSource.java
index b84aab4..66ec423 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/main/java/org/apache/shardingsphere/driver/orchestration/internal/datasource/OrchestrationShardingSphereDataSource.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/main/java/org/apache/shardingsphere/driver/orchestration/internal/datasource/OrchestrationShardingSphereDataSource.java
@@ -109,6 +109,26 @@ public final class OrchestrationShardingSphereDataSource extends AbstractUnsuppo
         initControlPanel();
     }
     
+    public OrchestrationShardingSphereDataSource(final OrchestrationConfiguration orchestrationConfig, final ClusterConfiguration clusterConfiguration) throws SQLException {
+        init(orchestrationConfig);
+        dataSource = loadDataSource();
+        initWithOrchestrationCenter();
+        initConfigurations(clusterConfiguration, null);
+        disableDataSources();
+        persistMetaData(dataSource.getSchemaContexts().getDefaultSchemaContext().getSchema().getMetaData().getSchema());
+        initControlPanel();
+    }
+    
+    public OrchestrationShardingSphereDataSource(final OrchestrationConfiguration orchestrationConfig, final MetricsConfiguration metricsConfiguration) throws SQLException {
+        init(orchestrationConfig);
+        dataSource = loadDataSource();
+        initWithOrchestrationCenter();
+        initConfigurations(null, metricsConfiguration);
+        disableDataSources();
+        persistMetaData(dataSource.getSchemaContexts().getDefaultSchemaContext().getSchema().getMetaData().getSchema());
+        initControlPanel();
+    }
+    
     public OrchestrationShardingSphereDataSource(final ShardingSphereDataSource dataSource, final OrchestrationConfiguration orchestrationConfig) {
         init(orchestrationConfig);
         this.dataSource = dataSource;
@@ -131,6 +151,30 @@ public final class OrchestrationShardingSphereDataSource extends AbstractUnsuppo
         initControlPanel();
     }
     
+    public OrchestrationShardingSphereDataSource(final ShardingSphereDataSource dataSource,
+                                                 final OrchestrationConfiguration orchestrationConfig,
+                                                 final ClusterConfiguration clusterConfiguration) {
+        init(orchestrationConfig);
+        this.dataSource = dataSource;
+        initWithLocalConfiguration();
+        initConfigurations(clusterConfiguration, null);
+        disableDataSources();
+        persistMetaData(this.dataSource.getSchemaContexts().getDefaultSchemaContext().getSchema().getMetaData().getSchema());
+        initControlPanel();
+    }
+    
+    public OrchestrationShardingSphereDataSource(final ShardingSphereDataSource dataSource,
+                                                 final OrchestrationConfiguration orchestrationConfig,
+                                                 final MetricsConfiguration metricsConfiguration) {
+        init(orchestrationConfig);
+        this.dataSource = dataSource;
+        initWithLocalConfiguration();
+        initConfigurations(null, metricsConfiguration);
+        disableDataSources();
+        persistMetaData(this.dataSource.getSchemaContexts().getDefaultSchemaContext().getSchema().getMetaData().getSchema());
+        initControlPanel();
+    }
+    
     private void init(final OrchestrationConfiguration config) {
         orchestrationFacade.init(config, Collections.singletonList(DefaultSchema.LOGIC_NAME));
         OrchestrationEventBus.getInstance().register(this);
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/DataSourceBeanDefinitionTag.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/DataS [...]
index 2d86cbb..c8f08d0 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/DataSourceBeanDefinitionTag.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/DataSourceBeanDefinitionTag.java
@@ -38,5 +38,7 @@ public final class DataSourceBeanDefinitionTag {
     
     public static final String CLUSTER_REF_ATTRIBUTE = "cluster-ref";
     
+    public static final String METRICS_REF_ATTRIBUTE = "metrics-ref";
+    
     public static final String OVERWRITE_ATTRIBUTE = "overwrite";
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/DataSourceBeanDefinitionTag.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/Metri [...]
similarity index 64%
copy from shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/DataSourceBeanDefinitionTag.java
copy to shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/MetricsBeanDefinitionTag.java
index 2d86cbb..d352259 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/DataSourceBeanDefinitionTag.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/MetricsBeanDefinitionTag.java
@@ -21,22 +21,24 @@ import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 
 /**
- * Data source bean definition tag.
+ * Metrics bean definition tag.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DataSourceBeanDefinitionTag {
+public final class MetricsBeanDefinitionTag {
     
-    public static final String ROOT_TAG = "data-source";
+    public static final String ROOT_TAG = "metrics";
     
-    public static final String ID_ATTRIBUTE = "id";
+    public static final String NAME_TAG = "name";
     
-    public static final String DATA_SOURCE_REF_ATTRIBUTE = "data-source-ref";
+    public static final String HOST_TAG = "host";
     
-    public static final String REG_CENTER_REF_ATTRIBUTE = "reg-center-ref";
+    public static final String PORT_TAG = "port";
     
-    public static final String CONFIG_CENTER_REF_ATTRIBUTE = "config-center-ref";
+    public static final String ASYNC_TAG = "async";
     
-    public static final String CLUSTER_REF_ATTRIBUTE = "cluster-ref";
+    public static final String ENABLE_TAG = "enable";
     
-    public static final String OVERWRITE_ATTRIBUTE = "overwrite";
+    public static final String THREAD_COUNT_TAG = "thread-count";
+    
+    public static final String PROPS_TAG = "props";
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/DataSourceBeanDefinitionTag.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/handler/Metrics [...]
similarity index 54%
copy from shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/DataSourceBeanDefinitionTag.java
copy to shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/handler/MetricsNamespaceHandler.java
index 2d86cbb..1e55709 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/constants/DataSourceBeanDefinitionTag.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/handler/MetricsNamespaceHandler.java
@@ -15,28 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.spring.namespace.orchestration.constants;
+package org.apache.shardingsphere.spring.namespace.orchestration.handler;
 
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.spring.namespace.orchestration.constants.MetricsBeanDefinitionTag;
+import org.apache.shardingsphere.spring.namespace.orchestration.parser.MetricsBeanDefinitionParser;
+import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
 
 /**
- * Data source bean definition tag.
+ * Metrics spring namespace handler.
  */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DataSourceBeanDefinitionTag {
-    
-    public static final String ROOT_TAG = "data-source";
-    
-    public static final String ID_ATTRIBUTE = "id";
-    
-    public static final String DATA_SOURCE_REF_ATTRIBUTE = "data-source-ref";
-    
-    public static final String REG_CENTER_REF_ATTRIBUTE = "reg-center-ref";
-    
-    public static final String CONFIG_CENTER_REF_ATTRIBUTE = "config-center-ref";
-    
-    public static final String CLUSTER_REF_ATTRIBUTE = "cluster-ref";
-    
-    public static final String OVERWRITE_ATTRIBUTE = "overwrite";
+public final class MetricsNamespaceHandler extends NamespaceHandlerSupport {
+    @Override
+    public void init() {
+        registerBeanDefinitionParser(MetricsBeanDefinitionTag.ROOT_TAG, new MetricsBeanDefinitionParser());
+    }
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/parser/DataSourceBeanDefinitionParser.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/parser/DataSour [...]
index ed36131..03af652 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/parser/DataSourceBeanDefinitionParser.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/parser/DataSourceBeanDefinitionParser.java
@@ -47,9 +47,13 @@ public final class DataSourceBeanDefinitionParser extends AbstractBeanDefinition
         }
         factory.addConstructorArgValue(getOrchestrationConfiguration(element));
         String cluster = element.getAttribute(DataSourceBeanDefinitionTag.CLUSTER_REF_ATTRIBUTE);
+        String metrics = element.getAttribute(DataSourceBeanDefinitionTag.METRICS_REF_ATTRIBUTE);
         if (!Strings.isNullOrEmpty(cluster)) {
             factory.addConstructorArgReference(cluster);
         }
+        if (!Strings.isNullOrEmpty(metrics)) {
+            factory.addConstructorArgReference(metrics);
+        }
     }
     
     private BeanDefinition getOrchestrationConfiguration(final Element element) {
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/parser/MetricsBeanDefinitionParser.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/parser/MetricsBean [...]
new file mode 100644
index 0000000..a5d7cf6
--- /dev/null
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/orchestration/parser/MetricsBeanDefinitionParser.java
@@ -0,0 +1,75 @@
+/*
+ * 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.spring.namespace.orchestration.parser;
+
+import com.google.common.base.Strings;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+import org.apache.shardingsphere.spring.namespace.orchestration.constants.MetricsBeanDefinitionTag;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.util.xml.DomUtils;
+import org.w3c.dom.Element;
+
+import java.util.Properties;
+
+/**
+ * Metrics bean definition parser.
+ */
+public final class MetricsBeanDefinitionParser extends AbstractBeanDefinitionParser {
+    
+    private static final String PROPERTY_NAME = "metricsName";
+    
+    private static final String PROPERTY_HOST = "host";
+    
+    private static final String PROPERTY_PORT = "port";
+    
+    private static final String PROPERTY_ASYNC = "async";
+    
+    private static final String PROPERTY_ENABLE = "enable";
+    
+    private static final String PROPERTY_THREAD_COUNT = "threadCount";
+    
+    private static final String PROPERTY_PROPS = "props";
+    
+    @Override
+    protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
+        BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(MetricsConfiguration.class);
+        addPropertyValueIfNotEmpty(MetricsBeanDefinitionTag.NAME_TAG, PROPERTY_NAME, element, factory);
+        addPropertyValueIfNotEmpty(MetricsBeanDefinitionTag.HOST_TAG, PROPERTY_HOST, element, factory);
+        addPropertyValueIfNotEmpty(MetricsBeanDefinitionTag.PORT_TAG, PROPERTY_PORT, element, factory);
+        addPropertyValueIfNotEmpty(MetricsBeanDefinitionTag.ASYNC_TAG, PROPERTY_ASYNC, element, factory);
+        addPropertyValueIfNotEmpty(MetricsBeanDefinitionTag.ENABLE_TAG, PROPERTY_ENABLE, element, factory);
+        addPropertyValueIfNotEmpty(MetricsBeanDefinitionTag.THREAD_COUNT_TAG, PROPERTY_THREAD_COUNT, element, factory);
+        factory.addPropertyValue(PROPERTY_PROPS, parseProperties(element, parserContext));
+        return factory.getBeanDefinition();
+    }
+    
+    private void addPropertyValueIfNotEmpty(final String attributeName, final String propertyName, final Element element, final BeanDefinitionBuilder factory) {
+        String attributeValue = element.getAttribute(attributeName);
+        if (!Strings.isNullOrEmpty(attributeValue)) {
+            factory.addPropertyValue(propertyName, attributeValue);
+        }
+    }
+    
+    private Properties parseProperties(final Element element, final ParserContext parserContext) {
+        Element propsElement = DomUtils.getChildElementByTagName(element, MetricsBeanDefinitionTag.PROPS_TAG);
+        return null == propsElement ? new Properties() : parserContext.getDelegate().parsePropsElement(propsElement);
+    }
+}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/namespace/orchestration.xsd b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/namespace/metrics.xsd
similarity index 56%
copy from shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/namespace/orchestration.xsd
copy to shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/namespace/metrics.xsd
index 51480b1..6d730e1 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/namespace/orchestration.xsd
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/namespace/metrics.xsd
@@ -18,41 +18,23 @@
 
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:beans="http://www.springframework.org/schema/beans"
-            xmlns="http://shardingsphere.apache.org/schema/shardingsphere/orchestration"
-            targetNamespace="http://shardingsphere.apache.org/schema/shardingsphere/orchestration"
+            xmlns="http://shardingsphere.apache.org/schema/shardingsphere/metrics"
+            targetNamespace="http://shardingsphere.apache.org/schema/shardingsphere/metrics"
             elementFormDefault="qualified">
     <xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd" />
     
-    <xsd:element name="data-source">
-        <xsd:complexType>
-            <xsd:attribute name="id" type="xsd:string" use="required" />
-            <xsd:attribute name="data-source-ref" type="xsd:string" />
-            <xsd:attribute name="reg-center-ref" type="xsd:string" use="required" />
-            <xsd:attribute name="config-center-ref" type="xsd:string" />
-            <xsd:attribute name="cluster-ref" type="xsd:string" />
-            <xsd:attribute name="overwrite" type="xsd:string" default="false" />
-        </xsd:complexType>
-    </xsd:element>
-    
-    <xsd:element name="reg-center">
-        <xsd:complexType>
-            <xsd:all>
-                <xsd:element ref="beans:props" minOccurs="0" />
-            </xsd:all>
-            <xsd:attribute name="id" type="xsd:string" use="required" />
-            <xsd:attribute name="type" type="xsd:string" use="required" />
-            <xsd:attribute name="server-lists" type="xsd:string" use="required" />
-        </xsd:complexType>
-    </xsd:element>
-    
-    <xsd:element name="config-center">
+    <xsd:element name="metrics">
         <xsd:complexType>
             <xsd:all>
                 <xsd:element ref="beans:props" minOccurs="0" />
             </xsd:all>
             <xsd:attribute name="id" type="xsd:string" use="required" />
-            <xsd:attribute name="type" type="xsd:string" use="required" />
-            <xsd:attribute name="server-lists" type="xsd:string" use="required" />
+            <xsd:attribute name="name" type="xsd:string" use="required" />
+            <xsd:attribute name="host" type="xsd:string" use="required" />
+            <xsd:attribute name="port" type="xsd:string" use="required" />
+            <xsd:attribute name="thread-count" type="xsd:string"/>
+            <xsd:attribute name="async" type="xsd:string" default="false"/>
+            <xsd:attribute name="enable" type="xsd:string" default="false"/>
         </xsd:complexType>
     </xsd:element>
 </xsd:schema>
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/namespace/orchestration.xsd b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/namespace/orchestration.xsd
index 51480b1..40939b6 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/namespace/orchestration.xsd
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/namespace/orchestration.xsd
@@ -30,6 +30,7 @@
             <xsd:attribute name="reg-center-ref" type="xsd:string" use="required" />
             <xsd:attribute name="config-center-ref" type="xsd:string" />
             <xsd:attribute name="cluster-ref" type="xsd:string" />
+            <xsd:attribute name="metrics-ref" type="xsd:string" />
             <xsd:attribute name="overwrite" type="xsd:string" default="false" />
         </xsd:complexType>
     </xsd:element>
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/spring.handlers b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/spring.handlers
index 5de5506..cfac1bf 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/spring.handlers
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/spring.handlers
@@ -17,3 +17,4 @@
 
 http\://shardingsphere.apache.org/schema/shardingsphere/orchestration=org.apache.shardingsphere.spring.namespace.orchestration.handler.OrchestrationNamespaceHandler
 http\://shardingsphere.apache.org/schema/shardingsphere/cluster=org.apache.shardingsphere.spring.namespace.orchestration.handler.ClusterNamespaceHandler
+http\://shardingsphere.apache.org/schema/shardingsphere/metrics=org.apache.shardingsphere.spring.namespace.orchestration.handler.MetricsNamespaceHandler
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/spring.schemas b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/spring.schemas
index 754869a..fbb2c84 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/spring.schemas
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/main/resources/META-INF/spring.schemas
@@ -17,3 +17,4 @@
 
 http\://shardingsphere.apache.org/schema/shardingsphere/orchestration/orchestration.xsd=META-INF/namespace/orchestration.xsd
 http\://shardingsphere.apache.org/schema/shardingsphere/orchestration/cluster.xsd=META-INF/namespace/cluster.xsd
+http\://shardingsphere.apache.org/schema/shardingsphere/orchestration/metrics.xsd=META-INF/namespace/metrics.xsd
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/orchestration/MetricsNamespaceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/orchestration/MetricsNamespaceTest.java
new file mode 100644
index 0000000..86a5c0d
--- /dev/null
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/orchestration/MetricsNamespaceTest.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.spring.namespace.orchestration;
+
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+import org.junit.Test;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+@ContextConfiguration(locations = "classpath:META-INF/rdb/namespace/metricsNamespace.xml")
+public final class MetricsNamespaceTest extends AbstractJUnit4SpringContextTests {
+    
+    @Test
+    public void assertMetricsConfiguration() {
+        MetricsConfiguration metricsConfiguration = applicationContext.getBean("metrics-config", MetricsConfiguration.class);
+        assertNotNull(metricsConfiguration);
+        assertThat(metricsConfiguration.getMetricsName(), is("prometheus"));
+        assertThat(metricsConfiguration.getHost(), is("127.0.0.1"));
+        assertThat(metricsConfiguration.getPort(), is(9191));
+        assertTrue(metricsConfiguration.getEnable());
+        assertFalse(metricsConfiguration.getAsync());
+        assertThat(metricsConfiguration.getThreadCount(), is(10));
+        assertThat(metricsConfiguration.getProps().getProperty("test"), is("test"));
+    }
+}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/resources/META-INF/rdb/namespace/metricsNamespace.xml b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/resources/META-INF/rdb/namespace/metricsNamespace.xml
new file mode 100644
index 0000000..b9d1f7b
--- /dev/null
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-namespace/src/test/resources/META-INF/rdb/namespace/metricsNamespace.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns="http://www.springframework.org/schema/beans"
+       xmlns:metrics="http://shardingsphere.apache.org/schema/shardingsphere/metrics"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+                           http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://shardingsphere.apache.org/schema/shardingsphere/metrics
+                           http://shardingsphere.apache.org/schema/shardingsphere/orchestration/metrics.xsd
+                           ">
+    <metrics:metrics id="metrics-config" name="prometheus" host="127.0.0.1" port="9191" async="false" enable="true" thread-count="10">
+        <props>
+            <prop key="test">test</prop>
+        </props>
+    </metrics:metrics>
+</beans>