fix: fix multiple bugs in tsf. (#1746)

pull/1752/head
shedfreewu 3 weeks ago committed by Haotian Zhang
parent 0fd33bdc1d
commit 4830ec823d

@ -18,6 +18,7 @@
package com.tencent.cloud.polaris.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -163,12 +164,24 @@ public class ConfigurationModifier implements PolarisConfigurationConfigModifier
private void checkAddressAccessible(List<String> configAddresses) {
// check address can connect
configAddresses.forEach(address -> {
String[] ipPort = address.split(":");
String[] ipPort;
// check ipv6 address, format: [ipv6_ip]:port
if (address.contains("[") && address.contains("]")) {
int lastColonIndex = address.lastIndexOf(':');
String port = address.substring(lastColonIndex + 1);
String ip = address.substring(1, lastColonIndex - 1);
ipPort = new String[]{ip, port};
}
else {
ipPort = address.split(":");
}
if (ipPort.length != 2) {
throw new IllegalArgumentException("Config server address (" + address + ") is wrong, please check address like grpc://183.47.111.8:8091.");
}
LOGGER.info("[SCT] Check config server ipPort: {}", Arrays.asList(ipPort));
if (!AddressUtils.accessible(ipPort[0], Integer.parseInt(ipPort[1]), 3000)) {
String errMsg = "Config server address (" + address + ") can not be connected. Please check your config in bootstrap.yml"
+ " with spring.cloud.polaris.address or spring.cloud.polaris.config.address.";

@ -175,10 +175,12 @@ public final class TsfTagUtils {
Map<String, String> tsfDisposableMetadata = new HashMap<>(tagSize);
if (CollectionUtils.isNotEmpty(tsfUserTagList)) {
for (Tag tag : tsfUserTagList) {
if (Tag.ControlFlag.TRANSITIVE.equals(tag.getFlags())) {
if (tag.getFlags() != null && tag.getFlags().contains(Tag.ControlFlag.TRANSITIVE)) {
tsfTransitiveMetadata.put(tag.getKey(), tag.getValue());
}
tsfDisposableMetadata.put(tag.getKey(), tag.getValue());
else {
tsfDisposableMetadata.put(tag.getKey(), tag.getValue());
}
}
mergedTransitiveMetadata.putAll(tsfTransitiveMetadata);
mergedDisposableMetadata.putAll(tsfDisposableMetadata);

@ -90,21 +90,27 @@ public class GatewayConsulConfig {
Response<List<GetValue>> watchResponse = consulClient.getKVValues(keyPrefix,
consulConfigContext.getAclToken(), new QueryParams(consulConfigContext.getWaitTime(), index));
if (watchResponse.getValue() == null) {
gatewayAllResult = loadResponseFromFile();
if (!isFirstLoad) {
refreshAction.run();
}
return;
}
Long newIndex = watchResponse.getConsulIndex();
if (logger.isDebugEnabled()) {
logger.debug("[watch] keyPrefix:{}, index: {}, newIndex: {}", keyPrefix, index, newIndex);
logger.debug("[watch] keyPrefix:{}, index: {}, newIndex: {}, response is empty:{}", keyPrefix, index, newIndex, watchResponse.getValue() == null);
}
boolean change = false;
if (newIndex != null && !Objects.equals(index, newIndex)) {
change = true;
index = newIndex;
}
if (watchResponse.getValue() == null) {
// only load from the cache file when the first load and response is empty.
if (isFirstLoad) {
gatewayAllResult = loadResponseFromFile();
logger.debug("[watch] loadResponseFromFile, keyPrefix: {}", keyPrefix);
}
return;
}
if (change) {
gatewayAllResult = parseGroupResponse(watchResponse);
if (!isFirstLoad) {
refreshAction.run();

@ -311,7 +311,12 @@ public class GatewayConsulRepo {
}
GroupContext groupContext = groups.get(wildcardRule.getGroupId());
groupContext.getRoutes().add(contextRoute);
if (groupContext != null && groupContext.getRoutes() != null) {
groupContext.getRoutes().add(contextRoute);
}
else {
logger.warn("path wildcard rule {} not found in group {}", wildcardRule.getWildCardId(), wildcardRule.getGroupId());
}
}
}
@ -319,8 +324,9 @@ public class GatewayConsulRepo {
contextGatewayProperties.setRoutes(routes);
contextGatewayProperties.setPathRewrites(Optional.ofNullable(pathRewriteResult).map(PathRewriteResult::getResult)
.orElse(new ArrayList<>()));
logger.debug("Gateway config loaded. :{}", JacksonUtils.serialize2Json(contextGatewayProperties));
if (logger.isDebugEnabled()) {
logger.debug("Gateway config loaded. :{}", JacksonUtils.serialize2Json(contextGatewayProperties));
}
contextGatewayPropertiesManager.setPathRewrites(contextGatewayProperties.getPathRewrites());

@ -139,8 +139,8 @@ public final class PluginUtil {
if (path.charAt(0) != '/') {
path = "/" + path;
}
String apiPath = StringUtils.substring(path, StringUtils.ordinalIndexOf(path, "/", 4));
// apiPath is the path of downstream service.
String apiPath = path;
boolean matched = antPathMatcher.match(preTagName, apiPath);
if (matched) {
Map<String, String> pathTagMap = antPathMatcher.extractUriTemplateVariables(preTagName, apiPath);

@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.Map;
import com.tencent.cloud.common.tsf.TsfContextUtils;
import com.tencent.polaris.api.utils.IPAddressUtils;
import com.tencent.polaris.api.utils.StringUtils;
import org.apache.commons.logging.Log;
@ -164,7 +165,7 @@ public final class TsfCoreEnvironmentPostProcessor implements EnvironmentPostPro
defaultProperties.put("spring.cloud.polaris.config.enabled", "true");
defaultProperties.put("spring.cloud.polaris.config.internal-enabled", "false");
defaultProperties.put("spring.cloud.polaris.config.data-source", "consul");
defaultProperties.put("spring.cloud.polaris.config.address", "http://" + tsfConsulIp + ":" + tsfConsulPort);
defaultProperties.put("spring.cloud.polaris.config.address", "http://" + IPAddressUtils.getIpCompatible(tsfConsulIp) + ":" + tsfConsulPort);
defaultProperties.put("spring.cloud.polaris.config.port", tsfConsulPort);
defaultProperties.put("spring.cloud.polaris.config.token", tsfConsulToken);
defaultProperties.put("spring.cloud.polaris.config.groups[0].namespace", "config");

Loading…
Cancel
Save