Skip to content

Commit 08d5255

Browse files
authored
Merge pull request #1557 from hanbingleixue/develop
Fixed the issue that the KIE configuration fails to be delivered and the configuration of the tag-transmission plugin fails to be queried
2 parents 6b79f67 + 2884661 commit 08d5255

File tree

14 files changed

+85
-32
lines changed

14 files changed

+85
-32
lines changed

sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/dynamicconfig/kie/KieDynamicConfigService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.sermant.core.service.dynamicconfig.common.DynamicConfigListener;
2222
import io.sermant.implement.service.dynamicconfig.kie.client.kie.KieConfigEntity;
2323
import io.sermant.implement.service.dynamicconfig.kie.client.kie.KieResponse;
24+
import io.sermant.implement.service.dynamicconfig.kie.constants.KieConstants;
2425
import io.sermant.implement.service.dynamicconfig.kie.listener.SubscriberManager;
2526
import io.sermant.implement.utils.LabelGroupUtils;
2627

@@ -84,8 +85,8 @@ public boolean addConfigListener(String key, String group, DynamicConfigListener
8485
String newGroup = group;
8586
if (!LabelGroupUtils.isLabelGroup(group)) {
8687
// Add label group judgment to adapt irregular groups
87-
newGroup = LabelGroupUtils
88-
.createLabelGroup(Collections.singletonMap(fixSeparator(group, true), fixSeparator(key, false)));
88+
newGroup = LabelGroupUtils.createLabelGroup(Collections.singletonMap(KieConstants.DEFAULT_GROUP,
89+
fixSeparator(group, true)));
8990
}
9091
return subscriberManager.addConfigListener(key, newGroup, listener, ifNotify);
9192
}

sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/dynamicconfig/kie/client/kie/KieClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.sermant.implement.service.dynamicconfig.kie.client.ClientUrlManager;
2323
import io.sermant.implement.service.dynamicconfig.kie.client.http.HttpClient;
2424
import io.sermant.implement.service.dynamicconfig.kie.client.http.HttpResult;
25+
import io.sermant.implement.service.dynamicconfig.kie.constants.KieConstants;
2526
import io.sermant.implement.utils.LabelGroupUtils;
2627

