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

albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new 8d1152d86d :bug:Fix/consumer provider metrics name cover (#11753)
8d1152d86d is described below

commit 8d1152d86df52b1c36a069d5375b661b44a5f98d
Author: songxiaosheng <[email protected]>
AuthorDate: Fri Mar 10 15:19:58 2023 +0800

    :bug:Fix/consumer provider metrics name cover (#11753)
---
 .../event/{MetricsEvent.java => MethodEvent.java}  | 44 +++--------
 .../apache/dubbo/metrics/event/MetricsEvent.java   | 38 +++++++---
 .../org/apache/dubbo/metrics/model/MetricsKey.java |  6 --
 .../collector/AggregateMetricsCollector.java       | 85 +++++++++++++---------
 .../collector/sample/MethodMetricsSampler.java     | 42 ++++++-----
 .../metrics/filter/MethodMetricsInterceptor.java   | 29 ++++++--
 .../dubbo/metrics/filter/MetricsClusterFilter.java | 14 +++-
 .../collector/AggregateMetricsCollectorTest.java   | 17 ++---
 .../dubbo/metrics/filter/MetricsFilterTest.java    | 29 ++++----
 .../collector/DefaultMetricsCollectorTest.java     | 22 +++---
 .../dubbo/metrics/sampler/CountSamplerTest.java    | 69 +++++++++---------
 11 files changed, 213 insertions(+), 182 deletions(-)

diff --git 
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/event/MetricsEvent.java
 
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/event/MethodEvent.java
similarity index 50%
copy from 
dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/event/MetricsEvent.java
copy to 
dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/event/MethodEvent.java
index 5c49988f2e..c876070e17 100644
--- 
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/event/MetricsEvent.java
+++ 
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/event/MethodEvent.java
@@ -17,47 +17,21 @@
 
 package org.apache.dubbo.metrics.event;
 
-import org.apache.dubbo.metrics.model.MethodMetric;
+public class MethodEvent extends MetricsEvent {
+    private String type;
 
-/**
- * BaseMetricsEvent.
- */
-public abstract class MetricsEvent {
-
-    /**
-     * Metric object. (eg. {@link MethodMetric})
-     */
-    protected transient Object source;
-
-    public MetricsEvent(Object source) {
-        if (source == null) {
-            throw new IllegalArgumentException("null source");
-        }
-
-        this.source = source;
+    public MethodEvent(Object source, String type) {
+        super(source);
+        this.type = type;
     }
 
-    public Object getSource() {
-        return source;
+    public String getType() {
+        return type;
     }
 
-    public String toString() {
-        return getClass().getName() + "[source=" + source + "]";
+    public void setType(String type) {
+        this.type = type;
     }
 
-    public enum Type {
-        TOTAL,
-        SUCCEED,
-        BUSINESS_FAILED,
-        REQUEST_TIMEOUT,
-        REQUEST_LIMIT,
-        PROCESSING,
-        UNKNOWN_FAILED,
-        TOTAL_FAILED,
-        APPLICATION_INFO,
-        NETWORK_EXCEPTION,
-        SERVICE_UNAVAILABLE,
-        CODEC_EXCEPTION;
 
-    }
 }
diff --git 
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/event/MetricsEvent.java
 
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/event/MetricsEvent.java
index 5c49988f2e..0a67ac9029 100644
--- 
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/event/MetricsEvent.java
+++ 
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/event/MetricsEvent.java
@@ -46,18 +46,32 @@ public abstract class MetricsEvent {
     }
 
     public enum Type {
-        TOTAL,
-        SUCCEED,
-        BUSINESS_FAILED,
-        REQUEST_TIMEOUT,
-        REQUEST_LIMIT,
-        PROCESSING,
-        UNKNOWN_FAILED,
-        TOTAL_FAILED,
-        APPLICATION_INFO,
-        NETWORK_EXCEPTION,
-        SERVICE_UNAVAILABLE,
-        CODEC_EXCEPTION;
+        TOTAL("TOTAL_%s"),
+        SUCCEED("SUCCEED_%s"),
+        BUSINESS_FAILED("BUSINESS_FAILED_%s"),
+        REQUEST_TIMEOUT("REQUEST_TIMEOUT_%s"),
+        REQUEST_LIMIT("REQUEST_LIMIT_%s"),
+        PROCESSING("PROCESSING_%s"),
+        UNKNOWN_FAILED("UNKNOWN_FAILED_%s"),
+        TOTAL_FAILED("TOTAL_FAILED_%s"),
+        APPLICATION_INFO("APPLICATION_INFO_%s"),
+        NETWORK_EXCEPTION("NETWORK_EXCEPTION_%s"),
+        SERVICE_UNAVAILABLE("SERVICE_UNAVAILABLE_%s"),
+        CODEC_EXCEPTION("CODEC_EXCEPTION_%s"),;
 
+        private String name;
+
+        public final String getName() {
+            return this.name;
+        }
+
+        public final String getNameByType(String type) {
+            return String.format(name, type);
+        }
+
+
+        Type(String name) {
+            this.name = name;
+        }
     }
 }
diff --git 
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsKey.java
 
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsKey.java
index 8d55c707b1..86b2c873c9 100644
--- 
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsKey.java
+++ 
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsKey.java
@@ -106,12 +106,6 @@ public enum MetricsKey {
         return String.format(name, type);
     }
 
-
-    public final MetricsKey formatName(String type) {
-        this.name = String.format(name, type);
-        return this;
-    }
-
     public final String getDescription() {
         return this.description;
     }
diff --git 
a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/AggregateMetricsCollector.java
 
b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/AggregateMetricsCollector.java
index c5e0191d7b..664fa371de 100644
--- 
a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/AggregateMetricsCollector.java
+++ 
b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/AggregateMetricsCollector.java
@@ -23,9 +23,9 @@ import org.apache.dubbo.config.context.ConfigManager;
 import org.apache.dubbo.config.nested.AggregationConfig;
 import org.apache.dubbo.metrics.aggregate.TimeWindowCounter;
 import org.apache.dubbo.metrics.aggregate.TimeWindowQuantile;
+import org.apache.dubbo.metrics.event.MethodEvent;
 import org.apache.dubbo.metrics.event.MetricsEvent;
 import org.apache.dubbo.metrics.event.RTEvent;
-import org.apache.dubbo.metrics.event.RequestEvent;
 import org.apache.dubbo.metrics.listener.MetricsListener;
 import org.apache.dubbo.metrics.model.MethodMetric;
 import org.apache.dubbo.metrics.model.MetricsKey;
@@ -39,6 +39,8 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
+import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
 import static org.apache.dubbo.metrics.model.MetricsCategory.QPS;
 import static org.apache.dubbo.metrics.model.MetricsCategory.REQUESTS;
 import static org.apache.dubbo.metrics.model.MetricsCategory.RT;
@@ -50,7 +52,7 @@ import static 
org.apache.dubbo.metrics.model.MetricsCategory.RT;
 public class AggregateMetricsCollector implements MetricsCollector, 
MetricsListener {
     private int bucketNum;
     private int timeWindowSeconds;
-    private final Map<MetricsEvent.Type, ConcurrentHashMap<MethodMetric, 
TimeWindowCounter>> methodTypeCounter = new ConcurrentHashMap<>();
+    private final Map<String, ConcurrentHashMap<MethodMetric, 
TimeWindowCounter>> methodTypeCounter = new ConcurrentHashMap<>();
     private final ConcurrentMap<MethodMetric, TimeWindowQuantile> rt = new 
ConcurrentHashMap<>();
     private final ConcurrentHashMap<MethodMetric, TimeWindowCounter> qps = new 
ConcurrentHashMap<>();
     private final ApplicationModel applicationModel;
@@ -59,7 +61,7 @@ public class AggregateMetricsCollector implements 
MetricsCollector, MetricsListe
     private static final Integer DEFAULT_TIME_WINDOW_SECONDS = 120;
 
     public AggregateMetricsCollector(ApplicationModel applicationModel) {
-        this.registryerEventTypeHandler();
+        this.registryEventTypeHandler();
 
         this.applicationModel = applicationModel;
         ConfigManager configManager = 
applicationModel.getApplicationConfigManager();
@@ -78,8 +80,8 @@ public class AggregateMetricsCollector implements 
MetricsCollector, MetricsListe
     public void onEvent(MetricsEvent event) {
         if (event instanceof RTEvent) {
             onRTEvent((RTEvent) event);
-        } else if (event instanceof RequestEvent) {
-            onRequestEvent((RequestEvent) event);
+        } else if (event instanceof MethodEvent) {
+            onRequestEvent((MethodEvent) event);
         }
     }
 
@@ -91,10 +93,10 @@ public class AggregateMetricsCollector implements 
MetricsCollector, MetricsListe
     }
 
 
-    private void onRequestEvent(RequestEvent event) {
+    private void onRequestEvent(MethodEvent event) {
         MethodMetric metric = (MethodMetric) event.getSource();
 
-        MetricsEvent.Type type = event.getType();
+        String type = event.getType();
 
         ConcurrentMap<MethodMetric, TimeWindowCounter> counter = 
methodTypeCounter.get(type);
 
@@ -103,7 +105,8 @@ public class AggregateMetricsCollector implements 
MetricsCollector, MetricsListe
         }
         TimeWindowCounter windowCounter = 
ConcurrentHashMapUtils.computeIfAbsent(counter, metric, methodMetric -> new 
TimeWindowCounter(bucketNum, timeWindowSeconds));
 
-        if (type == MetricsEvent.Type.TOTAL) {
+        if (MetricsEvent.Type.TOTAL.getNameByType(PROVIDER_SIDE).equals(type)
+            || 
MetricsEvent.Type.TOTAL.getNameByType(CONSUMER_SIDE).equals(type)) {
             TimeWindowCounter qpsCounter = 
ConcurrentHashMapUtils.computeIfAbsent(qps, metric, methodMetric -> new 
TimeWindowCounter(bucketNum, timeWindowSeconds));
             qpsCounter.increment();
         }
@@ -121,47 +124,61 @@ public class AggregateMetricsCollector implements 
MetricsCollector, MetricsListe
     }
 
     private void collectRequests(List<MetricSample> list) {
-        collectMethod(list, MetricsEvent.Type.TOTAL, 
MetricsKey.METRIC_REQUESTS_TOTAL_AGG);
-        collectMethod(list, MetricsEvent.Type.SUCCEED, 
MetricsKey.METRIC_REQUESTS_SUCCEED_AGG);
-        collectMethod(list, MetricsEvent.Type.UNKNOWN_FAILED, 
MetricsKey.METRIC_REQUESTS_FAILED_AGG);
-        collectMethod(list, MetricsEvent.Type.BUSINESS_FAILED, 
MetricsKey.METRIC_REQUESTS_BUSINESS_FAILED_AGG);
-        collectMethod(list, MetricsEvent.Type.REQUEST_TIMEOUT, 
MetricsKey.METRIC_REQUESTS_TIMEOUT_AGG);
-        collectMethod(list, MetricsEvent.Type.REQUEST_LIMIT, 
MetricsKey.METRIC_REQUESTS_LIMIT_AGG);
-        collectMethod(list, MetricsEvent.Type.TOTAL_FAILED, 
MetricsKey.METRIC_REQUESTS_TOTAL_FAILED_AGG);
-        collectMethod(list, MetricsEvent.Type.NETWORK_EXCEPTION, 
MetricsKey.METRIC_REQUESTS_TOTAL_NETWORK_FAILED_AGG);
-        collectMethod(list, MetricsEvent.Type.CODEC_EXCEPTION, 
MetricsKey.METRIC_REQUESTS_TOTAL_CODEC_FAILED_AGG);
-        collectMethod(list, MetricsEvent.Type.SERVICE_UNAVAILABLE, 
MetricsKey.METRIC_REQUESTS_TOTAL_SERVICE_UNAVAILABLE_FAILED_AGG);
+        collectBySide(list, PROVIDER_SIDE);
+        collectBySide(list, CONSUMER_SIDE);
     }
 
-    private void collectMethod(List<MetricSample> list, MetricsEvent.Type 
eventType, MetricsKey metricsKey) {
+    private void collectBySide(List<MetricSample> list, String side) {
+        collectMethod(list, MetricsEvent.Type.TOTAL.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_TOTAL_AGG);
+        collectMethod(list, MetricsEvent.Type.SUCCEED.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_SUCCEED_AGG);
+        collectMethod(list, 
MetricsEvent.Type.UNKNOWN_FAILED.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_FAILED_AGG);
+        collectMethod(list, 
MetricsEvent.Type.BUSINESS_FAILED.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_BUSINESS_FAILED_AGG);
+        collectMethod(list, 
MetricsEvent.Type.REQUEST_TIMEOUT.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_TIMEOUT_AGG);
+        collectMethod(list, 
MetricsEvent.Type.REQUEST_LIMIT.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_LIMIT_AGG);
+        collectMethod(list, 
MetricsEvent.Type.TOTAL_FAILED.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_TOTAL_FAILED_AGG);
+        collectMethod(list, 
MetricsEvent.Type.NETWORK_EXCEPTION.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_TOTAL_NETWORK_FAILED_AGG);
+        collectMethod(list, 
MetricsEvent.Type.CODEC_EXCEPTION.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_TOTAL_CODEC_FAILED_AGG);
+        collectMethod(list, 
MetricsEvent.Type.SERVICE_UNAVAILABLE.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_TOTAL_SERVICE_UNAVAILABLE_FAILED_AGG);
+    }
+
+    private void collectMethod(List<MetricSample> list, String eventType, 
MetricsKey metricsKey) {
         ConcurrentHashMap<MethodMetric, TimeWindowCounter> windowCounter = 
methodTypeCounter.get(eventType);
         if (windowCounter != null) {
-            windowCounter.forEach((k, v) -> list.add(new 
GaugeMetricSample<>(metricsKey.formatName(k.getSide()), k.getTags(), REQUESTS, 
v, TimeWindowCounter::get)));
+            windowCounter.forEach((k, v) -> list.add(new 
GaugeMetricSample<>(metricsKey.getNameByType(k.getSide()),
+                metricsKey.getDescription(), k.getTags(), REQUESTS, v, 
TimeWindowCounter::get)));
         }
     }
 
     private void collectQPS(List<MetricSample> list) {
-        qps.forEach((k, v) -> list.add(new 
GaugeMetricSample<>(MetricsKey.METRIC_QPS.formatName(k.getSide()), k.getTags(), 
QPS, v, value -> value.get() / value.bucketLivedSeconds())));
+        qps.forEach((k, v) -> list.add(new 
GaugeMetricSample<>(MetricsKey.METRIC_QPS.getNameByType(k.getSide()),
+            MetricsKey.METRIC_QPS.getDescription(), k.getTags(), QPS, v, value 
-> value.get() / value.bucketLivedSeconds())));
     }
 
     private void collectRT(List<MetricSample> list) {
         rt.forEach((k, v) -> {
-            list.add(new 
GaugeMetricSample<>(MetricsKey.METRIC_RT_P99.formatName(k.getSide()), 
k.getTags(), RT, v, value -> value.quantile(0.99)));
-            list.add(new 
GaugeMetricSample<>(MetricsKey.METRIC_RT_P95.formatName(k.getSide()), 
k.getTags(), RT, v, value -> value.quantile(0.95)));
+            list.add(new 
GaugeMetricSample<>(MetricsKey.METRIC_RT_P99.getNameByType(k.getSide()),
+                MetricsKey.METRIC_RT_P99.getDescription(), k.getTags(), RT, v, 
value -> value.quantile(0.99)));
+            list.add(new 
GaugeMetricSample<>(MetricsKey.METRIC_RT_P95.getNameByType(k.getSide()),
+                MetricsKey.METRIC_RT_P99.getDescription(), k.getTags(), RT, v, 
value -> value.quantile(0.95)));
         });
     }
 
-    private void registryerEventTypeHandler() {
-        methodTypeCounter.put(MetricsEvent.Type.TOTAL, new 
ConcurrentHashMap<>());
-        methodTypeCounter.put(MetricsEvent.Type.SUCCEED, new 
ConcurrentHashMap<>());
-        methodTypeCounter.put(MetricsEvent.Type.UNKNOWN_FAILED, new 
ConcurrentHashMap<>());
-        methodTypeCounter.put(MetricsEvent.Type.BUSINESS_FAILED, new 
ConcurrentHashMap<>());
-        methodTypeCounter.put(MetricsEvent.Type.REQUEST_TIMEOUT, new 
ConcurrentHashMap<>());
-        methodTypeCounter.put(MetricsEvent.Type.REQUEST_LIMIT, new 
ConcurrentHashMap<>());
-        methodTypeCounter.put(MetricsEvent.Type.TOTAL_FAILED, new 
ConcurrentHashMap<>());
-        methodTypeCounter.put(MetricsEvent.Type.SERVICE_UNAVAILABLE, new 
ConcurrentHashMap<>());
-        methodTypeCounter.put(MetricsEvent.Type.NETWORK_EXCEPTION, new 
ConcurrentHashMap<>());
-        methodTypeCounter.put(MetricsEvent.Type.CODEC_EXCEPTION, new 
ConcurrentHashMap<>());
+    private void registryEventTypeHandler() {
+        registryBySide(PROVIDER_SIDE);
+        registryBySide(CONSUMER_SIDE);
+    }
+
+    private void registryBySide(String side) {
+        methodTypeCounter.put(MetricsEvent.Type.TOTAL.getNameByType(side), new 
ConcurrentHashMap<>());
+        methodTypeCounter.put(MetricsEvent.Type.SUCCEED.getNameByType(side), 
new ConcurrentHashMap<>());
+        
methodTypeCounter.put(MetricsEvent.Type.UNKNOWN_FAILED.getNameByType(side), new 
ConcurrentHashMap<>());
+        
methodTypeCounter.put(MetricsEvent.Type.BUSINESS_FAILED.getNameByType(side), 
new ConcurrentHashMap<>());
+        
methodTypeCounter.put(MetricsEvent.Type.REQUEST_TIMEOUT.getNameByType(side), 
new ConcurrentHashMap<>());
+        
methodTypeCounter.put(MetricsEvent.Type.REQUEST_LIMIT.getNameByType(side), new 
ConcurrentHashMap<>());
+        
methodTypeCounter.put(MetricsEvent.Type.TOTAL_FAILED.getNameByType(side), new 
ConcurrentHashMap<>());
+        
methodTypeCounter.put(MetricsEvent.Type.SERVICE_UNAVAILABLE.getNameByType(side),
 new ConcurrentHashMap<>());
+        
methodTypeCounter.put(MetricsEvent.Type.NETWORK_EXCEPTION.getNameByType(side), 
new ConcurrentHashMap<>());
+        
methodTypeCounter.put(MetricsEvent.Type.CODEC_EXCEPTION.getNameByType(side), 
new ConcurrentHashMap<>());
     }
 
     private void registerListener() {
diff --git 
a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MethodMetricsSampler.java
 
b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MethodMetricsSampler.java
index b5a9af0157..a42f6c5b38 100644
--- 
a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MethodMetricsSampler.java
+++ 
b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MethodMetricsSampler.java
@@ -18,9 +18,9 @@
 package org.apache.dubbo.metrics.collector.sample;
 
 import org.apache.dubbo.metrics.collector.DefaultMetricsCollector;
+import org.apache.dubbo.metrics.event.MethodEvent;
 import org.apache.dubbo.metrics.event.MetricsEvent;
 import org.apache.dubbo.metrics.event.RTEvent;
-import org.apache.dubbo.metrics.event.RequestEvent;
 import org.apache.dubbo.metrics.model.MethodMetric;
 import org.apache.dubbo.metrics.model.Metric;
 import org.apache.dubbo.metrics.model.MetricsCategory;
@@ -34,10 +34,12 @@ import java.util.List;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.function.ToDoubleFunction;
 
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
+import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
 import static org.apache.dubbo.metrics.model.MetricsCategory.REQUESTS;
 import static org.apache.dubbo.metrics.model.MetricsCategory.RT;
 
-public class MethodMetricsSampler extends 
SimpleMetricsCountSampler<Invocation, MetricsEvent.Type, MethodMetric> {
+public class MethodMetricsSampler extends 
SimpleMetricsCountSampler<Invocation, String, MethodMetric> {
 
     private final DefaultMetricsCollector collector;
 
@@ -47,14 +49,15 @@ public class MethodMetricsSampler extends 
SimpleMetricsCountSampler<Invocation,
 
     @Override
     protected void countConfigure(
-        MetricsCountSampleConfigurer<Invocation, MetricsEvent.Type, 
MethodMetric> sampleConfigure) {
+        MetricsCountSampleConfigurer<Invocation, String, MethodMetric> 
sampleConfigure) {
         sampleConfigure.configureMetrics(configure -> new 
MethodMetric(collector.getApplicationName(), configure.getSource()));
-        sampleConfigure.configureEventHandler(configure -> 
collector.getEventMulticaster().publishEvent(new 
RequestEvent(configure.getMetric(), configure.getMetricName())));
+        sampleConfigure.configureEventHandler(configure -> 
collector.getEventMulticaster().publishEvent(new 
MethodEvent(configure.getMetric(),
+            configure.getMetricName())));
     }
 
     @Override
     public void rtConfigure(
-        MetricsCountSampleConfigurer<Invocation, MetricsEvent.Type, 
MethodMetric> sampleConfigure) {
+        MetricsCountSampleConfigurer<Invocation, String, MethodMetric> 
sampleConfigure) {
         sampleConfigure.configureMetrics(configure -> new 
MethodMetric(collector.getApplicationName(), configure.getSource()));
         sampleConfigure.configureEventHandler(configure -> 
collector.getEventMulticaster().publishEvent(new RTEvent(configure.getMetric(), 
configure.getRt())));
     }
@@ -76,17 +79,22 @@ public class MethodMetricsSampler extends 
SimpleMetricsCountSampler<Invocation,
     }
 
     private void collect(List<MetricSample> list) {
-        count(list, MetricsEvent.Type.TOTAL, MetricsKey.METRIC_REQUESTS);
-        count(list, MetricsEvent.Type.SUCCEED, 
MetricsKey.METRIC_REQUESTS_SUCCEED);
-        count(list, MetricsEvent.Type.UNKNOWN_FAILED, 
MetricsKey.METRIC_REQUESTS_FAILED);
-        count(list, MetricsEvent.Type.PROCESSING, 
MetricsKey.METRIC_REQUESTS_PROCESSING);
-        count(list, MetricsEvent.Type.BUSINESS_FAILED, 
MetricsKey.METRIC_REQUEST_BUSINESS_FAILED);
-        count(list, MetricsEvent.Type.REQUEST_TIMEOUT, 
MetricsKey.METRIC_REQUESTS_TIMEOUT);
-        count(list, MetricsEvent.Type.REQUEST_LIMIT, 
MetricsKey.METRIC_REQUESTS_LIMIT);
-        count(list, MetricsEvent.Type.TOTAL_FAILED, 
MetricsKey.METRIC_REQUESTS_TOTAL_FAILED);
-        count(list, MetricsEvent.Type.NETWORK_EXCEPTION, 
MetricsKey.METRIC_REQUESTS_NETWORK_FAILED);
-        count(list, MetricsEvent.Type.SERVICE_UNAVAILABLE, 
MetricsKey.METRIC_REQUESTS_SERVICE_UNAVAILABLE_FAILED);
-        count(list, MetricsEvent.Type.CODEC_EXCEPTION, 
MetricsKey.METRIC_REQUESTS_CODEC_FAILED);
+        collectBySide(list, PROVIDER_SIDE);
+        collectBySide(list, CONSUMER_SIDE);
+    }
+
+    private void collectBySide(List<MetricSample> list, String side) {
+        count(list, MetricsEvent.Type.TOTAL.getNameByType(side), 
MetricsKey.METRIC_REQUESTS);
+        count(list, MetricsEvent.Type.SUCCEED.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_SUCCEED);
+        count(list, MetricsEvent.Type.UNKNOWN_FAILED.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_FAILED);
+        count(list, MetricsEvent.Type.PROCESSING.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_PROCESSING);
+        count(list, MetricsEvent.Type.BUSINESS_FAILED.getNameByType(side), 
MetricsKey.METRIC_REQUEST_BUSINESS_FAILED);
+        count(list, MetricsEvent.Type.REQUEST_TIMEOUT.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_TIMEOUT);
+        count(list, MetricsEvent.Type.REQUEST_LIMIT.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_LIMIT);
+        count(list, MetricsEvent.Type.TOTAL_FAILED.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_TOTAL_FAILED);
+        count(list, MetricsEvent.Type.NETWORK_EXCEPTION.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_NETWORK_FAILED);
+        count(list, MetricsEvent.Type.SERVICE_UNAVAILABLE.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_SERVICE_UNAVAILABLE_FAILED);
+        count(list, MetricsEvent.Type.CODEC_EXCEPTION.getNameByType(side), 
MetricsKey.METRIC_REQUESTS_CODEC_FAILED);
     }
 
 
@@ -104,7 +112,7 @@ public class MethodMetricsSampler extends 
SimpleMetricsCountSampler<Invocation,
             apply);
     }
 
-    private <T extends Metric> void count(List<MetricSample> list, 
MetricsEvent.Type eventType, MetricsKey metricsKey) {
+    private <T extends Metric> void count(List<MetricSample> list, String 
eventType, MetricsKey metricsKey) {
         getCount(eventType).filter(e -> !e.isEmpty())
             .ifPresent(map -> map.forEach((k, v) ->
                 list.add(getGaugeMetricSample(metricsKey, k, REQUESTS, v, 
AtomicLong::get))));
diff --git 
a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/filter/MethodMetricsInterceptor.java
 
b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/filter/MethodMetricsInterceptor.java
index 2394fbe56a..74fd349f7b 100644
--- 
a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/filter/MethodMetricsInterceptor.java
+++ 
b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/filter/MethodMetricsInterceptor.java
@@ -16,11 +16,17 @@
  */
 
 package org.apache.dubbo.metrics.filter;
+
 import org.apache.dubbo.metrics.collector.sample.MethodMetricsSampler;
 import org.apache.dubbo.metrics.event.MetricsEvent;
 import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.Result;
 import org.apache.dubbo.rpc.RpcException;
+
+import java.util.Optional;
+
+import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
 import static 
org.apache.dubbo.common.constants.MetricsConstants.METRIC_FILTER_START_TIME;
 
 public class MethodMetricsInterceptor {
@@ -32,16 +38,23 @@ public class MethodMetricsInterceptor {
     }
 
     public void beforeMethod(Invocation invocation) {
-        sampler.incOnEvent(invocation, MetricsEvent.Type.TOTAL);
-        sampler.incOnEvent(invocation,MetricsEvent.Type.PROCESSING);
+        String side = getSide(invocation);
+        sampler.incOnEvent(invocation, 
MetricsEvent.Type.TOTAL.getNameByType(side));
+        sampler.incOnEvent(invocation, 
MetricsEvent.Type.PROCESSING.getNameByType(side));
         invocation.put(METRIC_FILTER_START_TIME, System.currentTimeMillis());
     }
 
+    private String getSide(Invocation invocation) {
+        Optional<? extends Invoker<?>> invoker = 
Optional.ofNullable(invocation.getInvoker());
+        String side = invoker.isPresent() ? invoker.get().getUrl().getSide() : 
PROVIDER_SIDE;
+        return side;
+    }
+
     public void afterMethod(Invocation invocation, Result result) {
         if (result.hasException()) {
             handleMethodException(invocation, result.getException());
-        }else{
-            sampler.incOnEvent(invocation,MetricsEvent.Type.SUCCEED);
+        } else {
+            sampler.incOnEvent(invocation, 
MetricsEvent.Type.SUCCEED.getNameByType(getSide(invocation)));
             onCompleted(invocation);
         }
     }
@@ -50,7 +63,7 @@ public class MethodMetricsInterceptor {
         if (throwable == null) {
             return;
         }
-
+        String side = getSide(invocation);
         if (throwable instanceof RpcException) {
             RpcException e = (RpcException) throwable;
 
@@ -71,7 +84,7 @@ public class MethodMetricsInterceptor {
             if (e.isNetwork()) {
                 eventType = MetricsEvent.Type.NETWORK_EXCEPTION;
             }
-            sampler.incOnEvent(invocation,eventType);
+            sampler.incOnEvent(invocation, eventType.getNameByType(side));
         }
 
         if (throwable instanceof RpcException && ((RpcException) 
throwable).isBiz()) {
@@ -80,7 +93,7 @@ public class MethodMetricsInterceptor {
             rtTime(invocation);
         }
 
-        sampler.incOnEvent(invocation,MetricsEvent.Type.TOTAL_FAILED);
+        sampler.incOnEvent(invocation, 
MetricsEvent.Type.TOTAL_FAILED.getNameByType(side));
     }
 
     private void rtTime(Invocation invocation){
@@ -92,6 +105,6 @@ public class MethodMetricsInterceptor {
 
     private void onCompleted(Invocation invocation) {
         rtTime(invocation);
-        sampler.dec(invocation,MetricsEvent.Type.PROCESSING);
+        sampler.dec(invocation, 
MetricsEvent.Type.PROCESSING.getNameByType(getSide(invocation)));
     }
 }
diff --git 
a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/filter/MetricsClusterFilter.java
 
b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/filter/MetricsClusterFilter.java
index 114b191fa0..4fa30ee0b2 100644
--- 
a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/filter/MetricsClusterFilter.java
+++ 
b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/filter/MetricsClusterFilter.java
@@ -16,6 +16,7 @@
  */
 
 package org.apache.dubbo.metrics.filter;
+
 import org.apache.dubbo.common.extension.Activate;
 import org.apache.dubbo.metrics.collector.DefaultMetricsCollector;
 import org.apache.dubbo.metrics.event.MetricsEvent;
@@ -27,7 +28,11 @@ import org.apache.dubbo.rpc.RpcException;
 import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
 import org.apache.dubbo.rpc.model.ApplicationModel;
 import org.apache.dubbo.rpc.model.ScopeModelAware;
+
+import java.util.Optional;
+
 import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
 
 @Activate(group = CONSUMER)
 public class MetricsClusterFilter implements ClusterFilter, 
BaseFilter.Listener, ScopeModelAware {
@@ -61,8 +66,15 @@ public class MetricsClusterFilter implements ClusterFilter, 
BaseFilter.Listener,
         if (t != null && t instanceof RpcException) {
             RpcException e = (RpcException) t;
             if (e.isForbidden()) {
-                collector.getMethodSampler().incOnEvent(invocation, 
MetricsEvent.Type.SERVICE_UNAVAILABLE);
+                collector.getMethodSampler().incOnEvent(invocation,
+                    
MetricsEvent.Type.SERVICE_UNAVAILABLE.getNameByType(getSide(invocation)));
             }
         }
     }
+
+    private String getSide(Invocation invocation) {
+        Optional<? extends Invoker<?>> invoker = 
Optional.ofNullable(invocation.getInvoker());
+        String side = invoker.isPresent() ? invoker.get().getUrl().getSide() : 
PROVIDER_SIDE;
+        return side;
+    }
 }
diff --git 
a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/collector/AggregateMetricsCollectorTest.java
 
b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/collector/AggregateMetricsCollectorTest.java
index c4232f0039..6514aa0d9c 100644
--- 
a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/collector/AggregateMetricsCollectorTest.java
+++ 
b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/collector/AggregateMetricsCollectorTest.java
@@ -41,8 +41,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
-import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.*;
 import static org.apache.dubbo.common.constants.MetricsConstants.TAG_GROUP_KEY;
 import static 
org.apache.dubbo.common.constants.MetricsConstants.TAG_INTERFACE_KEY;
 import static 
org.apache.dubbo.common.constants.MetricsConstants.TAG_METHOD_KEY;
@@ -106,13 +105,13 @@ class AggregateMetricsCollectorTest {
         defaultCollector.setApplicationName(applicationName);
         MethodMetricsSampler methodMetricsCountSampler = 
defaultCollector.getMethodSampler();
 
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.TOTAL);
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.SUCCEED);
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.UNKNOWN_FAILED);
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.BUSINESS_FAILED);
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.NETWORK_EXCEPTION);
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.SERVICE_UNAVAILABLE);
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.CODEC_EXCEPTION);
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.TOTAL.getNameByType(side));
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.SUCCEED.getNameByType(side));
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.UNKNOWN_FAILED.getNameByType(side));
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.BUSINESS_FAILED.getNameByType(side));
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.NETWORK_EXCEPTION.getNameByType(side));
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.SERVICE_UNAVAILABLE.getNameByType(side));
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.CODEC_EXCEPTION.getNameByType(side));
 
 
         List<MetricSample> samples = collector.collect();
diff --git 
a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/filter/MetricsFilterTest.java
 
b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/filter/MetricsFilterTest.java
index 0dcf43c04b..a50fd29dc6 100644
--- 
a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/filter/MetricsFilterTest.java
+++ 
b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/filter/MetricsFilterTest.java
@@ -50,6 +50,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.function.Function;
 import java.util.stream.Collectors;
+
 import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE;
 import static 
org.apache.dubbo.common.constants.CommonConstants.GENERIC_PARAMETER_DESC;
 import static org.apache.dubbo.common.constants.MetricsConstants.TAG_GROUP_KEY;
@@ -90,7 +91,7 @@ class MetricsFilterTest {
         filter = new MetricsFilter();
 
         collector = 
applicationModel.getBeanFactory().getOrRegisterBean(DefaultMetricsCollector.class);
-        if(!initApplication.get()) {
+        if (!initApplication.get()) {
             collector.collectApplication(applicationModel);
             initApplication.set(true);
         }
@@ -273,18 +274,20 @@ class MetricsFilterTest {
     }
 
     @Test
-    public void testErrors(){
-        testFilterError(RpcException.SERIALIZATION_EXCEPTION, 
MetricsKey.METRIC_REQUESTS_CODEC_FAILED.formatName(side));
-        testFilterError(RpcException.NETWORK_EXCEPTION, 
MetricsKey.METRIC_REQUESTS_NETWORK_FAILED.formatName(side));
+    public void testErrors() {
+        testFilterError(RpcException.SERIALIZATION_EXCEPTION,
+            MetricsKey.METRIC_REQUESTS_CODEC_FAILED.getNameByType(side));
+        testFilterError(RpcException.NETWORK_EXCEPTION,
+            MetricsKey.METRIC_REQUESTS_NETWORK_FAILED.getNameByType(side));
     }
 
     @Test
-    public void testNoProvider(){
+    public void testNoProvider() {
         testClusterFilterError(RpcException.FORBIDDEN_EXCEPTION,
-            
MetricsKey.METRIC_REQUESTS_SERVICE_UNAVAILABLE_FAILED.formatName(CommonConstants.CONSUMER));
+            
MetricsKey.METRIC_REQUESTS_SERVICE_UNAVAILABLE_FAILED.getNameByType(CommonConstants.CONSUMER));
     }
 
-    private void testClusterFilterError(int errorCode,MetricsKey metricsKey){
+    private void testClusterFilterError(int errorCode, String name) {
 //        setup();
         collector.setCollectEnabled(true);
         given(invoker.invoke(invocation)).willThrow(new 
RpcException(errorCode));
@@ -301,15 +304,15 @@ class MetricsFilterTest {
             }
         }
         Map<String, MetricSample> metricsMap = getMetricsMap();
-        Assertions.assertTrue(metricsMap.containsKey(metricsKey.getName()));
+        Assertions.assertTrue(metricsMap.containsKey(name));
 
-        MetricSample sample = metricsMap.get(metricsKey.getName());
+        MetricSample sample = metricsMap.get(name);
 
         Assertions.assertSame(((GaugeMetricSample) sample).applyAsLong(), 
count);
         teardown();
     }
 
-    private void testFilterError(int errorCode,MetricsKey metricsKey){
+    private void testFilterError(int errorCode, String name) {
         setup();
         collector.setCollectEnabled(true);
         given(invoker.invoke(invocation)).willThrow(new 
RpcException(errorCode));
@@ -326,14 +329,14 @@ class MetricsFilterTest {
             }
         }
         Map<String, MetricSample> metricsMap = getMetricsMap();
-        Assertions.assertTrue(metricsMap.containsKey(metricsKey.getName()));
+        Assertions.assertTrue(metricsMap.containsKey(name));
 
-        MetricSample sample = metricsMap.get(metricsKey.getName());
+        MetricSample sample = metricsMap.get(name);
 
         Assertions.assertSame(((GaugeMetricSample) sample).applyAsLong(), 
count);
 
 
-        Assertions.assertTrue(metricsMap.containsKey(metricsKey.getName()));
+        Assertions.assertTrue(metricsMap.containsKey(name));
         Map<String, String> tags = sample.getTags();
 
         Assertions.assertEquals(tags.get(TAG_INTERFACE_KEY), INTERFACE_NAME);
diff --git 
a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/metrics/collector/DefaultMetricsCollectorTest.java
 
b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/metrics/collector/DefaultMetricsCollectorTest.java
index 7a1d238b3f..7affb9ae8b 100644
--- 
a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/metrics/collector/DefaultMetricsCollectorTest.java
+++ 
b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/metrics/collector/DefaultMetricsCollectorTest.java
@@ -23,9 +23,9 @@ import org.apache.dubbo.config.ApplicationConfig;
 import org.apache.dubbo.metrics.TestMetricsInvoker;
 import org.apache.dubbo.metrics.collector.DefaultMetricsCollector;
 import org.apache.dubbo.metrics.collector.sample.MethodMetricsSampler;
+import org.apache.dubbo.metrics.event.MethodEvent;
 import org.apache.dubbo.metrics.event.MetricsEvent;
 import org.apache.dubbo.metrics.event.RTEvent;
-import org.apache.dubbo.metrics.event.RequestEvent;
 import org.apache.dubbo.metrics.listener.MetricsListener;
 import org.apache.dubbo.metrics.model.MetricsKey;
 import org.apache.dubbo.metrics.model.sample.GaugeMetricSample;
@@ -44,8 +44,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
-import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.*;
 import static org.apache.dubbo.common.constants.MetricsConstants.TAG_GROUP_KEY;
 import static 
org.apache.dubbo.common.constants.MetricsConstants.TAG_INTERFACE_KEY;
 import static 
org.apache.dubbo.common.constants.MetricsConstants.TAG_METHOD_KEY;
@@ -101,10 +100,10 @@ class DefaultMetricsCollectorTest {
 
         MethodMetricsSampler methodMetricsCountSampler = 
collector.getMethodSampler();
 
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.TOTAL);
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.PROCESSING);
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.SUCCEED);
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.UNKNOWN_FAILED);
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.TOTAL.getNameByType(side));
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.PROCESSING.getNameByType(side));
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.SUCCEED.getNameByType(side));
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.UNKNOWN_FAILED.getNameByType(side));
 
         List<MetricSample> samples = collector.collect();
         for (MetricSample sample : samples) {
@@ -119,7 +118,7 @@ class DefaultMetricsCollectorTest {
             Assertions.assertEquals(gaugeSample.applyAsLong(), 1);
         }
 
-        methodMetricsCountSampler.dec(invocation, 
MetricsEvent.Type.PROCESSING);
+        methodMetricsCountSampler.dec(invocation, 
MetricsEvent.Type.PROCESSING.getNameByType(side));
         samples = collector.collect();
 
         Map<String, Long> sampleMap = 
samples.stream().collect(Collectors.toMap(MetricSample::getName, k -> 
((GaugeMetricSample) k).applyAsLong()));
@@ -169,10 +168,11 @@ class DefaultMetricsCollectorTest {
         collector.addListener(mockListener);
         collector.setApplicationName(applicationModel.getApplicationName());
 
-        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.TOTAL);
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.TOTAL.getNameByType(side));
         Assertions.assertNotNull(mockListener.getCurEvent());
