tristaZero commented on a change in pull request #11538: URL: https://github.com/apache/shardingsphere/pull/11538#discussion_r677878343
########## File path: shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/resources/interceptors.yaml ########## @@ -0,0 +1,52 @@ +# +# 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. +# + +interceptors: + - target: org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask + instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.CommandExecutorTaskAdvice + points: + - type: instance + name: run + - type: instance + name: processException + - target: org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler + instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.ChannelHandlerAdvice + points: + - type: instance + name: channelActive + - type: instance + name: channelRead + - type: instance + name: channelInactive + - target: org.apache.shardingsphere.infra.route.engine.SQLRouteEngine + instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.SQLRouteEngineAdvice + points: + - type: instance + name: route + - target: org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager + instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.TransactionAdvice + points: + - type: instance + name: commit + - type: instance + name: rollback + - target: org.apache.shardingsphere.infra.config.datasource.JDBCParameterDecoratorHelper + staticAdvice: org.apache.shardingsphere.agent.metrics.api.advice.DataSourceAdvice + points: + - type: static + name: decorate + Review comment: Generally, the last line is expected to be a blank line, rather than an indented line. ########## File path: shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/resources/interceptors.yaml ########## @@ -0,0 +1,52 @@ +# +# 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. +# + +interceptors: + - target: org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask + instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.CommandExecutorTaskAdvice + points: + - type: instance + name: run + - type: instance + name: processException + - target: org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler + instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.ChannelHandlerAdvice + points: + - type: instance + name: channelActive + - type: instance + name: channelRead + - type: instance + name: channelInactive + - target: org.apache.shardingsphere.infra.route.engine.SQLRouteEngine + instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.SQLRouteEngineAdvice + points: + - type: instance + name: route + - target: org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager + instanceAdvice: org.apache.shardingsphere.agent.metrics.api.advice.TransactionAdvice + points: + - type: instance + name: commit + - type: instance + name: rollback + - target: org.apache.shardingsphere.infra.config.datasource.JDBCParameterDecoratorHelper + staticAdvice: org.apache.shardingsphere.agent.metrics.api.advice.DataSourceAdvice + points: + - type: static + name: decorate + Review comment: Please check other files. Thanks. ########## File path: shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/main/java/org/apache/shardingsphere/agent/metrics/api/definition/MetricsPluginDefinitionService.java ########## @@ -17,58 +17,56 @@ package org.apache.shardingsphere.agent.metrics.api.definition; +import lombok.extern.slf4j.Slf4j; import net.bytebuddy.matcher.ElementMatchers; -import org.apache.shardingsphere.agent.metrics.api.constant.MethodNameConstant; +import org.apache.shardingsphere.agent.api.point.PluginInterceptorPoint; +import org.apache.shardingsphere.agent.core.entity.Interceptor; +import org.apache.shardingsphere.agent.core.entity.Interceptors; +import org.apache.shardingsphere.agent.core.entity.TargetPoint; import org.apache.shardingsphere.agent.spi.definition.AbstractPluginDefinitionService; +import org.yaml.snakeyaml.Yaml; + +import java.io.InputStream; /** * Metrics plugin definition service. */ +@Slf4j public final class MetricsPluginDefinitionService extends AbstractPluginDefinitionService { - private static final String COMMAND_EXECUTOR_TASK_ENHANCE_CLASS = "org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask"; - - private static final String COMMAND_EXECUTOR_TASK_ADVICE_CLASS = "org.apache.shardingsphere.agent.metrics.api.advice.CommandExecutorTaskAdvice"; - - private static final String CHANNEL_HANDLER_ENHANCE_CLASS = "org.apache.shardingsphere.proxy.frontend.netty.FrontendChannelInboundHandler"; - - private static final String CHANNEL_HANDLER_ADVICE_CLASS = "org.apache.shardingsphere.agent.metrics.api.advice.ChannelHandlerAdvice"; - - private static final String SQL_ROUTER_ENGINE_ENHANCE_CLASS = "org.apache.shardingsphere.infra.route.engine.SQLRouteEngine"; - - private static final String SQL_ROUTER_ENGINE_ADVICE_CLASS = "org.apache.shardingsphere.agent.metrics.api.advice.SQLRouteEngineAdvice"; - - private static final String TRANSACTION_ENHANCE_CLASS = "org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager"; - - private static final String TRANSACTION_ADVICE_CLASS = "org.apache.shardingsphere.agent.metrics.api.advice.TransactionAdvice"; - - private static final String DATASOURCE_ENHANCE_CLASS = "org.apache.shardingsphere.infra.config.datasource.JDBCParameterDecoratorHelper"; - - private static final String DATASOURCE_ADVICE_CLASS = "org.apache.shardingsphere.agent.metrics.api.advice.DataSourceAdvice"; - @Override public void defineInterceptors() { - defineInterceptor(COMMAND_EXECUTOR_TASK_ENHANCE_CLASS) - .aroundInstanceMethod(ElementMatchers.named(MethodNameConstant.COMMAND_EXECUTOR_RUN)) - .implement(COMMAND_EXECUTOR_TASK_ADVICE_CLASS) - .build(); - defineInterceptor(CHANNEL_HANDLER_ENHANCE_CLASS) - .aroundInstanceMethod(ElementMatchers.named(MethodNameConstant.CHANNEL_ACTIVE).or(ElementMatchers.named(MethodNameConstant.CHANNEL_INACTIVE)) - .or(ElementMatchers.named(MethodNameConstant.CHANNEL_READ))) - .implement(CHANNEL_HANDLER_ADVICE_CLASS) - .build(); - defineInterceptor(SQL_ROUTER_ENGINE_ENHANCE_CLASS) - .aroundInstanceMethod(ElementMatchers.named(MethodNameConstant.SQL_ROUTER)) - .implement(SQL_ROUTER_ENGINE_ADVICE_CLASS) - .build(); - defineInterceptor(TRANSACTION_ENHANCE_CLASS) - .aroundInstanceMethod(ElementMatchers.named(MethodNameConstant.COMMIT).or(ElementMatchers.named(MethodNameConstant.ROLL_BACK))) - .implement(TRANSACTION_ADVICE_CLASS) - .build(); - defineInterceptor(DATASOURCE_ENHANCE_CLASS) - .aroundClassStaticMethod(ElementMatchers.named(MethodNameConstant.DECORATE)) - .implement(DATASOURCE_ADVICE_CLASS) - .build(); + Yaml yaml = new Yaml(); + InputStream in = this.getClass().getResourceAsStream("/interceptors.yaml"); + Interceptors interceptors = yaml.loadAs(in, Interceptors.class); + for (Interceptor interceptor : interceptors.getInterceptors()) { + String[] instancePoints = interceptor + .getPoints() + .stream() + .filter(i -> i.getType().equals("instance")) + .map(TargetPoint::getName) + .toArray(String[]::new); + String[] staticPoints = interceptor + .getPoints() + .stream() + .filter(i -> i.getType().equals("static")) + .map(TargetPoint::getName) + .toArray(String[]::new); + Review comment: It's suggested to remove this blank line. If you want to split these codings, extracting a function is a preferred way. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