2728
import org.apache.http.HttpStatus;
@@ -220,8 +221,9 @@ public String getConfig(String key, String group) {
220221
@Override
221222
public Map<String, List<String>> getConfigList(String key, String group, boolean exactMatchFlag) {
222223
final KieResponse kieResponse;
224+
String covertGroup = group.replace(KieConstants.SEPARATOR, KieConstants.CONNECTOR);
223225
if (exactMatchFlag) {
224-
kieResponse = getKieResponse(key, group, exactMatchFlag);
226+
kieResponse = getKieResponse(key, covertGroup, exactMatchFlag);
225227
} else {
226228
kieResponse = getKieResponse(key, null, exactMatchFlag);
227229
}
@@ -236,7 +238,7 @@ public Map<String, List<String>> getConfigList(String key, String group, boolean
236238
configList.add(entity.getKey());
237239
} else {
238240
String currentConfigGroup = LabelGroupUtils.createLabelGroup(entity.getLabels());
239-
if (currentConfigGroup.contains(group)) {
241+
if (currentConfigGroup.contains(covertGroup)) {
240242
List<String> configList = result.computeIfAbsent(
241243
LabelGroupUtils.createLabelGroup(entity.getLabels()), configKey -> new ArrayList<>());
242244
configList.add(entity.getKey());

sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/dynamicconfig/kie/constants/KieConstants.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ public class KieConstants {
2828
*/
2929
public static final String DEFAULT_GROUP_KEY = "_DEFAULT_GROUP_KEY";
3030

31+
/**
32+
* Unsupported delimiter in Group
33+
*/
34+
public static final String SEPARATOR = "/";
35+
36+
/**
37+
* Supported connectors in Group
38+
*/
39+
public static final String CONNECTOR = ".";
40+
41+
/**
42+
* The default key for the label
43+
*/
44+
public static final String DEFAULT_LABEL_PRE = "GROUP=";
45+
46+
/**
47+
* The default key for the label
48+
*/
49+
public static final String DEFAULT_GROUP = "GROUP";
50+
3151
private KieConstants() {
3252
}
3353
}

sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/dynamicconfig/zookeeper/ZooKeeperClient.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class ZooKeeperClient implements ConfigClient {
4848
* ZK path separator
4949
*/
5050
public static final char ZK_PATH_SEPARATOR = '/';
51+
5152
private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperClient.class.getName());
5253

5354
/**
@@ -167,33 +168,38 @@ private Map<String, List<String>> fuzzyGetConfigListByGroupAndKey(String key, St
167168
if (!ifNodeExist(parentNodePath)) {
168169
return configList;
169170
}
170-
List<String> childList = this.zkClient.getChildren(parentNodePath, false);
171-
for (String child : childList) {
171+
fillChildrenInfo(parentNodePath, configList, nodeName, key);
172+
return configList;
173+
}
174+
175+
private void fillChildrenInfo(String path, Map<String, List<String>> configMap, String nodeName,
176+
String key) throws InterruptedException, KeeperException {
177+
List<String> children = this.zkClient.getChildren(path, false);
178+
children.parallelStream().forEach(child -> {
179+
List<String> subChild;
172180
if (!child.contains(nodeName)) {
173-
continue;
181+
return;
174182
}
175-
String childPath;
176-
if (parentNodePath.endsWith(String.valueOf(ZK_PATH_SEPARATOR))) {
177-
childPath = parentNodePath + child;
178-
} else {
179-
childPath = parentNodePath + ZK_PATH_SEPARATOR + child;
183+
String childPath = toPath(child, path);
184+
try {
185+
subChild = this.zkClient.getChildren(childPath, false);
186+
} catch (KeeperException | InterruptedException e) {
187+
return;
180188
}
181-
List<String> subChild = this.zkClient.getChildren(childPath, false);
182189
if (subChild == null || subChild.isEmpty()) {
183-
continue;
190+
return;
184191
}
185192
if (key == null || key.isEmpty()) {
186-
configList.put(childPath.substring(1), subChild);
187-
continue;
193+
configMap.put(childPath.substring(1), subChild);
194+
return;
188195
}
189196
List<String> matchSubChild = subChild.stream().filter(value -> value.contains(key))
190197
.collect(Collectors.toList());
191198
if (matchSubChild.isEmpty()) {
192-
continue;
199+
return;
193200
}
194-
configList.put(childPath.substring(1), matchSubChild);
195-
}
196-
return configList;
201+
configMap.put(childPath.substring(1), matchSubChild);
202+
});
197203
}
198204

199205
private Map<String, List<String>> accurateGetConfigListByGroupAndKey(String key, String group)

sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/utils/LabelGroupUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.sermant.implement.utils;
1818

1919
import io.sermant.implement.service.dynamicconfig.common.DynamicConstants;
20+
import io.sermant.implement.service.dynamicconfig.kie.constants.KieConstants;
2021

2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
@@ -95,7 +96,8 @@ public static String createLabelGroup(Map<String, String> labels) {
9596
if (group.length() == 0) {
9697
return DynamicConstants.EMPTY_STRING;
9798
}
98-
return group.deleteCharAt(group.length() - 1).toString();
99+
String groupString = group.deleteCharAt(group.length() - 1).toString();
100+
return groupString.replace(KieConstants.SEPARATOR, KieConstants.CONNECTOR);
99101
}
100102

101103
/**
@@ -132,7 +134,7 @@ public static Map<String, String> resolveGroupLabels(String group) {
132134
if (group == null) {
133135
return result;
134136
}
135-
String curGroup = group;
137+
String curGroup = group.replace(KieConstants.SEPARATOR, KieConstants.SEPARATOR);
136138
if (!isLabelGroup(curGroup)) {
137139
// If the label is not a group (applicable to the ZK configuration center scenario), create a label for
138140
// the group
@@ -176,7 +178,8 @@ public static String getLabelCondition(String group) {
176178
.append(buildSingleLabel(entry.getKey(), entry.getValue()))
177179
.append(GROUP_SEPARATOR);
178180
}
179-
return finalGroup.deleteCharAt(finalGroup.length() - 1).toString();
181+
String finalGroupStr = finalGroup.deleteCharAt(finalGroup.length() - 1).toString();
182+
return finalGroupStr.replace(KieConstants.SEPARATOR, KieConstants.CONNECTOR);
180183
}
181184

182185
private static String buildSingleLabel(String key, String value) {

sermant-backend/src/main/java/io/sermant/backend/common/conf/DynamicConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ public class DynamicConfig {
9191
/**
9292
* Switch for configuration management
9393
*/
94-
@Value("${dynamic.config.dynamicConfigEnable}")
95-
private boolean dynamicConfigEnable;
94+
@Value("${dynamic.config.enable}")
95+
private boolean enable;
9696
}

sermant-backend/src/main/java/io/sermant/backend/entity/config/ResultCodeType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ public enum ResultCodeType {
7474
/**
7575
* Interface call failed
7676
*/
77-
FAIL("09", "Failure.");
77+
FAIL("09", "Failure."),
78+
79+
/**
80+
* Dynamic configuration switch not turned on
81+
*/
82+
NOT_ENABLE("10", "Dynamic configuration switch not turned on.");
7883

7984
private final String code;
8085

sermant-backend/src/main/java/io/sermant/backend/service/ConfigService.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.alibaba.nacos.api.PropertyKeyConst;
2020
import com.alibaba.nacos.api.exception.NacosException;
21+
import com.alibaba.nacos.client.auth.impl.NacosAuthLoginConstant;
2122

2223
import io.sermant.backend.common.conf.DynamicConfig;
2324
import io.sermant.backend.entity.config.ConfigCenterType;
@@ -31,6 +32,7 @@
3132
import io.sermant.implement.service.dynamicconfig.ConfigClient;
3233
import io.sermant.implement.service.dynamicconfig.kie.client.ClientUrlManager;
3334
import io.sermant.implement.service.dynamicconfig.kie.client.kie.KieClient;
35+
import io.sermant.implement.service.dynamicconfig.kie.constants.KieConstants;
3436
import io.sermant.implement.service.dynamicconfig.nacos.NacosClient;
3537
import io.sermant.implement.service.dynamicconfig.nacos.NacosUtils;
3638
import io.sermant.implement.service.dynamicconfig.zookeeper.ZooKeeperClient;
@@ -108,6 +110,9 @@ public Result<List<ConfigInfo>> getConfigList(ConfigInfo request, PluginType plu
108110
String group = entry.getKey();
109111
if (client instanceof NacosClient) {
110112
group = NacosUtils.convertGroup(group);
113+
} else if (client instanceof KieClient) {
114+
group = group.replace(KieConstants.CONNECTOR, KieConstants.SEPARATOR);
115+
group = group.replace(KieConstants.DEFAULT_LABEL_PRE, StringUtils.EMPTY);
111116
}
112117
if (!exactMatchFlag && !handler.verifyConfigurationGroup(group)) {
113118
continue;
@@ -202,7 +207,7 @@ public Result<Boolean> deleteConfig(ConfigInfo request) {
202207
*/
203208
@PostConstruct
204209
public void init() {
205-
if (!dynamicConfig.isDynamicConfigEnable()) {
210+
if (!dynamicConfig.isEnable()) {
206211
return;
207212
}
208213
EXECUTOR_SERVICE.scheduleAtFixedRate(this::reConnection, dynamicConfig.getConnectTimeout(),
@@ -262,7 +267,6 @@ private ConfigClient createNacosClient(String namespace) {
262267
try {
263268
client = new NacosClient(properties);
264269
CONFIG_CLIENT_MAP.put(namespace, client);
265-
return client;
266270
} catch (NacosException e) {
267271
LOGGER.error("Nacos connection exception", e);
268272
}
@@ -280,6 +284,7 @@ private Properties createProperties(String namespace) {
280284
properties.setProperty(PropertyKeyConst.USERNAME, userName);
281285
properties.setProperty(PropertyKeyConst.PASSWORD, password);
282286
}
287+
properties.setProperty(NacosAuthLoginConstant.SERVER, dynamicConfig.getServerAddress());
283288
properties.setProperty(PropertyKeyConst.SERVER_ADDR, dynamicConfig.getServerAddress());
284289
properties.setProperty(PropertyKeyConst.NAMESPACE, namespace);
285290
properties.setProperty(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT,
@@ -294,6 +299,9 @@ private Properties createProperties(String namespace) {
294299
* @return Configuration Center Client
295300
*/
296301
public Result<Boolean> checkConnection(ConfigInfo request) {
302+
if (!dynamicConfig.isEnable()) {
303+
return new Result<>(ResultCodeType.NOT_ENABLE.getCode(), ResultCodeType.NOT_ENABLE.getMessage());
304+
}
297305
ConfigClient client = getConfigClient(request.getNamespace());
298306
if (client == null || !client.isConnect()) {
299307
return new Result<>(ResultCodeType.CONNECT_FAIL.getCode(), ResultCodeType.CONNECT_FAIL.getMessage());

sermant-backend/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ database.fixedDelay=10000
3838
session.expire=60
3939

4040
# Dynamic config service configuration
41-
dynamic.config.dynamicConfigEnable=true
41+
dynamic.config.enable=true
4242
dynamic.config.namespace=default
4343
dynamic.config.timeout=30000
4444
dynamic.config.serverAddress=127.0.0.1:30110

sermant-backend/src/main/webapp/frontend/auto-imports.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
// Generated by unplugin-auto-import
55
export {}
66
declare global {
7-
const ElMessage: typeof import('element-plus/es')['ElMessage']
7+
88
}

sermant-backend/src/main/webapp/frontend/src/composables/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const resultCodes = [
1212
{code: '07', key: 'common.configurationDoesNotExist'},
1313
{code: '08', key: 'common.missingRequestParameters'},
1414
{code: '09', key: 'common.failedToRequest'},
15+
{code: '10', key: 'common.notEnable'},
1516
];
1617

1718
export const resultCodeMap = new Map(resultCodes.map(item => [item.code, i18n.global.t(item.key)]));

sermant-backend/src/main/webapp/frontend/src/composables/translations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ const messages = {
157157
configurationDoesNotExist: 'Configuration does not exist',
158158
missingRequestParameters: 'Missing request parameters',
159159
failedToRequest: 'Failed to request',
160+
notEnable: 'Dynamic configuration switch not turned on',
160161
router: 'router',
161162
springbootRegistry: 'springboot-registry',
162163
serviceRegistry: 'service-registry',
@@ -372,6 +373,7 @@ const messages = {
372373
configurationDoesNotExist: '配置不存在',
373374
missingRequestParameters: '缺少请求参数',
374375
failedToRequest: '请求失败',
376+
notEnable: '动态配置开关未开启',
375377
router: '路由插件',
376378
springbootRegistry: 'springboot注册插件',
377379
serviceRegistry: '注册迁移插件',

sermant-backend/src/main/webapp/frontend/src/views/ConfigInfo.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ import {onMounted, reactive, ref, watch} from "vue";
226226
import {LocationQuery, useRouter} from "vue-router";
227227
import axios from "axios";
228228
import TooltipIcon from '../components/layouts/TooltipIcon.vue'
229-
import {ElMessage, FormInstance, FormRules} from "element-plus";
229+
import {ElMessage, FormInstance} from "element-plus";
230230
import {options, resultCodeMap} from '~/composables/config'
231231
import i18n from "~/composables/translations";
232232
@@ -315,7 +315,11 @@ const goBack = () => {
315315
316316
const getConfig = () => {
317317
axios.get(`${window.location.origin}/sermant/config`, {
318-
params: requestParam,
318+
params : {
319+
key: requestParam.key,
320+
group: requestParam.group,
321+
namespace: requestParam.namespace
322+
}
319323
}).then(function (response) {
320324
if (response.data.code == "00") {
321325
requestParam.content = response.data.data.content;

sermant-backend/src/test/java/io/sermant/backend/service/ConfigServiceTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public void setUp() {
7777
PowerMockito.when(configClient.getConfig(KEY, GROUP)).thenReturn(CONTENT);
7878
PowerMockito.when(configClient.publishConfig(KEY, GROUP, CONTENT)).thenReturn(true);
7979
PowerMockito.when(configClient.removeConfig(KEY, GROUP)).thenReturn(true);
80+
PowerMockito.when(dynamicConfig.isEnable()).thenReturn(true);
8081
}
8182

8283
@Test

0 commit comments

Comments
 (0)