From 2ec71186e29430ae4e38f0fd2cba2c802529c632 Mon Sep 17 00:00:00 2001 From: provenceee <83857838+provenceee@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:50:23 +0800 Subject: [PATCH] resolve wrong process for content of DynamicConfigEvent Signed-off-by: provenceee <83857838+provenceee@users.noreply.github.com> --- .../ConfigOrderIntegratedProcessor.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/subscribe/processor/ConfigOrderIntegratedProcessor.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/subscribe/processor/ConfigOrderIntegratedProcessor.java index 959b3e36a1..8020cbd82d 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/subscribe/processor/ConfigOrderIntegratedProcessor.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/subscribe/processor/ConfigOrderIntegratedProcessor.java @@ -22,14 +22,15 @@ import io.sermant.core.service.dynamicconfig.common.DynamicConfigEvent; import io.sermant.core.service.dynamicconfig.common.DynamicConfigEventType; import io.sermant.core.service.dynamicconfig.common.DynamicConfigListener; -import io.sermant.core.utils.MapUtils; import io.sermant.core.utils.StringUtils; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; /** @@ -112,9 +113,7 @@ private Map buildOrderData() { final Map result = new HashMap<>(CAP_SIZE); for (ConfigDataHolder dataHolder : dataHolders) { for (Map data : dataHolder.getHolder().values()) { - if (data != null) { - result.putAll(data); - } + handleConfig(result, data); } } return result; @@ -125,12 +124,34 @@ private Map buildOrderData(DynamicConfigEvent originEvent) { dataHolders.forEach(dataHolder -> { final Map curContent = dataHolder.getHolder().get(originEvent.getKey()); if (curContent != null) { - result.putAll(curContent); + handleConfig(result, curContent); } }); return result; } + private void handleConfig(Map result, Map config) { + if (config == null || config.isEmpty()) { + return; + } + for (Entry entry : config.entrySet()) { + String key = entry.getKey(); + final Object value = entry.getValue(); + if (value instanceof Map) { + Object resultValue = result.get(key); + Map map = resultValue instanceof Map ? (Map) resultValue + : new HashMap<>(); + handleConfig(map, (Map) value); + result.put(key, map); + } else if (value instanceof Collection) { + result.put(key, value); + } else { + // Other types are reserved directly + result.put(key, value == null ? "" : value); + } + } + } + private boolean updateHolder(ConfigDataHolder targetHolder, DynamicConfigEvent originEvent) { final Map olderDataMap = targetHolder.getHolder().getOrDefault(originEvent.getKey(), new HashMap<>(CAP_SIZE));