Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the issue that the KIE configuration fails to be delivered and the configuration of the tag-transmission plugin fails to be queried #1557

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.sermant.core.service.dynamicconfig.common.DynamicConfigListener;
import io.sermant.implement.service.dynamicconfig.kie.client.kie.KieConfigEntity;
import io.sermant.implement.service.dynamicconfig.kie.client.kie.KieResponse;
import io.sermant.implement.service.dynamicconfig.kie.constants.KieConstants;
import io.sermant.implement.service.dynamicconfig.kie.listener.SubscriberManager;
import io.sermant.implement.utils.LabelGroupUtils;

Expand Down Expand Up @@ -84,8 +85,8 @@ public boolean addConfigListener(String key, String group, DynamicConfigListener
String newGroup = group;
if (!LabelGroupUtils.isLabelGroup(group)) {
// Add label group judgment to adapt irregular groups
newGroup = LabelGroupUtils
.createLabelGroup(Collections.singletonMap(fixSeparator(group, true), fixSeparator(key, false)));
newGroup = LabelGroupUtils.createLabelGroup(Collections.singletonMap(KieConstants.DEFAULT_GROUP,
fixSeparator(group, true)));
}
return subscriberManager.addConfigListener(key, newGroup, listener, ifNotify);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.sermant.implement.service.dynamicconfig.kie.client.ClientUrlManager;
import io.sermant.implement.service.dynamicconfig.kie.client.http.HttpClient;
import io.sermant.implement.service.dynamicconfig.kie.client.http.HttpResult;
import io.sermant.implement.service.dynamicconfig.kie.constants.KieConstants;
import io.sermant.implement.utils.LabelGroupUtils;

import org.apache.http.HttpStatus;
Expand Down Expand Up @@ -220,8 +221,9 @@ public String getConfig(String key, String group) {
@Override
public Map<String, List<String>> getConfigList(String key, String group, boolean exactMatchFlag) {
final KieResponse kieResponse;
String covertGroup = group.replace(KieConstants.SEPARATOR, KieConstants.CONNECTOR);
if (exactMatchFlag) {
kieResponse = getKieResponse(key, group, exactMatchFlag);
kieResponse = getKieResponse(key, covertGroup, exactMatchFlag);
} else {
kieResponse = getKieResponse(key, null, exactMatchFlag);
}
Expand All @@ -236,7 +238,7 @@ public Map<String, List<String>> getConfigList(String key, String group, boolean
configList.add(entity.getKey());
} else {
String currentConfigGroup = LabelGroupUtils.createLabelGroup(entity.getLabels());
if (currentConfigGroup.contains(group)) {
if (currentConfigGroup.contains(covertGroup)) {
List<String> configList = result.computeIfAbsent(
LabelGroupUtils.createLabelGroup(entity.getLabels()), configKey -> new ArrayList<>());
configList.add(entity.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ public class KieConstants {
*/
public static final String DEFAULT_GROUP_KEY = "_DEFAULT_GROUP_KEY";

/**
* Unsupported delimiter in Group
*/
public static final String SEPARATOR = "/";

/**
* Supported connectors in Group
*/
public static final String CONNECTOR = ".";

/**
* The default key for the label
*/
public static final String DEFAULT_LABEL_PRE = "GROUP=";

/**
* The default key for the label
*/
public static final String DEFAULT_GROUP = "GROUP";

private KieConstants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public class ZooKeeperClient implements ConfigClient {
* ZK path separator
*/
public static final char ZK_PATH_SEPARATOR = '/';

private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperClient.class.getName());

/**
* ZK client
*/
Expand Down Expand Up @@ -166,33 +168,38 @@ private Map<String, List<String>> fuzzyGetConfigListByGroupAndKey(String key, St
if (!ifNodeExist(parentNodePath)) {
return configList;
}
List<String> childList = this.zkClient.getChildren(parentNodePath, false);
for (String child : childList) {
fillChildrenInfo(parentNodePath, configList, nodeName, key);
return configList;
}

private void fillChildrenInfo(String path, Map<String, List<String>> configMap, String nodeName,
String key) throws InterruptedException, KeeperException {
List<String> children = this.zkClient.getChildren(path, false);
children.parallelStream().forEach(child -> {
lilai23 marked this conversation as resolved.
Show resolved Hide resolved
List<String> subChild;
if (!child.contains(nodeName)) {
continue;
return;
}
String childPath;
if (parentNodePath.endsWith(String.valueOf(ZK_PATH_SEPARATOR))) {
childPath = parentNodePath + child;
} else {
childPath = parentNodePath + ZK_PATH_SEPARATOR + child;
String childPath = toPath(child, path);
try {
subChild = this.zkClient.getChildren(childPath, false);
} catch (KeeperException | InterruptedException e) {
return;
}
List<String> subChild = this.zkClient.getChildren(childPath, false);
if (subChild == null || subChild.isEmpty()) {
continue;
return;
}
if (key == null || key.isEmpty()) {
configList.put(childPath.substring(1), subChild);
continue;
configMap.put(childPath.substring(1), subChild);
return;
}
List<String> matchSubChild = subChild.stream().filter(value -> value.contains(key))
.collect(Collectors.toList());
if (matchSubChild.isEmpty()) {
continue;
return;
}
configList.put(childPath.substring(1), matchSubChild);
}
return configList;
configMap.put(childPath.substring(1), matchSubChild);
});
}

private Map<String, List<String>> accurateGetConfigListByGroupAndKey(String key, String group)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.sermant.implement.utils;

import io.sermant.implement.service.dynamicconfig.common.DynamicConstants;
import io.sermant.implement.service.dynamicconfig.kie.constants.KieConstants;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -94,7 +95,8 @@ public static String createLabelGroup(Map<String, String> labels) {
if (group.length() == 0) {
return DynamicConstants.EMPTY_STRING;
}
return group.deleteCharAt(group.length() - 1).toString();
String groupString = group.deleteCharAt(group.length() - 1).toString();
return groupString.replace(KieConstants.SEPARATOR, KieConstants.CONNECTOR);
}

/**
Expand Down Expand Up @@ -131,7 +133,7 @@ public static Map<String, String> resolveGroupLabels(String group) {
if (group == null) {
return result;
}
String curGroup = group;
String curGroup = group.replace(KieConstants.SEPARATOR, KieConstants.SEPARATOR);
if (!isLabelGroup(curGroup)) {
// If the label is not a group (applicable to the ZK configuration center scenario), create a label for
// the group
Expand Down Expand Up @@ -175,7 +177,8 @@ public static String getLabelCondition(String group) {
.append(buildSingleLabel(entry.getKey(), entry.getValue()))
.append(GROUP_SEPARATOR);
}
return finalGroup.deleteCharAt(finalGroup.length() - 1).toString();
String finalGroupStr = finalGroup.deleteCharAt(finalGroup.length() - 1).toString();
return finalGroupStr.replace(KieConstants.SEPARATOR, KieConstants.CONNECTOR);
}

private static String buildSingleLabel(String key, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ public class DynamicConfig {
/**
* Switch for configuration management
*/
@Value("${dynamic.config.dynamicConfigEnable}")
private boolean dynamicConfigEnable;
@Value("${dynamic.config.enable}")
private boolean enable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ public enum ResultCodeType {
/**
* Interface call failed
*/
FAIL("09", "Failure.");
FAIL("09", "Failure."),

/**
* Dynamic configuration switch not turned on
*/
NOT_ENABLE("10", "Dynamic configuration switch not turned on.");

private final String code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.auth.impl.NacosAuthLoginConstant;

import io.sermant.backend.common.conf.DynamicConfig;
import io.sermant.backend.entity.config.ConfigCenterType;
Expand All @@ -31,6 +32,7 @@
import io.sermant.implement.service.dynamicconfig.ConfigClient;
import io.sermant.implement.service.dynamicconfig.kie.client.ClientUrlManager;
import io.sermant.implement.service.dynamicconfig.kie.client.kie.KieClient;
import io.sermant.implement.service.dynamicconfig.kie.constants.KieConstants;
import io.sermant.implement.service.dynamicconfig.nacos.NacosClient;
import io.sermant.implement.service.dynamicconfig.nacos.NacosUtils;
import io.sermant.implement.service.dynamicconfig.zookeeper.ZooKeeperClient;
Expand Down Expand Up @@ -108,6 +110,9 @@ public Result<List<ConfigInfo>> getConfigList(ConfigInfo request, PluginType plu
String group = entry.getKey();
if (client instanceof NacosClient) {
group = NacosUtils.convertGroup(group);
} else if (client instanceof KieClient) {
group = group.replace(KieConstants.CONNECTOR, KieConstants.SEPARATOR);
group = group.replace(KieConstants.DEFAULT_LABEL_PRE, StringUtils.EMPTY);
}
if (!exactMatchFlag && !handler.verifyConfigurationGroup(group)) {
continue;
Expand Down Expand Up @@ -202,7 +207,7 @@ public Result<Boolean> deleteConfig(ConfigInfo request) {
*/
@PostConstruct
public void init() {
if (!dynamicConfig.isDynamicConfigEnable()) {
if (!dynamicConfig.isEnable()) {
return;
}
EXECUTOR_SERVICE.scheduleAtFixedRate(this::reConnection, dynamicConfig.getConnectTimeout(),
Expand Down Expand Up @@ -262,7 +267,6 @@ private ConfigClient createNacosClient(String namespace) {
try {
client = new NacosClient(properties);
CONFIG_CLIENT_MAP.put(namespace, client);
return client;
} catch (NacosException e) {
LOGGER.error("Nacos connection exception", e);
}
Expand All @@ -280,6 +284,7 @@ private Properties createProperties(String namespace) {
properties.setProperty(PropertyKeyConst.USERNAME, userName);
properties.setProperty(PropertyKeyConst.PASSWORD, password);
}
properties.setProperty(NacosAuthLoginConstant.SERVER, dynamicConfig.getServerAddress());
properties.setProperty(PropertyKeyConst.SERVER_ADDR, dynamicConfig.getServerAddress());
properties.setProperty(PropertyKeyConst.NAMESPACE, namespace);
properties.setProperty(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT,
Expand All @@ -294,6 +299,9 @@ private Properties createProperties(String namespace) {
* @return Configuration Center Client
*/
public Result<Boolean> checkConnection(ConfigInfo request) {
if (!dynamicConfig.isEnable()) {
return new Result<>(ResultCodeType.NOT_ENABLE.getCode(), ResultCodeType.NOT_ENABLE.getMessage());
}
ConfigClient client = getConfigClient(request.getNamespace());
if (client == null || !client.isConnect()) {
return new Result<>(ResultCodeType.CONNECT_FAIL.getCode(), ResultCodeType.CONNECT_FAIL.getMessage());
Expand Down
2 changes: 1 addition & 1 deletion sermant-backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ database.fixedDelay=10000
session.expire=60

# Dynamic config service configuration
dynamic.config.dynamicConfigEnable=true
dynamic.config.enable=true
dynamic.config.namespace=default
dynamic.config.timeout=30000
dynamic.config.serverAddress=127.0.0.1:30110
Expand Down
2 changes: 1 addition & 1 deletion sermant-backend/src/main/webapp/frontend/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
// Generated by unplugin-auto-import
export {}
declare global {
const ElMessage: typeof import('element-plus/es')['ElMessage']

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const resultCodes = [
{code: '07', key: 'common.configurationDoesNotExist'},
{code: '08', key: 'common.missingRequestParameters'},
{code: '09', key: 'common.failedToRequest'},
{code: '10', key: 'common.notEnable'},
];

export const resultCodeMap = new Map(resultCodes.map(item => [item.code, i18n.global.t(item.key)]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const messages = {
configurationDoesNotExist: 'Configuration does not exist',
missingRequestParameters: 'Missing request parameters',
failedToRequest: 'Failed to request',
notEnable: 'Dynamic configuration switch not turned on',
router: 'router',
springbootRegistry: 'springboot-registry',
serviceRegistry: 'service-registry',
Expand Down Expand Up @@ -372,6 +373,7 @@ const messages = {
configurationDoesNotExist: '配置不存在',
missingRequestParameters: '缺少请求参数',
failedToRequest: '请求失败',
notEnable: '动态配置开关未开启',
router: '路由插件',
springbootRegistry: 'springboot注册插件',
serviceRegistry: '注册迁移插件',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ import {onMounted, reactive, ref, watch} from "vue";
import {LocationQuery, useRouter} from "vue-router";
import axios from "axios";
import TooltipIcon from '../components/layouts/TooltipIcon.vue'
import {ElMessage, FormInstance, FormRules} from "element-plus";
import {ElMessage, FormInstance} from "element-plus";
import {options, resultCodeMap} from '~/composables/config'
import i18n from "~/composables/translations";

Expand Down Expand Up @@ -315,7 +315,11 @@ const goBack = () => {

const getConfig = () => {
axios.get(`${window.location.origin}/sermant/config`, {
params: requestParam,
params : {
key: requestParam.key,
group: requestParam.group,
namespace: requestParam.namespace
}
}).then(function (response) {
if (response.data.code == "00") {
requestParam.content = response.data.data.content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void setUp() {
PowerMockito.when(configClient.getConfig(KEY, GROUP)).thenReturn(CONTENT);
PowerMockito.when(configClient.publishConfig(KEY, GROUP, CONTENT)).thenReturn(true);
PowerMockito.when(configClient.removeConfig(KEY, GROUP)).thenReturn(true);
PowerMockito.when(dynamicConfig.isEnable()).thenReturn(true);
}

@Test
Expand Down
Loading