-        Assertions.assertTrue(mockListener.getCurEvent() instanceof 
RequestEvent);
-        Assertions.assertEquals(((RequestEvent) 
mockListener.getCurEvent()).getType(), MetricsEvent.Type.TOTAL);
+        Assertions.assertTrue(mockListener.getCurEvent() instanceof 
MethodEvent);
+        Assertions.assertEquals(((MethodEvent) 
mockListener.getCurEvent()).getType(),
+            MetricsEvent.Type.TOTAL.getNameByType(side));
 
         methodMetricsCountSampler.addRT(invocation, 5L);
         Assertions.assertTrue(mockListener.getCurEvent() instanceof RTEvent);
diff --git 
a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/sampler/CountSamplerTest.java
 
b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/sampler/CountSamplerTest.java
index ff3b6c0714..ed9cbca73b 100644
--- 
a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/sampler/CountSamplerTest.java
+++ 
b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/sampler/CountSamplerTest.java
@@ -39,6 +39,7 @@ import java.util.stream.Collectors;
 import static org.apache.dubbo.metrics.model.MetricsCategory.RT;
 
 public class CountSamplerTest {
+    String side = "consumer";
 
     public RequestMetricsCountSampler sampler = new 
RequestMetricsCountSampler();
 
@@ -57,59 +58,54 @@ public class CountSamplerTest {
 
         Assertions.assertNotNull(collect);
 
-        Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_LAST.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_LAST.getName()).applyAsLong() == 2);
-        Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_MIN.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_MIN.getName()).applyAsLong() == 2);
-        Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_MAX.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_MAX.getName()).applyAsLong() == 2);
-        Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_AVG.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_AVG.getName()).applyAsLong() == 2);
-        Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_SUM.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_SUM.getName()).applyAsLong() == 2);
+        Assertions.assertTrue(null != 
collect.get(MetricsKey.METRIC_RT_LAST.getNameByType(side)) && collect.get(
+                MetricsKey.METRIC_RT_LAST.getNameByType(side)).applyAsLong() 
== 2);
+        Assertions.assertTrue(null != 
collect.get(MetricsKey.METRIC_RT_MIN.getNameByType(side)) && collect.get(
+                MetricsKey.METRIC_RT_MIN.getNameByType(side)).applyAsLong() == 
2);
+        Assertions.assertTrue(null != 
collect.get(MetricsKey.METRIC_RT_MAX.getNameByType(side)) && collect.get(
+                MetricsKey.METRIC_RT_MAX.getNameByType(side)).applyAsLong() == 
2);
+        Assertions.assertTrue(null != 
collect.get(MetricsKey.METRIC_RT_AVG.getNameByType(side)) && collect.get(
+                MetricsKey.METRIC_RT_AVG.getNameByType(side)).applyAsLong() == 
2);
+        Assertions.assertTrue(null != 
collect.get(MetricsKey.METRIC_RT_SUM.getNameByType(side)) && collect.get(
+                MetricsKey.METRIC_RT_SUM.getNameByType(side)).applyAsLong() == 
2);
 
         sampler.addRT(applicationName, RTType.METHOD_REQUEST, 1L);
         collect = getCollect(RTType.METHOD_REQUEST);
 
         Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_LAST.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_LAST.getName()).applyAsLong() == 1);
