You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/12/19 09:53:01 UTC

[shardingsphere] branch master updated: Refactor advisors.yaml's type enum (#22973)

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

panjuan 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 5059c8f0f5a Refactor advisors.yaml's type enum (#22973)
5059c8f0f5a is described below

commit 5059c8f0f5a1949db669f200347c379854c9e8aa
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Dec 19 17:52:52 2022 +0800

    Refactor advisors.yaml's type enum (#22973)
---
 .../yaml/swapper/YamlAdvisorConfigurationSwapper.java  | 10 +++-------
 .../swapper/YamlAdvisorsConfigurationSwapperTest.java  | 12 ++++++------
 agent/core/src/test/resources/advisors.yaml            | 18 +++++++++---------
 .../src/main/resources/prometheus/advisors.yaml        | 18 +++++++++---------
 4 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorConfigurationSwapper.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorConfigurationSwapper.java
index 793628c0921..63dbae5110c 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorConfigurationSwapper.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorConfigurationSwapper.java
@@ -42,13 +42,9 @@ public final class YamlAdvisorConfigurationSwapper {
         if (constructPointcuts.length > 0) {
             result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.isConstructor(), yamlAdvisorConfig.getAdvice()));
         }
-        String[] instanceMethodPointcuts = yamlAdvisorConfig.getPointcuts().stream().filter(each -> "instance".equals(each.getType())).map(YamlPointcutConfiguration::getName).toArray(String[]::new);
-        if (instanceMethodPointcuts.length > 0) {
-            result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.namedOneOf(instanceMethodPointcuts), yamlAdvisorConfig.getAdvice()));
-        }
-        String[] staticMethodPointcuts = yamlAdvisorConfig.getPointcuts().stream().filter(each -> "static".equals(each.getType())).map(YamlPointcutConfiguration::getName).toArray(String[]::new);
-        if (staticMethodPointcuts.length > 0) {
-            result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.namedOneOf(staticMethodPointcuts), yamlAdvisorConfig.getAdvice()));
+        String[] methodPointcuts = yamlAdvisorConfig.getPointcuts().stream().filter(each -> "method".equals(each.getType())).map(YamlPointcutConfiguration::getName).toArray(String[]::new);
+        if (methodPointcuts.length > 0) {
+            result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.namedOneOf(methodPointcuts), yamlAdvisorConfig.getAdvice()));
         }
         return result;
     }
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
index f7aacdc8fb7..198b677f07b 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
@@ -41,19 +41,19 @@ public final class YamlAdvisorsConfigurationSwapperTest {
         List<YamlAdvisorConfiguration> actualYamlAdvisorConfigs = new ArrayList<>(actual.getAdvisors());
         assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(0), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask",
                 "org.apache.shardingsphere.agent.metrics.core.advice.CommandExecutorTaskAdvice",
-                Arrays.asList(createExpectedYamlPointcutConfiguration("run", "instance"), createExpectedYamlPointcutConfiguration("processException", "instance"))));
+                Arrays.asList(createExpectedYamlPointcutConfiguration("run", "method"), createExpectedYamlPointcutConfiguration("processException", "method"))));
         assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(1), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler",
                 "org.apache.shardingsphere.agent.metrics.core.advice.ChannelHandlerAdvice",
-                Arrays.asList(createExpectedYamlPointcutConfiguration("channelActive", "instance"),
-                        createExpectedYamlPointcutConfiguration("channelRead", "instance"), createExpectedYamlPointcutConfiguration("channelInactive", "instance"))));
+                Arrays.asList(createExpectedYamlPointcutConfiguration("channelActive", "method"),
+                        createExpectedYamlPointcutConfiguration("channelRead", "method"), createExpectedYamlPointcutConfiguration("channelInactive", "method"))));
         assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(2), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.infra.route.engine.SQLRouteEngine",
