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

sunnianjun 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 652ba896c0e Use SPI to refactor MetricsCollectorFactory (#23634)
652ba896c0e is described below

commit 652ba896c0e36f66bb24688234ca2af20ef37ac1
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Jan 18 19:09:13 2023 +0800

    Use SPI to refactor MetricsCollectorFactory (#23634)
    
    * Use SPI to refactor MetricsCollectorFactory
---
 .../agent/core/spi/AgentServiceLoaderTest.java     |  8 +--
 .../agent/plugin/core/spi/PluginServiceLoader.java | 76 ++++++++++++++++++++++
 .../agent/plugin/core/spi/PluginTypedSPI.java}     | 21 +++---
 .../core/advice/RouteResultCountAdvice.java        |  4 +-
 .../metrics/core/advice/SQLParseCountAdvice.java   |  5 +-
 .../metrics/core/advice/SQLRouteCountAdvice.java   |  5 +-
 .../proxy/CommitTransactionsCountAdvice.java       |  2 +-
 .../proxy/CurrentConnectionsCountAdvice.java       |  4 +-
 .../advice/proxy/ExecuteErrorsCountAdvice.java     |  2 +-
 .../proxy/ExecuteLatencyHistogramAdvice.java       |  2 +-
 .../core/advice/proxy/RequestsCountAdvice.java     |  2 +-
 .../proxy/RollbackTransactionsCountAdvice.java     |  2 +-
 .../core/collector/MetricsCollectorFactory.java    |  4 +-
 .../core/collector/MetricsCollectorRegistry.java   | 18 ++---
 .../metrics/core/MetricsCollectorRegistryTest.java | 35 ----------
 .../core/advice/RouteResultCountAdviceTest.java    | 10 +--
 .../core/advice/SQLParseCountAdviceTest.java       |  6 +-
 .../core/advice/SQLRouteCountAdviceTest.java       |  6 +-
 .../proxy/CommitTransactionsCountAdviceTest.java   |  9 ++-
 .../proxy/CurrentConnectionsCountAdviceTest.java   |  9 ++-
 .../advice/proxy/ExecuteErrorsCountAdviceTest.java |  9 ++-
 .../proxy/ExecuteLatencyHistogramAdviceTest.java   |  9 ++-
 .../core/advice/proxy/RequestsCountAdviceTest.java |  9 ++-
 .../proxy/RollbackTransactionsCountAdviceTest.java |  9 ++-
 .../core/fixture/FixtureCollectorFactory.java      |  5 ++
 ....metrics.core.collector.MetricsCollectorFactory | 18 +++++
 .../PrometheusPluginLifecycleService.java          |  5 +-
 .../collector/PrometheusCollectorFactory.java      |  5 ++
 ....metrics.core.collector.MetricsCollectorFactory | 18 +++++
 test/e2e/agent/plugins/jaeger/pom.xml              | 21 ------
 test/e2e/agent/plugins/metrics/pom.xml             | 21 ------
 test/e2e/agent/plugins/opentelemetry/pom.xml       | 21 ------
 test/e2e/agent/plugins/zipkin/pom.xml              | 21 ------
 .../test/e2e/agent/zipkin/ZipkinPluginE2EIT.java   |  3 +-
 34 files changed, 195 insertions(+), 209 deletions(-)

diff --git 
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoaderTest.java
 
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoaderTest.java
index afe01739dec..8a84a2bd4b9 100644
--- 
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoaderTest.java
+++ 
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoaderTest.java
@@ -28,22 +28,22 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public final class AgentServiceLoaderTest {
-
+    
     @Test(expected = NullPointerException.class)
     public void assertGetServiceLoaderWithNullValue() {
         AgentServiceLoader.getServiceLoader(null);
     }
-
+    
     @Test(expected = IllegalArgumentException.class)
     public void assertGetServiceLoaderWithNoInterface() {
         AgentServiceLoader.getServiceLoader(Object.class);
     }
-
+    
     @Test
     public void assertGetServiceLoaderWithEmptyInstances() {
         
assertTrue(AgentServiceLoader.getServiceLoader(AgentServiceEmptySPIFixture.class).getServices().isEmpty());
     }
-
+    
     @Test
     public void assertGetServiceLoaderWithImplementSPI() {
         AgentServiceLoader<AgentServiceSPIFixture> actual = 
AgentServiceLoader.getServiceLoader(AgentServiceSPIFixture.class);
diff --git 
a/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/spi/PluginServiceLoader.java
 
b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/spi/PluginServiceLoader.java
new file mode 100644
index 00000000000..b8fb41b2307
--- /dev/null
+++ 
b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/spi/PluginServiceLoader.java
@@ -0,0 +1,76 @@
+/*
+ * 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.plugin.core.spi;
+
+import com.google.common.base.Preconditions;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Plugin service loader.
+ */
+public final class PluginServiceLoader<T> {
+    
+    private static final Map<Class<?>, PluginServiceLoader<?>> LOADERS = new 
ConcurrentHashMap<>();
+    
+    private final Collection<T> services;
+    
+    private PluginServiceLoader(final Class<T> service) {
+        validate(service);
+        this.services = load(service);
+    }
+    
+    private void validate(final Class<T> service) {
+        Preconditions.checkNotNull(service, "SPI class is null.");
+        Preconditions.checkArgument(service.isInterface(), "SPI class `%s` is 
not interface.", service);
+    }
+    
+    private Collection<T> load(final Class<T> service) {
+        Collection<T> result = new LinkedList<>();
+        for (T each : ServiceLoader.load(service)) {
+            result.add(each);
+        }
+        return result;
+    }
+    
+    /**
+     * Get singleton agent service loader.
+     *
+     * @param service service type
+     * @param <T> type of class
+     * @return agent service loader
+     */
+    @SuppressWarnings("unchecked")
+    public static <T extends PluginTypedSPI> PluginServiceLoader<T> 
getServiceLoader(final Class<T> service) {
+        return (PluginServiceLoader<T>) LOADERS.computeIfAbsent(service, 
PluginServiceLoader::new);
+    }
+    
+    /**
+     * Get service.
+     * 
+     * @param pluginType plugin type
+     * @return service
+     */
+    public T getService(final String pluginType) {
+        return services.stream().filter(each -> 
pluginType.equalsIgnoreCase(((PluginTypedSPI) 
each).getType())).findFirst().orElseThrow(() -> new 
UnsupportedOperationException(pluginType));
+    }
+}
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
 
b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/spi/PluginTypedSPI.java
similarity index 63%
rename from 
agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
rename to 
agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/spi/PluginTypedSPI.java
index 8c40856f160..38f1fc5b2ce 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/MetricsAdviceBaseTest.java
+++ 
b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/spi/PluginTypedSPI.java
@@ -15,16 +15,17 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.agent.plugin.metrics.core.advice;
+package org.apache.shardingsphere.agent.plugin.core.spi;
 
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureCollectorFactory;
-import org.junit.BeforeClass;
-
-public abstract class MetricsAdviceBaseTest {
+/**
+ * Plugin typed SPI.
+ */
+public interface PluginTypedSPI {
     
-    @BeforeClass
-    public static void setup() {
-        MetricsCollectorRegistry.setMetricsFactory(new 
FixtureCollectorFactory());
-    }
+    /**
+     * Get type.
+     *
+     * @return type
+     */
+    String getType();
 }
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
index bdb9e9429fc..4ae18259aed 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdvice.java
@@ -43,8 +43,8 @@ public final class RouteResultCountAdvice implements 
InstanceMethodAdvice {
         }
         for (RouteUnit each : ((RouteContext) result).getRouteUnits()) {
             RouteMapper dataSourceMapper = each.getDataSourceMapper();
-            
MetricsCollectorRegistry.<CounterMetricsCollector>get(ROUTED_DATA_SOURCES_METRIC_KEY).inc(dataSourceMapper.getActualName());
-            each.getTableMappers().forEach(table -> 
MetricsCollectorRegistry.<CounterMetricsCollector>get(ROUTED_TABLES_METRIC_KEY).inc(table.getActualName()));
+            
MetricsCollectorRegistry.<CounterMetricsCollector>get(ROUTED_DATA_SOURCES_METRIC_KEY,
 pluginType).inc(dataSourceMapper.getActualName());
+            each.getTableMappers().forEach(table -> 
MetricsCollectorRegistry.<CounterMetricsCollector>get(ROUTED_TABLES_METRIC_KEY, 
pluginType).inc(table.getActualName()));
         }
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
index deb0661a85f..f3f1ce7228b 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdvice.java
@@ -47,10 +47,9 @@ public final class SQLParseCountAdvice implements 
InstanceMethodAdvice {
     @Override
     public void afterMethod(final TargetAdviceObject target, final Method 
method, final Object[] args, final Object result, final String pluginType) {
         String sqlType = getSQLType((SQLStatement) result);
-        if (null == sqlType) {
-            return;
+        if (null != sqlType) {
+            
MetricsCollectorRegistry.<CounterMetricsCollector>get(PARSED_SQL_METRIC_KEY, 
pluginType).inc(sqlType);
         }
-        
MetricsCollectorRegistry.<CounterMetricsCollector>get(PARSED_SQL_METRIC_KEY).inc(sqlType);
     }
     
     private String getSQLType(final SQLStatement sqlStatement) {
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
index 1c3c39c2605..9650e11e13d 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdvice.java
@@ -42,10 +42,9 @@ public final class SQLRouteCountAdvice implements 
InstanceMethodAdvice {
         QueryContext queryContext = (QueryContext) args[1];
         SQLStatement sqlStatement = 
queryContext.getSqlStatementContext().getSqlStatement();
         String sqlType = getSQLType(sqlStatement);
-        if (null == sqlType) {
-            return;
+        if (null != sqlType) {
+            
MetricsCollectorRegistry.<CounterMetricsCollector>get(ROUTED_SQL_METRIC_KEY, 
pluginType).inc(sqlType);
         }
-        
MetricsCollectorRegistry.<CounterMetricsCollector>get(ROUTED_SQL_METRIC_KEY).inc(sqlType);
     }
     
     private String getSQLType(final SQLStatement sqlStatement) {
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
index 3eb84683a42..cff9aadf4a2 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdvice.java
@@ -33,6 +33,6 @@ public final class CommitTransactionsCountAdvice implements 
InstanceMethodAdvice
     
     @Override
     public void beforeMethod(final TargetAdviceObject target, final Method 
method, final Object[] args, final String pluginType) {
-        
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_COMMIT_TRANSACTIONS_METRIC_KEY).inc();
+        
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_COMMIT_TRANSACTIONS_METRIC_KEY,
 pluginType).inc();
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
index e7360d94f86..d2114c251ce 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdvice.java
@@ -35,10 +35,10 @@ public final class CurrentConnectionsCountAdvice implements 
InstanceMethodAdvice
     public void beforeMethod(final TargetAdviceObject target, final Method 
method, final Object[] args, final String pluginType) {
         switch (method.getName()) {
             case "channelActive":
-                
MetricsCollectorRegistry.<GaugeMetricsCollector>get(PROXY_CURRENT_CONNECTIONS_METRIC_KEY).inc();
+                
MetricsCollectorRegistry.<GaugeMetricsCollector>get(PROXY_CURRENT_CONNECTIONS_METRIC_KEY,
 pluginType).inc();
                 break;
             case "channelInactive":
-                
MetricsCollectorRegistry.<GaugeMetricsCollector>get(PROXY_CURRENT_CONNECTIONS_METRIC_KEY).dec();
+                
MetricsCollectorRegistry.<GaugeMetricsCollector>get(PROXY_CURRENT_CONNECTIONS_METRIC_KEY,
 pluginType).dec();
                 break;
             default:
                 break;
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
index 35716d62eda..3d456947e9e 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdvice.java
@@ -33,6 +33,6 @@ public final class ExecuteErrorsCountAdvice implements 
InstanceMethodAdvice {
     
     @Override
     public void afterMethod(final TargetAdviceObject target, final Method 
method, final Object[] args, final Object result, final String pluginType) {
-        
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_EXECUTE_ERRORS_METRIC_KEY).inc();
+        
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_EXECUTE_ERRORS_METRIC_KEY,
 pluginType).inc();
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
index ddb56aa255d..4b9931d2e33 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdvice.java
@@ -41,6 +41,6 @@ public final class ExecuteLatencyHistogramAdvice implements 
InstanceMethodAdvice
     
     @Override
     public void afterMethod(final TargetAdviceObject target, final Method 
method, final Object[] args, final Object result, final String pluginType) {
-        
MetricsCollectorRegistry.<HistogramMetricsCollector>get(PROXY_EXECUTE_LATENCY_MILLIS_METRIC_KEY).observe(methodTimeRecorder.getElapsedTimeAndClean(method));
+        
MetricsCollectorRegistry.<HistogramMetricsCollector>get(PROXY_EXECUTE_LATENCY_MILLIS_METRIC_KEY,
 pluginType).observe(methodTimeRecorder.getElapsedTimeAndClean(method));
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
index 56f91c4b3d0..43f8452cff7 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdvice.java
@@ -33,6 +33,6 @@ public final class RequestsCountAdvice implements 
InstanceMethodAdvice {
     
     @Override
     public void beforeMethod(final TargetAdviceObject target, final Method 
method, final Object[] args, final String pluginType) {
-        
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_REQUESTS_METRIC_KEY).inc();
+        
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_REQUESTS_METRIC_KEY,
 pluginType).inc();
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
index 13dec9c463e..bd3a7b1dbe9 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdvice.java
@@ -33,6 +33,6 @@ public final class RollbackTransactionsCountAdvice implements 
InstanceMethodAdvi
     
     @Override
     public void beforeMethod(final TargetAdviceObject target, final Method 
method, final Object[] args, final String pluginType) {
-        
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_ROLLBACK_TRANSACTIONS_METRIC_KEY).inc();
+        
MetricsCollectorRegistry.<CounterMetricsCollector>get(PROXY_ROLLBACK_TRANSACTIONS_METRIC_KEY,
 pluginType).inc();
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorFactory.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorFactory.java
index cee359112ca..7724136a107 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorFactory.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorFactory.java
@@ -17,10 +17,12 @@
 
 package org.apache.shardingsphere.agent.plugin.metrics.core.collector;
 
+import org.apache.shardingsphere.agent.plugin.core.spi.PluginTypedSPI;
+
 /**
  * Metrics collector factory.
  */
-public interface MetricsCollectorFactory {
+public interface MetricsCollectorFactory extends PluginTypedSPI {
     
     /**
      * Create metrics collector.
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
index 7ff4b1c2051..4ed495848d3 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/collector/MetricsCollectorRegistry.java
@@ -17,6 +17,8 @@
 
 package org.apache.shardingsphere.agent.plugin.metrics.core.collector;
 
+import org.apache.shardingsphere.agent.plugin.core.spi.PluginServiceLoader;
+
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -27,28 +29,18 @@ public final class MetricsCollectorRegistry {
     
     private static final Map<String, MetricsCollector> METRICS_WRAPPERS = new 
ConcurrentHashMap<>();
     
-    private static MetricsCollectorFactory factory;
-    
-    /**
-     * Set metrics collector factory.
-     *
-     * @param metricsCollectorFactory metrics collector factory
-     */
-    public static void setMetricsFactory(final MetricsCollectorFactory 
metricsCollectorFactory) {
-        MetricsCollectorRegistry.factory = metricsCollectorFactory;
-    }
-    
     /**
      * Get metrics collector.
      *
      * @param id metric ID
+     * @param pluginType plugin type
      * @param <T> type of metrics collector
      * @return metrics collector
      * @see <a 
href="https://bugs.openjdk.java.net/browse/JDK-8161372";>JDK-8161372</a>
      */
     @SuppressWarnings("unchecked")
-    public static <T extends MetricsCollector> T get(final String id) {
+    public static <T extends MetricsCollector> T get(final String id, final 
String pluginType) {
         T result = (T) METRICS_WRAPPERS.get(id);
-        return (T) (null == result ? METRICS_WRAPPERS.computeIfAbsent(id, 
factory::create) : result);
+        return (T) (null == result ? METRICS_WRAPPERS.computeIfAbsent(id, 
PluginServiceLoader.getServiceLoader(MetricsCollectorFactory.class).getService(pluginType)::create)
 : result);
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/MetricsCollectorRegistryTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/MetricsCollectorRegistryTest.java
deleted file mode 100644
index af1d6fa151b..00000000000
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/MetricsCollectorRegistryTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.plugin.metrics.core;
-
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureCollectorFactory;
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class MetricsCollectorRegistryTest {
-    
-    @Test
-    public void assertGet() {
-        MetricsCollectorRegistry.setMetricsFactory(new 
FixtureCollectorFactory());
-        assertThat(MetricsCollectorRegistry.get("test"), 
instanceOf(MetricsCollectorFixture.class));
-    }
-}
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
index 3ed3015d66a..b5f430d1f25 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/RouteResultCountAdviceTest.java
@@ -32,12 +32,12 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 
-public final class RouteResultCountAdviceTest extends MetricsAdviceBaseTest {
+public final class RouteResultCountAdviceTest {
     
     @After
     public void reset() {
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("routed_data_sources_total")).reset();
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("routed_tables_total")).reset();
+        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("routed_data_sources_total", "FIXTURE")).reset();
+        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("routed_tables_total", "FIXTURE")).reset();
     }
     
     @Test
@@ -47,9 +47,9 @@ public final class RouteResultCountAdviceTest extends 
MetricsAdviceBaseTest {
         RouteMapper tableMapper = new RouteMapper("t_order", "t_order_0");
         routeContext.getRouteUnits().add(new RouteUnit(dataSourceMapper, 
Collections.singleton(tableMapper)));
         new RouteResultCountAdvice().afterMethod(new MockTargetAdviceObject(), 
mock(Method.class), new Object[]{}, routeContext, "FIXTURE");
-        MetricsCollectorFixture wrapper = 
MetricsCollectorRegistry.get("routed_data_sources_total");
+        MetricsCollectorFixture wrapper = 
MetricsCollectorRegistry.get("routed_data_sources_total", "FIXTURE");
         assertThat(wrapper.getValue(), is(1d));
-        wrapper = MetricsCollectorRegistry.get("routed_tables_total");
+        wrapper = MetricsCollectorRegistry.get("routed_tables_total", 
"FIXTURE");
         assertThat(wrapper.getValue(), is(1d));
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
index a8c71688c82..2a07de649ef 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLParseCountAdviceTest.java
@@ -43,13 +43,13 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 
-public final class SQLParseCountAdviceTest extends MetricsAdviceBaseTest {
+public final class SQLParseCountAdviceTest {
     
     private static final String PARSED_SQL_METRIC_KEY = "parsed_sql_total";
     
     @After
     public void reset() {
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(PARSED_SQL_METRIC_KEY)).reset();
+        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(PARSED_SQL_METRIC_KEY, "FIXTURE")).reset();
     }
     
     @Test
@@ -114,6 +114,6 @@ public final class SQLParseCountAdviceTest extends 
MetricsAdviceBaseTest {
     
     private void assertParse(final String metricIds, final SQLStatement 
sqlStatement) {
         new SQLParseCountAdvice().afterMethod(new MockTargetAdviceObject(), 
mock(Method.class), new Object[]{}, sqlStatement, "FIXTURE");
-        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(metricIds)).getValue(), is(1d));
+        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(metricIds, "FIXTURE")).getValue(), is(1d));
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
index 375830fc2f0..068e0693fe0 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
@@ -36,7 +36,7 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 
-public final class SQLRouteCountAdviceTest extends MetricsAdviceBaseTest {
+public final class SQLRouteCountAdviceTest {
     
     private static final String ROUTED_SQL_METRIC_KEY = "routed_sql_total";
     
@@ -44,7 +44,7 @@ public final class SQLRouteCountAdviceTest extends 
MetricsAdviceBaseTest {
     
     @After
     public void reset() {
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(ROUTED_SQL_METRIC_KEY)).reset();
+        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(ROUTED_SQL_METRIC_KEY, "FIXTURE")).reset();
     }
     
     @Test
@@ -73,6 +73,6 @@ public final class SQLRouteCountAdviceTest extends 
MetricsAdviceBaseTest {
     
     public void assertRoute(final String metricId, final QueryContext 
queryContext) {
         advice.beforeMethod(new MockTargetAdviceObject(), mock(Method.class), 
new Object[]{new ConnectionContext(), queryContext}, "FIXTURE");
-        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(metricId)).getValue(), is(1d));
+        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(metricId, "FIXTURE")).getValue(), is(1d));
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
index 53aab8a874d..3d58b48c8a3 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CommitTransactionsCountAdviceTest.java
@@ -17,9 +17,8 @@
 
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
 import org.junit.After;
 import org.junit.Test;
@@ -30,7 +29,7 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 
-public final class CommitTransactionsCountAdviceTest extends 
MetricsAdviceBaseTest {
+public final class CommitTransactionsCountAdviceTest {
     
     private static final String PROXY_COMMIT_TRANSACTIONS_METRIC_KEY = 
"proxy_commit_transactions_total";
     
@@ -38,12 +37,12 @@ public final class CommitTransactionsCountAdviceTest 
extends MetricsAdviceBaseTe
     
     @After
     public void reset() {
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_commit_transactions_total")).reset();
+        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_commit_transactions_total", 
"FIXTURE")).reset();
     }
     
     @Test
     public void assertMethod() {
         advice.beforeMethod(new MockTargetAdviceObject(), mock(Method.class), 
new Object[]{}, "FIXTURE");
-        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(PROXY_COMMIT_TRANSACTIONS_METRIC_KEY)).getValue(), 
is(1D));
+        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(PROXY_COMMIT_TRANSACTIONS_METRIC_KEY, 
"FIXTURE")).getValue(), is(1D));
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
index d7488f881fb..5c2635bdc28 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/CurrentConnectionsCountAdviceTest.java
@@ -17,9 +17,8 @@
 
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
 import org.junit.After;
 import org.junit.Test;
@@ -31,13 +30,13 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-public final class CurrentConnectionsCountAdviceTest extends 
MetricsAdviceBaseTest {
+public final class CurrentConnectionsCountAdviceTest {
     
     private final CurrentConnectionsCountAdvice advice = new 
CurrentConnectionsCountAdvice();
     
     @After
     public void reset() {
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_current_connections")).reset();
+        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_current_connections", "FIXTURE")).reset();
     }
     
     @Test
@@ -46,7 +45,7 @@ public final class CurrentConnectionsCountAdviceTest extends 
MetricsAdviceBaseTe
         advice.beforeMethod(targetObject, mockMethod("channelActive"), new 
Object[]{}, "FIXTURE");
         advice.beforeMethod(targetObject, mockMethod("channelActive"), new 
Object[]{}, "FIXTURE");
         advice.beforeMethod(targetObject, mockMethod("channelInactive"), new 
Object[]{}, "FIXTURE");
-        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_current_connections")).getValue(), is(1d));
+        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_current_connections", 
"FIXTURE")).getValue(), is(1d));
     }
     
     private Method mockMethod(final String methodName) {
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
index 0e81153d5e4..19000e13222 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteErrorsCountAdviceTest.java
@@ -17,9 +17,8 @@
 
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
 import org.junit.After;
 import org.junit.Test;
@@ -30,17 +29,17 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 
-public final class ExecuteErrorsCountAdviceTest extends MetricsAdviceBaseTest {
+public final class ExecuteErrorsCountAdviceTest {
     
     @After
     public void reset() {
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_execute_errors_total")).reset();
+        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_execute_errors_total", "FIXTURE")).reset();
     }
     
     @Test
     public void assertCountExecuteErrors() {
         MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
         new ExecuteErrorsCountAdvice().afterMethod(targetObject, 
mock(Method.class), new Object[]{}, null, "FIXTURE");
-        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_execute_errors_total")).getValue(), is(1d));
+        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_execute_errors_total", 
"FIXTURE")).getValue(), is(1d));
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
index fb3897dd64d..d40c0098bb0 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/ExecuteLatencyHistogramAdviceTest.java
@@ -17,9 +17,8 @@
 
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
 import org.junit.After;
 import org.junit.Test;
@@ -30,11 +29,11 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
 import static org.mockito.Mockito.mock;
 
-public final class ExecuteLatencyHistogramAdviceTest extends 
MetricsAdviceBaseTest {
+public final class ExecuteLatencyHistogramAdviceTest {
     
     @After
     public void reset() {
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_execute_latency_millis")).reset();
+        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_execute_latency_millis", 
"FIXTURE")).reset();
     }
     
     @Test
@@ -45,6 +44,6 @@ public final class ExecuteLatencyHistogramAdviceTest extends 
MetricsAdviceBaseTe
         advice.beforeMethod(targetObject, method, new Object[]{}, "FIXTURE");
         Thread.sleep(500L);
         advice.afterMethod(targetObject, method, new Object[]{}, null, 
"FIXTURE");
-        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_execute_latency_millis")).getValue(), 
greaterThanOrEqualTo(500D));
+        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_execute_latency_millis", 
"FIXTURE")).getValue(), greaterThanOrEqualTo(500D));
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
index f9d655e2961..152abbf4dd5 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RequestsCountAdviceTest.java
@@ -17,9 +17,8 @@
 
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
 import org.junit.After;
 import org.junit.Test;
@@ -30,19 +29,19 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 
-public final class RequestsCountAdviceTest extends MetricsAdviceBaseTest {
+public final class RequestsCountAdviceTest {
     
     private final RequestsCountAdvice advice = new RequestsCountAdvice();
     
     @After
     public void reset() {
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_requests_total")).reset();
+        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_requests_total", "FIXTURE")).reset();
     }
     
     @Test
     public void assertCountRequests() {
         MockTargetAdviceObject targetObject = new MockTargetAdviceObject();
         advice.beforeMethod(targetObject, mock(Method.class), new Object[]{}, 
"FIXTURE");
-        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_requests_total")).getValue(), is(1d));
+        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_requests_total", "FIXTURE")).getValue(), 
is(1d));
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
index e3a5dfabead..e83d8d5d112 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/proxy/RollbackTransactionsCountAdviceTest.java
@@ -17,9 +17,8 @@
 
 package org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy;
 
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MetricsAdviceBaseTest;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.advice.MockTargetAdviceObject;
+import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
 import 
org.apache.shardingsphere.agent.plugin.metrics.core.fixture.MetricsCollectorFixture;
 import org.junit.After;
 import org.junit.Test;
@@ -30,18 +29,18 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 
-public final class RollbackTransactionsCountAdviceTest extends 
MetricsAdviceBaseTest {
+public final class RollbackTransactionsCountAdviceTest {
     
     private final RollbackTransactionsCountAdvice advice = new 
RollbackTransactionsCountAdvice();
     
     @After
     public void reset() {
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_rollback_transactions_total")).reset();
+        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_rollback_transactions_total", 
"FIXTURE")).reset();
     }
     
     @Test
     public void assertMethod() {
         advice.beforeMethod(new MockTargetAdviceObject(), mock(Method.class), 
new Object[]{}, "FIXTURE");
-        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_rollback_transactions_total")).getValue(), 
is(1D));
+        assertThat(((MetricsCollectorFixture) 
MetricsCollectorRegistry.get("proxy_rollback_transactions_total", 
"FIXTURE")).getValue(), is(1D));
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/FixtureCollectorFactory.java
 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/FixtureCollectorFactory.java
index be2403761f7..ab964f0c561 100644
--- 
a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/FixtureCollectorFactory.java
+++ 
b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/fixture/FixtureCollectorFactory.java
@@ -26,4 +26,9 @@ public final class FixtureCollectorFactory implements 
MetricsCollectorFactory {
     public MetricsCollector create(final String id) {
         return new MetricsCollectorFixture();
     }
+    
+    @Override
+    public String getType() {
+        return "FIXTURE";
+    }
 }
diff --git 
a/agent/plugins/metrics/core/src/test/resources/META-INF/services/org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory
 
b/agent/plugins/metrics/core/src/test/resources/META-INF/services/org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory
new file mode 100644
index 00000000000..a8cb342f4a6
--- /dev/null
+++ 
b/agent/plugins/metrics/core/src/test/resources/META-INF/services/org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.agent.plugin.metrics.core.fixture.FixtureCollectorFactory
diff --git 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
index 1a4e7a9a4fd..c5409d84032 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
+++ 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginLifecycleService.java
@@ -23,12 +23,10 @@ import io.prometheus.client.exporter.HTTPServer;
 import io.prometheus.client.hotspot.DefaultExports;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.agent.api.PluginConfiguration;
-import 
org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry;
+import 
org.apache.shardingsphere.agent.plugin.core.config.validator.PluginConfigurationValidator;
 import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.BuildInfoCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy.ProxyMetaDataInfoCollector;
 import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.business.proxy.ProxyStateCollector;
-import 
org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.PrometheusCollectorFactory;
-import 
org.apache.shardingsphere.agent.plugin.core.config.validator.PluginConfigurationValidator;
 import org.apache.shardingsphere.agent.spi.PluginLifecycleService;
 
 import java.io.IOException;
@@ -48,7 +46,6 @@ public final class PrometheusPluginLifecycleService 
implements PluginLifecycleSe
     public void start(final PluginConfiguration pluginConfig, final boolean 
isEnhancedForProxy) {
         PluginConfigurationValidator.validatePort(getType(), pluginConfig);
         startServer(pluginConfig, isEnhancedForProxy);
-        MetricsCollectorRegistry.setMetricsFactory(new 
PrometheusCollectorFactory());
     }
     
     private void startServer(final PluginConfiguration pluginConfig, final 
boolean isEnhancedForProxy) {
diff --git 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
index 0c811912894..9f47be186a7 100644
--- 
a/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
+++ 
b/agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusCollectorFactory.java
@@ -89,4 +89,9 @@ public final class PrometheusCollectorFactory implements 
MetricsCollectorFactory
         MetricConfiguration metricConfig = getMetricConfiguration(id);
         return new GaugeMetricFamily(metricConfig.getId(), 
metricConfig.getHelp(), value);
     }
+    
+    @Override
+    public String getType() {
+        return "Prometheus";
+    }
 }
diff --git 
a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory
 
b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory
new file mode 100644
index 00000000000..1898764beb8
--- /dev/null
+++ 
b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorFactory
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.agent.plugin.metrics.prometheus.collector.PrometheusCollectorFactory
diff --git a/test/e2e/agent/plugins/jaeger/pom.xml 
b/test/e2e/agent/plugins/jaeger/pom.xml
index acbc858abcc..b1e3bace696 100644
--- a/test/e2e/agent/plugins/jaeger/pom.xml
+++ b/test/e2e/agent/plugins/jaeger/pom.xml
@@ -84,27 +84,6 @@
                     </execution>
                 </executions>
             </plugin>
-            <plugin>
-                <artifactId>maven-resources-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>copy-resources</id>
-                        <goals>
-                            <goal>copy-resources</goal>
-                        </goals>
-                        <phase>validate</phase>
-                        <configuration>
-                            
<outputDirectory>target/test-classes</outputDirectory>
-                            <resources>
-                                <resource>
-                                    <directory>src/test/resources</directory>
-                                    <filtering>true</filtering>
-                                </resource>
-                            </resources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
     </build>
     
diff --git a/test/e2e/agent/plugins/metrics/pom.xml 
b/test/e2e/agent/plugins/metrics/pom.xml
index 54e1c9604a0..e37e995311b 100644
--- a/test/e2e/agent/plugins/metrics/pom.xml
+++ b/test/e2e/agent/plugins/metrics/pom.xml
@@ -84,27 +84,6 @@
                     </execution>
                 </executions>
             </plugin>
-            <plugin>
-                <artifactId>maven-resources-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>copy-resources</id>
-                        <goals>
-                            <goal>copy-resources</goal>
-                        </goals>
-                        <phase>validate</phase>
-                        <configuration>
-                            
<outputDirectory>target/test-classes</outputDirectory>
-                            <resources>
-                                <resource>
-                                    <directory>src/test/resources</directory>
-                                    <filtering>true</filtering>
-                                </resource>
-                            </resources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
     </build>
     
diff --git a/test/e2e/agent/plugins/opentelemetry/pom.xml 
b/test/e2e/agent/plugins/opentelemetry/pom.xml
index e527b961774..443b9620a10 100644
--- a/test/e2e/agent/plugins/opentelemetry/pom.xml
+++ b/test/e2e/agent/plugins/opentelemetry/pom.xml
@@ -89,27 +89,6 @@
                     </execution>
                 </executions>
             </plugin>
-            <plugin>
-                <artifactId>maven-resources-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>copy-resources</id>
-                        <goals>
-                            <goal>copy-resources</goal>
-                        </goals>
-                        <phase>validate</phase>
-                        <configuration>
-                            
<outputDirectory>target/test-classes</outputDirectory>
-                            <resources>
-                                <resource>
-                                    <directory>src/test/resources</directory>
-                                    <filtering>true</filtering>
-                                </resource>
-                            </resources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
     </build>
     
diff --git a/test/e2e/agent/plugins/zipkin/pom.xml 
b/test/e2e/agent/plugins/zipkin/pom.xml
index 816a33854f3..d23da9a2fa3 100644
--- a/test/e2e/agent/plugins/zipkin/pom.xml
+++ b/test/e2e/agent/plugins/zipkin/pom.xml
@@ -84,27 +84,6 @@
                     </execution>
                 </executions>
             </plugin>
-            <plugin>
-                <artifactId>maven-resources-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>copy-resources</id>
-                        <goals>
-                            <goal>copy-resources</goal>
-                        </goals>
-                        <phase>validate</phase>
-                        <configuration>
-                            
<outputDirectory>target/test-classes</outputDirectory>
-                            <resources>
-                                <resource>
-                                    <directory>src/test/resources</directory>
-                                    <filtering>true</filtering>
-                                </resource>
-                            </resources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
     </build>
     
diff --git 
a/test/e2e/agent/plugins/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/ZipkinPluginE2EIT.java
 
b/test/e2e/agent/plugins/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/ZipkinPluginE2EIT.java
index 44c0d86f580..4492bba8602 100644
--- 
a/test/e2e/agent/plugins/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/ZipkinPluginE2EIT.java
+++ 
b/test/e2e/agent/plugins/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/ZipkinPluginE2EIT.java
@@ -93,8 +93,7 @@ public final class ZipkinPluginE2EIT extends BasePluginE2EIT {
                 "INSERT INTO t_order (order_id, user_id, status) VALUES (10, 
10, 'INSERT_TEST')",
                 "DELETE FROM t_order WHERE order_id=10",
                 "UPDATE t_order SET status = 'ROLL_BACK' WHERE order_id =1000",
-                "SELECT * FROM t_order"
-        );
+                "SELECT * FROM t_order");
         traceResult.forEach(each -> 
traceStatement.addAll(extractTraceTags((List<?>) each)));
         sqlList.forEach(each -> assertTrue(String.format("Zipkin trace should 
contain `%s`.", each), traceStatement.contains(each)));
     }

Reply via email to