+            null != collect.get(MetricsKey.METRIC_RT_LAST.getNameByType(side)) 
&& collect.get(
+                MetricsKey.METRIC_RT_LAST.getNameByType(side)).applyAsLong() 
== 1);
         Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_MIN.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_MIN.getName()).applyAsLong() == 1);
+            null != collect.get(MetricsKey.METRIC_RT_MIN.getNameByType(side)) 
&& collect.get(
+                MetricsKey.METRIC_RT_MIN.getNameByType(side)).applyAsLong() == 
1);
         Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_MAX.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_MAX.getName()).applyAsLong() == 2);
+            null != collect.get(MetricsKey.METRIC_RT_MAX.getNameByType(side)) 
&& collect.get(
+                MetricsKey.METRIC_RT_MAX.getNameByType(side)).applyAsLong() == 
2);
         Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_AVG.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_AVG.getName()).applyAsLong() == 1);
+            null != collect.get(MetricsKey.METRIC_RT_AVG.getNameByType(side)) 
&& collect.get(
+                MetricsKey.METRIC_RT_AVG.getNameByType(side)).applyAsLong() == 
1);
         Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_SUM.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_SUM.getName()).applyAsLong() == 3);
+            null != collect.get(MetricsKey.METRIC_RT_SUM.getNameByType(side)) 
&& collect.get(
+                MetricsKey.METRIC_RT_SUM.getNameByType(side)).applyAsLong() == 
3);
 
         sampler.addRT(applicationName, RTType.APPLICATION, 4L);
         collect = getCollect(RTType.APPLICATION);
 
         Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_LAST.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_LAST.getName()).applyAsLong() == 4);
