diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/AgentCoreEntrance.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/AgentCoreEntrance.java index feced95bcf..1ea0e8f804 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/AgentCoreEntrance.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/AgentCoreEntrance.java @@ -32,6 +32,7 @@ import com.huaweicloud.sermant.core.plugin.agent.ByteEnhanceManager; import com.huaweicloud.sermant.core.plugin.agent.adviser.AdviserInterface; import com.huaweicloud.sermant.core.plugin.agent.adviser.AdviserScheduler; +import com.huaweicloud.sermant.core.plugin.agent.info.EnhanceInfo; import com.huaweicloud.sermant.core.plugin.agent.template.DefaultAdviser; import com.huaweicloud.sermant.core.service.ServiceManager; import com.huaweicloud.sermant.god.common.SermantManager; @@ -157,6 +158,9 @@ public static void uninstall() { // 清理配置类 ConfigManager.shutdown(); + // 清理增强信息类 + EnhanceInfo.clear(); + // 设置该artifact的Sermant状态为false,非运行状态 SermantManager.updateSermantStatus(artifactCache, false); } diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/CheckEnhanceCommandExecutor.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/CheckEnhanceCommandExecutor.java new file mode 100644 index 0000000000..617d85df8a --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/CheckEnhanceCommandExecutor.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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. + */ + +package com.huaweicloud.sermant.core.command; + +import com.huaweicloud.sermant.core.common.LoggerFactory; +import com.huaweicloud.sermant.core.plugin.Plugin; +import com.huaweicloud.sermant.core.plugin.PluginManager; +import com.huaweicloud.sermant.core.plugin.agent.info.EnhanceInfo; + +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * 增强信息查询命令执行器 + * + * @author tangle + * @since 2023-11-02 + */ +public class CheckEnhanceCommandExecutor implements CommandExecutor { + private static final Logger LOGGER = LoggerFactory.getLogger(); + + @Override + public void execute(String args) { + LOGGER.log(Level.INFO, "========== print enhance class and method =========="); + for (String enhancement : EnhanceInfo.getEnhancement()) { + LOGGER.log(Level.INFO, enhancement); + } + LOGGER.log(Level.INFO, "========== print plugin =========="); + for (Map.Entry entry : PluginManager.getPluginMap().entrySet()) { + String printPluginMsg = "[PluginName]:" + entry.getKey() + "\t[Version]:" + entry.getValue().getVersion(); + LOGGER.log(Level.INFO, printPluginMsg); + } + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/Command.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/Command.java index 0e6384a182..61d6e6d7b0 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/Command.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/Command.java @@ -34,7 +34,13 @@ public enum Command { /** * 卸载插件指令 */ - UNINSTALL_PLUGINS("UNINSTALL-PLUGINS"); + UNINSTALL_PLUGINS("UNINSTALL-PLUGINS"), + + /** + * 增强查询指令 + */ + CHECK_ENHANCE("CHECK-ENHANCE"); + private final String value; Command(String value) { diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/CommandProcessor.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/CommandProcessor.java index d685226a24..9776a391ba 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/CommandProcessor.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/CommandProcessor.java @@ -43,6 +43,7 @@ public class CommandProcessor { COMMAND_EXECUTOR_MAP.put(Command.INSTALL_PLUGINS.getValue(), new PluginsInstallCommandExecutor()); COMMAND_EXECUTOR_MAP.put(Command.UNINSTALL_AGENT.getValue(), new AgentUnInstallCommandExecutor()); COMMAND_EXECUTOR_MAP.put(Command.UNINSTALL_PLUGINS.getValue(), new PluginsUnInstallCommandExecutor()); + COMMAND_EXECUTOR_MAP.put(Command.CHECK_ENHANCE.getValue(), new CheckEnhanceCommandExecutor()); } /** diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/PluginManager.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/PluginManager.java index 209db2bc30..44c2e8991f 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/PluginManager.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/PluginManager.java @@ -183,6 +183,10 @@ public static void initPlugins(Set pluginNames, boolean isDynamic) { } } + public static Map getPluginMap() { + return PLUGIN_MAP; + } + private static void doInitPlugin(Plugin plugin) { loadPluginLibs(plugin); loadServiceLibs(plugin); diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/info/EnhanceInfo.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/info/EnhanceInfo.java new file mode 100644 index 0000000000..a871e8d139 --- /dev/null +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/info/EnhanceInfo.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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. + */ + +package com.huaweicloud.sermant.core.plugin.agent.info; + +import com.huaweicloud.sermant.core.utils.CollectionUtils; +import com.huaweicloud.sermant.core.utils.StringUtils; + +import java.util.HashSet; +import java.util.Set; + +/** + * 存储增强信息的静态类 + * + * @author tangle + * @since 2023-11-02 + */ +public class EnhanceInfo { + private static Set enhancement; + + private EnhanceInfo() { + } + + public static Set getEnhancement() { + return enhancement; + } + + public static void setEnhancement(Set enhancement) { + EnhanceInfo.enhancement = enhancement; + } + + /** + * 添加拦截器信息 + * + * @param className 类名 + * @param methodName 方法名 + */ + public static void addMethodDesc(String className, String methodName) { + if (CollectionUtils.isEmpty(enhancement)) { + enhancement = new HashSet<>(); + } + if (!StringUtils.isEmpty(className) && !StringUtils.isEmpty(methodName)) { + enhancement.add(className + "::" + methodName); + } + } + + /** + * 清理缓存的增强信息 + */ + public static void clear() { + enhancement.clear(); + } +} diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/transformer/ReentrantTransformer.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/transformer/ReentrantTransformer.java index 67ae1013af..460a1ddf66 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/transformer/ReentrantTransformer.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/transformer/ReentrantTransformer.java @@ -19,6 +19,7 @@ import com.huaweicloud.sermant.core.plugin.Plugin; import com.huaweicloud.sermant.core.plugin.agent.adviser.AdviserScheduler; import com.huaweicloud.sermant.core.plugin.agent.declarer.InterceptDeclarer; +import com.huaweicloud.sermant.core.plugin.agent.info.EnhanceInfo; import com.huaweicloud.sermant.core.plugin.agent.interceptor.Interceptor; import com.huaweicloud.sermant.core.plugin.agent.template.BaseAdviseHandler; @@ -69,6 +70,7 @@ protected Builder resolve(Builder builder, InDefinedShape methodDesc, List createdInterceptorForAdviceKey.add(interceptor.getClass().getCanonicalName()); } } + EnhanceInfo.addMethodDesc(methodDesc.getDeclaringType().getCanonicalName(), methodDesc.getActualName()); if (checkAdviceLock(adviceKey)) { return builder.visit(Advice.to(templateCls).on(ElementMatchers.is(methodDesc))); }