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

zhangliang 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 867f4446295 optimize routed_data_sources_total and routed_tables_total 
metrics (#23662)
867f4446295 is described below

commit 867f44462957f1b147dd44d5d91a50b3fece7690
Author: jiangML <[email protected]>
AuthorDate: Thu Jan 19 23:37:49 2023 +0800

    optimize routed_data_sources_total and routed_tables_total metrics (#23662)
    
    * add routed_result_total metric
    
    * update doc
    
    * add todo
    
    Co-authored-by: Liang Zhang <[email protected]>
---
 .../metrics/core/advice/RouteResultCountAdvice.java    | 13 +++++--------
 .../metrics/core/config/MetricConfiguration.java       |  9 +++++++++
 .../core/advice/RouteResultCountAdviceTest.java        | 18 +++++++-----------
 .../shardingsphere-proxy/observability/_index.cn.md    |  3 +--
 .../shardingsphere-proxy/observability/_index.en.md    |  3 +--
 .../test/e2e/agent/metrics/MetricsPluginE2EIT.java     |  3 +--
 6 files changed, 24 insertions(+), 25 deletions(-)

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 9ea89c66f9a..85d722cbd71 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
@@ -28,18 +28,15 @@ import 
org.apache.shardingsphere.infra.route.context.RouteMapper;
 import org.apache.shardingsphere.infra.route.context.RouteUnit;
 
 import java.lang.reflect.Method;
-import java.util.Collections;
+import java.util.Arrays;
 
 /**
  * Route result count advice.
  */
 public final class RouteResultCountAdvice implements InstanceMethodAdvice {
     
-    private final MetricConfiguration routedDataSourcesConfig = new 
MetricConfiguration("routed_data_sources_total",
-            MetricCollectorType.COUNTER, "Total count of data source routed", 
Collections.singletonList("name"), Collections.emptyMap());
-    
-    private final MetricConfiguration routedTablesConfig = new 
MetricConfiguration("routed_tables_total",
-            MetricCollectorType.COUNTER, "Total count of table routed", 
Collections.singletonList("name"), Collections.emptyMap());
+    private final MetricConfiguration routedResultConfig = new 
MetricConfiguration("routed_result_total",
+            MetricCollectorType.COUNTER, "Total count of routed result", 
Arrays.asList("object", "name"));
     
     @Override
     public void afterMethod(final TargetAdviceObject target, final Method 
method, final Object[] args, final Object result, final String pluginType) {
@@ -48,8 +45,8 @@ public final class RouteResultCountAdvice implements 
InstanceMethodAdvice {
         }
         for (RouteUnit each : ((RouteContext) result).getRouteUnits()) {
             RouteMapper dataSourceMapper = each.getDataSourceMapper();
-            
MetricsCollectorRegistry.<CounterMetricsCollector>get(routedDataSourcesConfig, 
pluginType).inc(dataSourceMapper.getActualName());
-            each.getTableMappers().forEach(table -> 
MetricsCollectorRegistry.<CounterMetricsCollector>get(routedTablesConfig, 
pluginType).inc(table.getActualName()));
+            
MetricsCollectorRegistry.<CounterMetricsCollector>get(routedResultConfig, 
pluginType).inc("data_source", dataSourceMapper.getActualName());
+            each.getTableMappers().forEach(table -> 
MetricsCollectorRegistry.<CounterMetricsCollector>get(routedResultConfig, 
pluginType).inc("table", table.getActualName()));
         }
     }
 }
diff --git 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricConfiguration.java
 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricConfiguration.java
index 16dc85d0f28..81ddb3b8cd0 100644
--- 
a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricConfiguration.java
+++ 
b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/config/MetricConfiguration.java
@@ -20,6 +20,7 @@ package 
org.apache.shardingsphere.agent.plugin.metrics.core.config;
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -39,4 +40,12 @@ public final class MetricConfiguration {
     private final List<String> labels;
     
     private final Map<String, Object> props;
+    
+    public MetricConfiguration(final String id, final MetricCollectorType 
type, final String help) {
+        this(id, type, help, Collections.emptyList(), Collections.emptyMap());
+    }
+    
+    public MetricConfiguration(final String id, final MetricCollectorType 
type, final String help, final List<String> labels) {
+        this(id, type, help, labels, Collections.emptyMap());
+    }
 }
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 030b7eb90e5..33c230fb4da 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
@@ -29,6 +29,7 @@ import org.junit.After;
 import org.junit.Test;
 
 import java.lang.reflect.Method;
+import java.util.Arrays;
 import java.util.Collections;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -37,16 +38,12 @@ import static org.mockito.Mockito.mock;
 
 public final class RouteResultCountAdviceTest {
     
-    private final MetricConfiguration routedDataSourcesConfig = new 
MetricConfiguration("routed_data_sources_total",
-            MetricCollectorType.COUNTER, null, 
Collections.singletonList("name"), Collections.emptyMap());
-    
-    private final MetricConfiguration routedTablesConfig = new 
MetricConfiguration("routed_tables_total",
-            MetricCollectorType.COUNTER, null, 
Collections.singletonList("name"), Collections.emptyMap());
+    private final MetricConfiguration routedResultConfig = new 
MetricConfiguration("routed_result_total",
+            MetricCollectorType.COUNTER, null, Arrays.asList("object", 
"name"));
     
     @After
     public void reset() {
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(routedDataSourcesConfig, "FIXTURE")).reset();
-        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(routedTablesConfig, "FIXTURE")).reset();
+        ((MetricsCollectorFixture) 
MetricsCollectorRegistry.get(routedResultConfig, "FIXTURE")).reset();
     }
     
     @Test
@@ -56,9 +53,8 @@ public final class RouteResultCountAdviceTest {
         RouteMapper tableMapper = new RouteMapper("t_order", "t_order_0");
         routeContext.getRouteUnits().add(new RouteUnit(dataSourceMapper, 
Collections.singleton(tableMapper)));
         new RouteResultCountAdvice().afterMethod(new 
TargetAdviceObjectFixture(), mock(Method.class), new Object[]{}, routeContext, 
"FIXTURE");
-        MetricsCollectorFixture wrapper = 
MetricsCollectorRegistry.get(routedDataSourcesConfig, "FIXTURE");
-        assertThat(wrapper.getValue(), is(1d));
-        wrapper = MetricsCollectorRegistry.get(routedTablesConfig, "FIXTURE");
-        assertThat(wrapper.getValue(), is(1d));
+        MetricsCollectorFixture wrapper = 
MetricsCollectorRegistry.get(routedResultConfig, "FIXTURE");
+        // TODO assert by specific label
+        assertThat(wrapper.getValue(), is(2d));
     }
 }