+            null != collect.get(MetricsKey.METRIC_RT_LAST.getNameByType(side)) 
&& collect.get(
+                MetricsKey.METRIC_RT_LAST.getNameByType(side)).applyAsLong() 
== 4);
         Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_MIN.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_MIN.getName()).applyAsLong() == 4);
+            null != collect.get(MetricsKey.METRIC_RT_MIN.getNameByType(side)) 
&& collect.get(
+                MetricsKey.METRIC_RT_MIN.getNameByType(side)).applyAsLong() == 
4);
         Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_MAX.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_MAX.getName()).applyAsLong() == 4);
+            null != collect.get(MetricsKey.METRIC_RT_MAX.getNameByType(side)) 
&& collect.get(
+                MetricsKey.METRIC_RT_MAX.getNameByType(side)).applyAsLong() == 
4);
         Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_AVG.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_AVG.getName()).applyAsLong() == 4);
+            null != collect.get(MetricsKey.METRIC_RT_AVG.getNameByType(side)) 
&& collect.get(
+                MetricsKey.METRIC_RT_AVG.getNameByType(side)).applyAsLong() == 
4);
         Assertions.assertTrue(
-            null != collect.get(MetricsKey.METRIC_RT_SUM.getName()) && 
collect.get(
-                MetricsKey.METRIC_RT_SUM.getName()).applyAsLong() == 4);
+            null != collect.get(MetricsKey.METRIC_RT_SUM.getNameByType(side)) 
&& collect.get(
+                MetricsKey.METRIC_RT_SUM.getNameByType(side)).applyAsLong() == 
4);
     }
 
     @SuppressWarnings("rawtypes")
@@ -118,7 +114,8 @@ public class CountSamplerTest {
             new MetricsCountSampler.MetricSampleFactory<RequestMethodMetrics, 
GaugeMetricSample<?>>() {
                 @Override
                 public <T> GaugeMetricSample<?> newInstance(MetricsKey key, 
RequestMethodMetrics metric, T value, ToDoubleFunction<T> apply) {
-                    return new GaugeMetricSample<>(key.formatName("consumer"), 
metric.getTags(), RT, value, apply);
+                    return new GaugeMetricSample<>(key.getNameByType(side), 
key.getDescription(),
+                        metric.getTags(), RT, value, apply);
                 }
             }, rtType);
 


Reply via email to