You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/03/31 08:03:01 UTC

[shardingsphere] branch master updated: Merge the advisors configuration of proxy and jdbc in agent (#24910)

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

jianglongtao 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 0a00e5ec265 Merge the advisors configuration of proxy and jdbc in agent (#24910)
0a00e5ec265 is described below

commit 0a00e5ec26522f70652a51f7d46551422568cf15
Author: jiangML <10...@qq.com>
AuthorDate: Fri Mar 31 16:02:40 2023 +0800

    Merge the advisors configuration of proxy and jdbc in agent (#24910)
    
    * Merge prometheus-jdbc-advisors.yaml and prometheus-proxy-advisors.yaml into prometheus-advisors.yaml
    
    * Remove the distinction between proxy and jdbc configuration files
---
 .../agent/core/ShardingSphereAgent.java            |  2 +-
 .../advisor/config/AdvisorConfigurationLoader.java | 18 ++----
 ...jdbc-advisors.yaml => prometheus-advisors.yaml} | 35 ++++++++++++
 .../META-INF/conf/prometheus-proxy-advisors.yaml   | 65 ----------------------
 4 files changed, 40 insertions(+), 80 deletions(-)

diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
index 9b32b64d2a5..a9537697935 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
@@ -53,7 +53,7 @@ public final class ShardingSphereAgent {
         Map<String, PluginConfiguration> pluginConfigs = PluginConfigurationLoader.load(rootPath);
         Collection<JarFile> pluginJars = PluginJarLoader.load(rootPath);
         boolean isEnhancedForProxy = isEnhancedForProxy();
-        Map<String, AdvisorConfiguration> advisorConfigs = AdvisorConfigurationLoader.load(pluginJars, pluginConfigs.keySet(), isEnhancedForProxy);
+        Map<String, AdvisorConfiguration> advisorConfigs = AdvisorConfigurationLoader.load(pluginJars, pluginConfigs.keySet());
         AgentBuilderFactory.create(pluginConfigs, pluginJars, advisorConfigs, isEnhancedForProxy).installOn(instrumentation);
     }
     
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationLoader.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationLoader.java
index 22bff1ae6eb..0e8043e83e3 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationLoader.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationLoader.java
@@ -45,14 +45,13 @@ public final class AdvisorConfigurationLoader {
      * 
      * @param pluginJars plugin jars
      * @param pluginTypes plugin types
-     * @param isEnhancedForProxy is enhanced for proxy
      * @return loaded configurations
      */
-    public static Map<String, AdvisorConfiguration> load(final Collection<JarFile> pluginJars, final Collection<String> pluginTypes, final boolean isEnhancedForProxy) {
+    public static Map<String, AdvisorConfiguration> load(final Collection<JarFile> pluginJars, final Collection<String> pluginTypes) {
         Map<String, AdvisorConfiguration> result = new HashMap<>();
         AgentPluginClassLoader agentPluginClassLoader = new AgentPluginClassLoader(AdvisorConfigurationLoader.class.getClassLoader(), pluginJars);
         for (String each : pluginTypes) {
-            InputStream advisorsResourceStream = getResourceStream(agentPluginClassLoader, each, isEnhancedForProxy);
+            InputStream advisorsResourceStream = getResourceStream(agentPluginClassLoader, each);
             if (null == advisorsResourceStream) {
                 LOGGER.info("No configuration of advisor for type `{}`.", each);
             } else {
@@ -62,17 +61,8 @@ public final class AdvisorConfigurationLoader {
         return result;
     }
     
-    private static InputStream getResourceStream(final ClassLoader pluginClassLoader, final String pluginType, final boolean isEnhancedForProxy) {
-        InputStream accurateResourceStream = getResourceStream(pluginClassLoader, getFileName(pluginType, isEnhancedForProxy));
-        return null == accurateResourceStream ? getResourceStream(pluginClassLoader, getFileName(pluginType)) : accurateResourceStream;
-    }
-    
-    private static InputStream getResourceStream(final ClassLoader pluginClassLoader, final String fileName) {
-        return pluginClassLoader.getResourceAsStream(String.join(File.separator, "META-INF", "conf", fileName));
-    }
-    
-    private static String getFileName(final String pluginType, final boolean isEnhancedForProxy) {
-        return String.join("-", pluginType.toLowerCase(), isEnhancedForProxy ? "proxy" : "jdbc", "advisors.yaml");
+    private static InputStream getResourceStream(final ClassLoader pluginClassLoader, final String pluginType) {
+        return pluginClassLoader.getResourceAsStream(String.join(File.separator, "META-INF", "conf", getFileName(pluginType)));
     }
     
     private static String getFileName(final String pluginType) {
diff --git a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-jdbc-advisors.yaml b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-advisors.yaml
similarity index 72%
rename from agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-jdbc-advisors.yaml
rename to agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-advisors.yaml
index 2b66546db58..347cbba423c 100644
--- a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-jdbc-advisors.yaml
+++ b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-advisors.yaml
@@ -16,6 +16,7 @@
 #
 
 advisors:
+  # config for proxy and jdbc
   - target: org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine
     advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.SQLParseCountAdvice
     pointcuts:
@@ -31,6 +32,40 @@ advisors:
     pointcuts:
       - name: route
         type: method
+  # config for proxy
+  - target: org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
+    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.ExecuteLatencyHistogramAdvice
+    pointcuts:
+      - name: doExecuteCommand
+        type: method
+  - target: org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
+    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.ExecuteErrorsCountAdvice
+    pointcuts:
+      - name: processException
+        type: method
+  - target: org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler
+    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.CurrentConnectionsCountAdvice
+    pointcuts:
+      - name: channelActive
+        type: method
+      - name: channelInactive
+        type: method
+  - target: org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
+    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.RequestsCountAdvice
+    pointcuts:
+      - name: run
+        type: method
+  - target: org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.BackendTransactionManager
+    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.CommitTransactionsCountAdvice
+    pointcuts:
+      - name: commit
+        type: method
+  - target: org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.BackendTransactionManager
+    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.RollbackTransactionsCountAdvice
+    pointcuts:
+      - name: rollback
+        type: method
+  # config for jdbc
   - target: org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement
     advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc.StatementExecuteCountAdvice
     pointcuts:
diff --git a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-proxy-advisors.yaml b/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-proxy-advisors.yaml
deleted file mode 100644
index 006d931f151..00000000000
--- a/agent/plugins/metrics/type/prometheus/src/main/resources/META-INF/conf/prometheus-proxy-advisors.yaml
+++ /dev/null
@@ -1,65 +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.
-#
-
-advisors:
-  - target: org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
-    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.ExecuteLatencyHistogramAdvice
-    pointcuts:
-      - name: doExecuteCommand
-        type: method
-  - target: org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
-    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.ExecuteErrorsCountAdvice
-    pointcuts:
-      - name: processException
-        type: method
-  - target: org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler
-    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.CurrentConnectionsCountAdvice
-    pointcuts:
-      - name: channelActive
-        type: method
-      - name: channelInactive
-        type: method
-  - target: org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
-    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.RequestsCountAdvice
-    pointcuts:
-      - name: run
-        type: method
-  - target: org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.BackendTransactionManager
-    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.CommitTransactionsCountAdvice
-    pointcuts:
-      - name: commit
-        type: method
-  - target: org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.BackendTransactionManager
-    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.proxy.RollbackTransactionsCountAdvice
-    pointcuts:
-      - name: rollback
-        type: method
-  - target: org.apache.shardingsphere.infra.route.engine.SQLRouteEngine
-    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.SQLRouteCountAdvice
-    pointcuts:
-      - name: route
-        type: method
-  - target: org.apache.shardingsphere.infra.route.engine.SQLRouteEngine
-    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.RouteResultCountAdvice
-    pointcuts:
-      - name: route
-        type: method
-  - target: org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine
-    advice: org.apache.shardingsphere.agent.plugin.metrics.core.advice.SQLParseCountAdvice
-    pointcuts:
-      - name: parse
-        type: method