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 8b323cd762 Collect No Provider Request count  (#12158)
8b323cd762 is described below

commit 8b323cd762acec8c9d1aa80a4ef07bb3bff90541
Author: MartinDai <[email protected]>
AuthorDate: Tue Apr 25 14:11:17 2023 +0800

    Collect No Provider Request count  (#12158)
    
    * Collect No Provider Request count as 
dubbo.consumer.invoker.no.available.count Metrics
    
    * ensure dubbo.consumer.invoker.no.available.count Metrics only collect in 
consumer side
    
    ---------
    
    Co-authored-by: daming <[email protected]>
---
 .../src/main/java/org/apache/dubbo/metrics/event/MetricsEvent.java    | 1 +
 .../src/main/java/org/apache/dubbo/metrics/model/key/MetricsKey.java  | 1 +
 .../org/apache/dubbo/metrics/collector/AggregateMetricsCollector.java | 2 ++
 .../org/apache/dubbo/metrics/filter/MethodMetricsInterceptor.java     | 4 ++++
 .../apache/dubbo/metrics/collector/AggregateMetricsCollectorTest.java | 2 ++
 5 files changed, 10 insertions(+)

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 26396c8acd..490e36df2c 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
@@ -103,6 +103,7 @@ public abstract class MetricsEvent {
         NETWORK_EXCEPTION("NETWORK_EXCEPTION_%s"),
         SERVICE_UNAVAILABLE("SERVICE_UNAVAILABLE_%s"),
         CODEC_EXCEPTION("CODEC_EXCEPTION_%s"),
+        NO_INVOKER_AVAILABLE("NO_INVOKER_AVAILABLE_%s"),
         ;
 
         private final String name;
diff --git 
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/key/MetricsKey.java
 
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/key/MetricsKey.java
index 0d993bb4cd..b142365fad 100644
--- 
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/key/MetricsKey.java
+++ 
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/key/MetricsKey.java
@@ -118,6 +118,7 @@ public enum MetricsKey {
     METADATA_GIT_COMMITID_METRIC("git.commit.id", "Git Commit Id Metrics"),
 
     // consumer metrics key
+    INVOKER_NO_AVAILABLE_COUNT("dubbo.consumer.invoker.no.available.count", 
"Request Throw No Invoker Available Exception Count"),
     ;
 
     private String name;
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 286fa1dcd0..fad110a90a 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
@@ -139,6 +139,7 @@ public class AggregateMetricsCollector implements 
MetricsCollector, MetricsListe
         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);
+        collectMethod(list, 
MetricsEvent.Type.NO_INVOKER_AVAILABLE.getNameByType(side), 
MetricsKey.INVOKER_NO_AVAILABLE_COUNT);
     }
 
     private void collectMethod(List<MetricSample> list, String eventType, 
MetricsKey metricsKey) {
@@ -179,6 +180,7 @@ public class AggregateMetricsCollector implements 
MetricsCollector, MetricsListe
         
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<>());
+        
methodTypeCounter.put(MetricsEvent.Type.NO_INVOKER_AVAILABLE.getNameByType(side),
 new ConcurrentHashMap<>());
     }
 
     private void registerListener() {
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 98620ccb7a..21da540c1e 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
@@ -17,6 +17,7 @@
 
 package org.apache.dubbo.metrics.filter;
 
+import org.apache.dubbo.common.constants.CommonConstants;
 import org.apache.dubbo.metrics.collector.sample.MethodMetricsSampler;
 import org.apache.dubbo.metrics.event.MetricsEvent;
 import org.apache.dubbo.rpc.Invocation;
@@ -85,6 +86,9 @@ public class MethodMetricsInterceptor {
             if (e.isNetwork()) {
                 eventType = MetricsEvent.Type.NETWORK_EXCEPTION;
             }
+            if (e.isNoInvokerAvailableAfterFilter() && 
CommonConstants.CONSUMER_SIDE.equals(side)) {
+                eventType = MetricsEvent.Type.NO_INVOKER_AVAILABLE;
+            }
         }
 
         sampler.incOnEvent(invocation, eventType.getNameByType(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 7bc56579b6..d4fbd1e571 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
@@ -156,6 +156,7 @@ class AggregateMetricsCollectorTest {
         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));
+        methodMetricsCountSampler.incOnEvent(invocation, 
MetricsEvent.Type.NO_INVOKER_AVAILABLE.getNameByType(side));
 
 
         List<MetricSample> samples = collector.collect();
@@ -181,6 +182,7 @@ class AggregateMetricsCollectorTest {
         
Assertions.assertEquals(sampleMap.get(MetricsKey.METRIC_REQUESTS_TOTAL_NETWORK_FAILED_AGG.getNameByType(side)),
 1L);
         
Assertions.assertEquals(sampleMap.get(MetricsKey.METRIC_REQUESTS_TOTAL_CODEC_FAILED_AGG.getNameByType(side)),
 1L);
         
Assertions.assertEquals(sampleMap.get(MetricsKey.METRIC_REQUESTS_TOTAL_SERVICE_UNAVAILABLE_FAILED_AGG.getNameByType(side)),
 1L);
+        
Assertions.assertEquals(sampleMap.get(MetricsKey.INVOKER_NO_AVAILABLE_COUNT.getNameByType(side)),
 1L);
 
         
Assertions.assertTrue(sampleMap.containsKey(MetricsKey.METRIC_QPS.getNameByType(side)));
     }

Reply via email to