-                "org.apache.shardingsphere.agent.metrics.core.advice.SQLRouteEngineAdvice", Collections.singleton(createExpectedYamlPointcutConfiguration("route", "instance"))));
+                "org.apache.shardingsphere.agent.metrics.core.advice.SQLRouteEngineAdvice", Collections.singleton(createExpectedYamlPointcutConfiguration("route", "method"))));
         assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(3), createExpectedYamlAdvisorConfiguration(
                 "org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager",
                 "org.apache.shardingsphere.agent.metrics.core.advice.TransactionAdvice",
-                Arrays.asList(createExpectedYamlPointcutConfiguration("commit", "instance"), createExpectedYamlPointcutConfiguration("rollback", "instance"))));
+                Arrays.asList(createExpectedYamlPointcutConfiguration("commit", "method"), createExpectedYamlPointcutConfiguration("rollback", "method"))));
         assertYamlAdvisorConfiguration(actualYamlAdvisorConfigs.get(4), createExpectedYamlAdvisorConfiguration("org.apache.shardingsphere.infra.config.datasource.JDBCParameterDecoratorHelper",
-                "org.apache.shardingsphere.agent.metrics.core.advice.DataSourceAdvice", Collections.singleton(createExpectedYamlPointcutConfiguration("decorate", "static"))));
+                "org.apache.shardingsphere.agent.metrics.core.advice.DataSourceAdvice", Collections.singleton(createExpectedYamlPointcutConfiguration("decorate", "method"))));
     }
     
     private void assertYamlAdvisorConfiguration(final YamlAdvisorConfiguration actual, final YamlAdvisorConfiguration expected) {
diff --git a/agent/core/src/test/resources/advisors.yaml b/agent/core/src/test/resources/advisors.yaml
index ec4e8cc7d6e..ef945e7b5e9 100644
--- a/agent/core/src/test/resources/advisors.yaml
+++ b/agent/core/src/test/resources/advisors.yaml
@@ -20,32 +20,32 @@ advisors:
     advice: org.apache.shardingsphere.agent.metrics.core.advice.CommandExecutorTaskAdvice
     pointcuts:
       - name: run
-        type: instance
+        type: method
       - name: processException
-        type: instance
+        type: method
   - target: org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler
     advice: org.apache.shardingsphere.agent.metrics.core.advice.ChannelHandlerAdvice
     pointcuts:
       - name: channelActive
-        type: instance
+        type: method
       - name: channelRead
-        type: instance
+        type: method
       - name: channelInactive
-        type: instance
+        type: method
   - target: org.apache.shardingsphere.infra.route.engine.SQLRouteEngine
     advice: org.apache.shardingsphere.agent.metrics.core.advice.SQLRouteEngineAdvice
     pointcuts:
       - name: route
-        type: instance
+        type: method
   - target: org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager
     advice: org.apache.shardingsphere.agent.metrics.core.advice.TransactionAdvice
     pointcuts:
       - name: commit
-        type: instance
+        type: method
       - name: rollback
-        type: instance
+        type: method
   - target: org.apache.shardingsphere.infra.config.datasource.JDBCParameterDecoratorHelper
     advice: org.apache.shardingsphere.agent.metrics.core.advice.DataSourceAdvice
     pointcuts:
       - name: decorate
-        type: static
+        type: method
diff --git a/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/advisors.yaml b/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/advisors.yaml
index 9a43f7dc19e..b72dea54591 100644
--- a/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/advisors.yaml
+++ b/agent/plugins/metrics/type/prometheus/src/main/resources/prometheus/advisors.yaml
@@ -20,32 +20,32 @@ advisors:
     advice: org.apache.shardingsphere.agent.metrics.core.advice.CommandExecutorTaskAdvice
     pointcuts:
       - name: run
-        type: instance
+        type: method
       - name: processException
-        type: instance
+        type: method
   - target: org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler
     advice: org.apache.shardingsphere.agent.metrics.core.advice.ChannelHandlerAdvice
     pointcuts:
       - name: channelActive
-        type: instance
+        type: method
       - name: channelRead
-        type: instance
+        type: method
       - name: channelInactive
-        type: instance
+        type: method
   - target: org.apache.shardingsphere.infra.route.engine.SQLRouteEngine
     advice: org.apache.shardingsphere.agent.metrics.core.advice.SQLRouteEngineAdvice
     pointcuts:
       - name: route
-        type: instance
+        type: method
   - target: org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.JDBCBackendTransactionManager
     advice: org.apache.shardingsphere.agent.metrics.core.advice.TransactionAdvice
     pointcuts:
       - name: commit
-        type: instance
+        type: method
       - name: rollback
-        type: instance
+        type: method
   - target: org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine
     advice: org.apache.shardingsphere.agent.metrics.core.advice.SQLParserEngineAdvice
     pointcuts:
       - name: parse
-        type: instance
+        type: method