diff --git 
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
 
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
index bd3c659197d..7939fb5b995 100644
--- 
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
+++ 
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.cn.md
@@ -159,8 +159,7 @@ services:
 | build_info                        | GAUGE_METRIC_FAMILY | 构建信息               
                                                                 |
 | parsed_sql_total                  | COUNTER             | 
按类型(INSERT、UPDATE、DELETE、SELECT、DDL、DCL、DAL、TCL、RQL、RDL、RAL、RUL)分类的解析总数 |
 | routed_sql_total                  | COUNTER             | 
按类型(INSERT、UPDATE、DELETE、SELECT)分类的路由总数                                      |
-| routed_data_sources_total         | COUNTER             | 数据源路由总数            
                                                               |
-| routed_tables_total               | COUNTER             | 表路由总数              
                                                                |
+| routed_result_total               | COUNTER             | 
路由结果总数(数据源路由结果、表路由结果)                                                    |
 | proxy_state                       | GAUGE_METRIC_FAMILY | 
ShardingSphere-Proxy 状态信息。0 表示正常状态;1 表示熔断状态;2 锁定状态                      |
 | proxy_meta_data_info              | GAUGE_METRIC_FAMILY | 
ShardingSphere-Proxy 元数据信息,schema_count:逻辑库数量, database_count:数据源数量        |
 | proxy_current_connections         | GAUGE               | 
ShardingSphere-Proxy 的当前连接数                                                     
   |
diff --git 
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
 
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
index b44cef31be4..13d7561d5d5 100644
--- 
a/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
+++ 
b/docs/document/content/user-manual/shardingsphere-proxy/observability/_index.en.md
@@ -162,8 +162,7 @@ services:
 | build_info                        | GAUGE_METRIC_FAMILY | Build information  
                                                                                
                                    |
 | parsed_sql_total                  | COUNTER             | Total count of 
parsed by type (INSERT, UPDATE, DELETE, SELECT, DDL, DCL, DAL, TCL, RQL, RDL, 
RAL, RUL)                                 |
 | routed_sql_total                  | COUNTER             | Total count of 
routed by type (INSERT, UPDATE, DELETE, SELECT)                                 
                                        |
-| routed_data_sources_total         | COUNTER             | Total count of 
data source routed                                                              
                                        |
-| routed_tables_total               | COUNTER             | Total count of 
table routed                                                                    
                                        |
+| routed_result_total               | COUNTER             | Total count of 
routed result. (data source routed, table routed)                               
                                        |
 | proxy_state                       | GAUGE_METRIC_FAMILY | Status information 
of ShardingSphere-Proxy. 0 is OK; 1 is CIRCUIT BREAK; 2 is LOCK                 
                                    |
 | proxy_meta_data_info              | GAUGE_METRIC_FAMILY | Meta data 
information of ShardingSphere-Proxy. schema_count is logic number of databases; 
database_count is actual number of databases |
 | proxy_current_connections         | GAUGE               | Current 
connections of ShardingSphere-Proxy                                             
                                               |
diff --git 
a/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
 
b/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
index 6064fa6b0fc..5967165271d 100644
--- 
a/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
+++ 
b/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
@@ -67,8 +67,7 @@ public final class MetricsPluginE2EIT extends BasePluginE2EIT 
{
         result.add("proxy_current_connections");
         result.add("proxy_execute_latency_millis_bucket");
         result.add("routed_sql_total");
-        result.add("routed_data_sources_total");
-        result.add("routed_tables_total");
+        result.add("routed_result_total");
         result.add("proxy_commit_transactions_total");
         result.add("proxy_rollback_transactions_total");
         result.add("proxy_execute_errors_total");

Reply via email to