From 6ede78491e89d3593829fffa044a48b1bd8ce763 Mon Sep 17 00:00:00 2001 From: lilai Date: Thu, 26 Dec 2024 15:47:27 +0800 Subject: [PATCH] fix args cannot take effect when dynamic install sermant agent with external agent Signed-off-by: lilai --- .../java/io/sermant/core/AgentCoreEntrance.java | 15 +++++++++++---- .../sermant/core/ext/ExternalAgentManager.java | 5 +++-- .../io/sermant/core/service/metric/api/Tags.java | 2 ++ .../metric/entity/MetricCommonTagEnum.java | 10 +++++----- .../service/xds/handler/XdsHandler.java | 1 - .../xds/utils/RdsProtocolTransformer.java | 2 +- .../frontend/src/composables/translations.ts | 16 ++++++++-------- .../webapp/frontend/src/views/InstancesView.vue | 4 ++-- .../ResetBeforeRequestErrorCondition.java | 3 +-- .../DispatcherServletInterceptor.java | 3 ++- 10 files changed, 35 insertions(+), 26 deletions(-) diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/AgentCoreEntrance.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/AgentCoreEntrance.java index ea810c2d53..6715bbc50f 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/AgentCoreEntrance.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/AgentCoreEntrance.java @@ -46,6 +46,7 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; /** * agent core entrance @@ -144,15 +145,21 @@ public static void install(String artifact, Map argsMap, Instrum CommandProcessor.cacheInstrumentation(instrumentation); // install external agent, such as OTEL - handleExternalAgentInstallation(instrumentation); + handleExternalAgentInstallation(instrumentation, isDynamic, argsMap); } - private static void handleExternalAgentInstallation(Instrumentation instrumentation) { + private static void handleExternalAgentInstallation(Instrumentation instrumentation, boolean isDynamic, + Map argsMap) { AgentConfig agentConfig = ConfigManager.getConfig(AgentConfig.class); if (agentConfig.isExternalAgentInjection()) { try { - ExternalAgentManager.installExternalAgent(false, agentConfig.getExternalAgentName(), - agentConfig.getExternalAgentFile(), null, instrumentation); + Map args = null; + if (isDynamic) { + args = argsMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, + entry -> entry.getValue() != null ? (String) entry.getValue() : null)); + } + ExternalAgentManager.installExternalAgent(isDynamic, agentConfig.getExternalAgentName(), + agentConfig.getExternalAgentFile(), args, instrumentation); } catch (Exception e) { LOGGER.severe("Failed to install external agent: " + e.getMessage()); } diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/ext/ExternalAgentManager.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/ext/ExternalAgentManager.java index bffe102982..72ef388c89 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/ext/ExternalAgentManager.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/ext/ExternalAgentManager.java @@ -35,6 +35,7 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicBoolean; import java.util.jar.Attributes; import java.util.jar.JarFile; @@ -191,8 +192,8 @@ static String loadAgentJar(String agentName, String agentPath, Instrumentation i * @param argsMap arguments of dynamic installation */ static void setArgsToSystemProperties(Map argsMap) { - for (String key : argsMap.keySet()) { - System.setProperty(key, argsMap.get(key)); + for (Entry entry : argsMap.entrySet()) { + System.setProperty(entry.getKey(), entry.getValue()); } } diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/Tags.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/Tags.java index bacc2e1197..52ea34ed73 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/Tags.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/Tags.java @@ -39,10 +39,12 @@ public final class Tags { * Key for the scope tag */ public static final String SCOPE = "scope"; + /** * Value for the core scope tag */ public static final String SCOPE_VALUE_CORE = "core"; + private final Map tags = new HashMap<>(); private Tags() { diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/entity/MetricCommonTagEnum.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/entity/MetricCommonTagEnum.java index c60df09b59..20175d2b29 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/entity/MetricCommonTagEnum.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/entity/MetricCommonTagEnum.java @@ -32,7 +32,6 @@ * @since 2024-12-18 */ public enum MetricCommonTagEnum { - /** * Define an AGENT tag with key "agent" and a constant value "sermant". */ @@ -64,10 +63,12 @@ public enum MetricCommonTagEnum { /** * Define an AGENT_VERSION tag with key "agent.version" and a value supplied by agent version */ - AGENT_VERSION("agent.version", false, BootArgsIndexer::getCoreVersion),; + AGENT_VERSION("agent.version", false, BootArgsIndexer::getCoreVersion); private final String key; + private final boolean defaultEnable; + private final Supplier valueSupplier; /** @@ -121,8 +122,8 @@ public static Set getDefaultKeys() { } /** - * Get the value of the tag corresponding to the given key. - * If the provided key is empty or does not correspond to any tag, return an empty string. + * Get the value of the tag corresponding to the given key. If the provided key is empty or does not correspond to + * any tag, return an empty string. * * @param key The key of the tag * @return The value of the tag, or an empty string if no matching tag exists @@ -138,5 +139,4 @@ public static String of(String key) { } return StringUtils.EMPTY; } - } diff --git a/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/xds/handler/XdsHandler.java b/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/xds/handler/XdsHandler.java index 39c797baae..38ffa12418 100644 --- a/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/xds/handler/XdsHandler.java +++ b/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/xds/handler/XdsHandler.java @@ -211,7 +211,6 @@ private void handleError(Throwable throwable, String requestKey) { Thread.sleep(DELAY_TIME); } catch (InterruptedException e) { LOGGER.log(Level.WARNING, "An error occurred in thread sleeping.", e); - Thread.currentThread().interrupt(); } client.updateChannel(); subscribe(requestKey, null); diff --git a/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/xds/utils/RdsProtocolTransformer.java b/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/xds/utils/RdsProtocolTransformer.java index 1be0673f4d..4e750e6c3e 100644 --- a/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/xds/utils/RdsProtocolTransformer.java +++ b/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/xds/utils/RdsProtocolTransformer.java @@ -347,7 +347,7 @@ private static XdsDelay parseDelay(FaultDelay faultDelay) { * } * } * } - *} + * } * * @param typedStruct Serial protocol buffer message for rate limiting configuration * @return Rate limiting configuration information diff --git a/sermant-backend/src/main/webapp/frontend/src/composables/translations.ts b/sermant-backend/src/main/webapp/frontend/src/composables/translations.ts index be8087976c..e014edbb1c 100644 --- a/sermant-backend/src/main/webapp/frontend/src/composables/translations.ts +++ b/sermant-backend/src/main/webapp/frontend/src/composables/translations.ts @@ -26,7 +26,7 @@ export const messages = { uninstallAgent: 'Uninstall Agent', updatePlugin: 'Update Plugin', updateAgent: 'Update Agent', - installExternalAgent: "Install External Agent", + installExternalAgent: 'Install External Agent', commandTypePlaceholder: 'Please select The command type', agentPathPlaceholder: 'Please input the Agent path', pluginNamePlaceholder: 'Please enter the plugin name', @@ -42,7 +42,7 @@ export const messages = { commandType: 'Command Type', pluginName: 'Plugin Name', agentPath: 'Agent Path', - externalAgentName: "Agent Name", + externalAgentName: 'Agent Name', param: 'Param', instance: 'Instance', version: 'Version', @@ -134,8 +134,8 @@ export const messages = { pluginInstall: 'Plugin Install', pluginUninstall: 'Plugin Uninstall', pluginUpdate: 'Plugin Update', - externalAgentInstall: "External Agent Install", - otelStart: "OTEL Agent Start", + externalAgentInstall: 'External Agent Install', + otelStart: 'OTEL Agent Start', }, eventConfigView: { event: 'Event', @@ -298,7 +298,7 @@ export const messages = { uninstallAgent: '卸载Agent', updatePlugin: '升级插件', updateAgent: '升级Agent', - installExternalAgent: "安装外部Agent", + installExternalAgent: '安装外部Agent', commandTypePlaceholder: '请选择命令类型', agentPathPlaceholder: '请输入Agent路径', pluginNamePlaceholder: '请输入插件名称', @@ -314,7 +314,7 @@ export const messages = { commandType: '命令类型', pluginName: '插件名称', agentPath: 'Agent路径', - externalAgentName: "Agent名称", + externalAgentName: 'Agent名称', param: '参数', instance: '实例', version: '版本', @@ -406,8 +406,8 @@ export const messages = { pluginInstall: '插件安装', pluginUninstall: '插件卸载', pluginUpdate: '插件更新', - externalAgentInstall: "安装外部Agent", - otelStart: "OTEL Agent启动", + externalAgentInstall: '安装外部Agent', + otelStart: 'OTEL Agent启动', }, eventConfigView: { event: '事件', diff --git a/sermant-backend/src/main/webapp/frontend/src/views/InstancesView.vue b/sermant-backend/src/main/webapp/frontend/src/views/InstancesView.vue index 0c0367af11..e10c24a5d4 100644 --- a/sermant-backend/src/main/webapp/frontend/src/views/InstancesView.vue +++ b/sermant-backend/src/main/webapp/frontend/src/views/InstancesView.vue @@ -151,7 +151,7 @@