Polish placeholders in logging content to slf4j convention (#1342)
* Polish placeholders in logging content to "{}"
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
This commit is contained in:
parent
e4769293dc
commit
eed77cafc2
|
|
@ -62,8 +62,8 @@ public final class GatewayApiDefinitionManager {
|
||||||
List<ApiDefinitionChangeObserver> listeners = SpiLoader.loadInstanceList(ApiDefinitionChangeObserver.class);
|
List<ApiDefinitionChangeObserver> listeners = SpiLoader.loadInstanceList(ApiDefinitionChangeObserver.class);
|
||||||
for (ApiDefinitionChangeObserver e : listeners) {
|
for (ApiDefinitionChangeObserver e : listeners) {
|
||||||
API_CHANGE_OBSERVERS.put(e.getClass().getCanonicalName(), e);
|
API_CHANGE_OBSERVERS.put(e.getClass().getCanonicalName(), e);
|
||||||
RecordLog.info("[GatewayApiDefinitionManager] ApiDefinitionChangeObserver added: {0}",
|
RecordLog.info("[GatewayApiDefinitionManager] ApiDefinitionChangeObserver added: "
|
||||||
e.getClass().getCanonicalName());
|
+ e.getClass().getCanonicalName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ public class UpdateGatewayApiDefinitionGroupCommandHandler implements CommandHan
|
||||||
return CommandResponse.ofFailure(e, "decode gateway API definition data error");
|
return CommandResponse.ofFailure(e, "decode gateway API definition data error");
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordLog.info("[API Server] Receiving data change (type: gateway API definition): {0}", data);
|
RecordLog.info("[API Server] Receiving data change (type: gateway API definition): {}", data);
|
||||||
|
|
||||||
String result = SUCCESS_MSG;
|
String result = SUCCESS_MSG;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ public abstract class AbstractSentinelInterceptor implements HandlerInterceptor
|
||||||
protected void setEntryInRequest(HttpServletRequest request, String name, Entry entry) {
|
protected void setEntryInRequest(HttpServletRequest request, String name, Entry entry) {
|
||||||
Object attrVal = request.getAttribute(name);
|
Object attrVal = request.getAttribute(name);
|
||||||
if (attrVal != null) {
|
if (attrVal != null) {
|
||||||
RecordLog.warn("[{}] The attribute key '{0}' already exists in request, please set `requestAttributeName`",
|
RecordLog.warn("[{}] The attribute key '{}' already exists in request, please set `requestAttributeName`",
|
||||||
getClass().getSimpleName(), name);
|
getClass().getSimpleName(), name);
|
||||||
} else {
|
} else {
|
||||||
request.setAttribute(name, entry);
|
request.setAttribute(name, entry);
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ public class DefaultRequestEntityWriter implements RequestEntityWriter<ClusterRe
|
||||||
EntityWriter<Object, ByteBuf> requestDataWriter = RequestDataWriterRegistry.getWriter(type);
|
EntityWriter<Object, ByteBuf> requestDataWriter = RequestDataWriterRegistry.getWriter(type);
|
||||||
|
|
||||||
if (requestDataWriter == null) {
|
if (requestDataWriter == null) {
|
||||||
RecordLog.warn("[DefaultRequestEntityWriter] Cannot find matching request writer for type <{0}>,"
|
RecordLog.warn("[DefaultRequestEntityWriter] Cannot find matching request writer for type <{}>,"
|
||||||
+ " dropping the request", type);
|
+ " dropping the request", type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ public class DefaultResponseEntityDecoder implements ResponseEntityDecoder<ByteB
|
||||||
|
|
||||||
EntityDecoder<ByteBuf, ?> decoder = ResponseDataDecodeRegistry.getDecoder(type);
|
EntityDecoder<ByteBuf, ?> decoder = ResponseDataDecodeRegistry.getDecoder(type);
|
||||||
if (decoder == null) {
|
if (decoder == null) {
|
||||||
RecordLog.warn("Unknown type of response data decoder: {0}", type);
|
RecordLog.warn("Unknown type of response data decoder: {}", type);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,10 +76,10 @@ public class TokenClientHandler extends ChannelInboundHandlerAdapter {
|
||||||
private void handlePingResponse(ChannelHandlerContext ctx, ClusterResponse response) {
|
private void handlePingResponse(ChannelHandlerContext ctx, ClusterResponse response) {
|
||||||
if (response.getStatus() == ClusterConstants.RESPONSE_STATUS_OK) {
|
if (response.getStatus() == ClusterConstants.RESPONSE_STATUS_OK) {
|
||||||
int count = (int) response.getData();
|
int count = (int) response.getData();
|
||||||
RecordLog.info("[TokenClientHandler] Client ping OK (target server: {0}, connected count: {1})",
|
RecordLog.info("[TokenClientHandler] Client ping OK (target server: {}, connected count: {})",
|
||||||
getRemoteAddress(ctx), count);
|
getRemoteAddress(ctx), count);
|
||||||
} else {
|
} else {
|
||||||
RecordLog.warn("[TokenClientHandler] Client ping failed (target server: {0})", getRemoteAddress(ctx));
|
RecordLog.warn("[TokenClientHandler] Client ping failed (target server: {})", getRemoteAddress(ctx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ public final class ClusterFlowRuleManager {
|
||||||
}
|
}
|
||||||
synchronized (UPDATE_LOCK) {
|
synchronized (UPDATE_LOCK) {
|
||||||
RecordLog.info("[ClusterFlowRuleManager] Registering new property to cluster flow rule manager"
|
RecordLog.info("[ClusterFlowRuleManager] Registering new property to cluster flow rule manager"
|
||||||
+ " for namespace <{0}>", namespace);
|
+ " for namespace <{}>", namespace);
|
||||||
registerPropertyInternal(namespace, property);
|
registerPropertyInternal(namespace, property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +180,7 @@ public final class ClusterFlowRuleManager {
|
||||||
PROPERTY_MAP.remove(namespace);
|
PROPERTY_MAP.remove(namespace);
|
||||||
}
|
}
|
||||||
RecordLog.info("[ClusterFlowRuleManager] Removing property from cluster flow rule manager"
|
RecordLog.info("[ClusterFlowRuleManager] Removing property from cluster flow rule manager"
|
||||||
+ " for namespace <{0}>", namespace);
|
+ " for namespace <{}>", namespace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -380,14 +380,14 @@ public final class ClusterFlowRuleManager {
|
||||||
@Override
|
@Override
|
||||||
public synchronized void configUpdate(List<FlowRule> conf) {
|
public synchronized void configUpdate(List<FlowRule> conf) {
|
||||||
applyClusterFlowRule(conf, namespace);
|
applyClusterFlowRule(conf, namespace);
|
||||||
RecordLog.info("[ClusterFlowRuleManager] Cluster flow rules received for namespace <{0}>: {1}",
|
RecordLog.info("[ClusterFlowRuleManager] Cluster flow rules received for namespace <{}>: {}",
|
||||||
namespace, FLOW_RULES);
|
namespace, FLOW_RULES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void configLoad(List<FlowRule> conf) {
|
public synchronized void configLoad(List<FlowRule> conf) {
|
||||||
applyClusterFlowRule(conf, namespace);
|
applyClusterFlowRule(conf, namespace);
|
||||||
RecordLog.info("[ClusterFlowRuleManager] Cluster flow rules loaded for namespace <{0}>: {1}",
|
RecordLog.info("[ClusterFlowRuleManager] Cluster flow rules loaded for namespace <{}>: {}",
|
||||||
namespace, FLOW_RULES);
|
namespace, FLOW_RULES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ public final class ClusterParamFlowRuleManager {
|
||||||
}
|
}
|
||||||
synchronized (UPDATE_LOCK) {
|
synchronized (UPDATE_LOCK) {
|
||||||
RecordLog.info("[ClusterParamFlowRuleManager] Registering new property to cluster param rule manager"
|
RecordLog.info("[ClusterParamFlowRuleManager] Registering new property to cluster param rule manager"
|
||||||
+ " for namespace <{0}>", namespace);
|
+ " for namespace <{}>", namespace);
|
||||||
registerPropertyInternal(namespace, property);
|
registerPropertyInternal(namespace, property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -167,7 +167,7 @@ public final class ClusterParamFlowRuleManager {
|
||||||
PROPERTY_MAP.remove(namespace);
|
PROPERTY_MAP.remove(namespace);
|
||||||
}
|
}
|
||||||
RecordLog.info("[ClusterParamFlowRuleManager] Removing property from cluster flow rule manager"
|
RecordLog.info("[ClusterParamFlowRuleManager] Removing property from cluster flow rule manager"
|
||||||
+ " for namespace <{0}>", namespace);
|
+ " for namespace <{}>", namespace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -303,14 +303,14 @@ public final class ClusterParamFlowRuleManager {
|
||||||
@Override
|
@Override
|
||||||
public void configLoad(List<ParamFlowRule> conf) {
|
public void configLoad(List<ParamFlowRule> conf) {
|
||||||
applyClusterParamRules(conf, namespace);
|
applyClusterParamRules(conf, namespace);
|
||||||
RecordLog.info("[ClusterParamFlowRuleManager] Cluster parameter rules loaded for namespace <{0}>: {1}",
|
RecordLog.info("[ClusterParamFlowRuleManager] Cluster parameter rules loaded for namespace <{}>: {}",
|
||||||
namespace, PARAM_RULES);
|
namespace, PARAM_RULES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configUpdate(List<ParamFlowRule> conf) {
|
public void configUpdate(List<ParamFlowRule> conf) {
|
||||||
applyClusterParamRules(conf, namespace);
|
applyClusterParamRules(conf, namespace);
|
||||||
RecordLog.info("[ClusterParamFlowRuleManager] Cluster parameter rules received for namespace <{0}>: {1}",
|
RecordLog.info("[ClusterParamFlowRuleManager] Cluster parameter rules received for namespace <{}>: {}",
|
||||||
namespace, PARAM_RULES);
|
namespace, PARAM_RULES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ public class DefaultRequestEntityDecoder implements RequestEntityDecoder<ByteBuf
|
||||||
|
|
||||||
EntityDecoder<ByteBuf, ?> dataDecoder = RequestDataDecodeRegistry.getDecoder(type);
|
EntityDecoder<ByteBuf, ?> dataDecoder = RequestDataDecodeRegistry.getDecoder(type);
|
||||||
if (dataDecoder == null) {
|
if (dataDecoder == null) {
|
||||||
RecordLog.warn("Unknown type of request data decoder: {0}", type);
|
RecordLog.warn("Unknown type of request data decoder: {}", type);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public class DefaultResponseEntityWriter implements ResponseEntityWriter<Cluster
|
||||||
|
|
||||||
if (responseDataWriter == null) {
|
if (responseDataWriter == null) {
|
||||||
writeHead(response.setStatus(ClusterConstants.RESPONSE_STATUS_BAD), out);
|
writeHead(response.setStatus(ClusterConstants.RESPONSE_STATUS_BAD), out);
|
||||||
RecordLog.warn("[NettyResponseEncoder] Cannot find matching writer for type <{0}>", response.getType());
|
RecordLog.warn("[NettyResponseEncoder] Cannot find matching writer for type <{}>", response.getType());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
writeHead(response, out);
|
writeHead(response, out);
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ public class ModifyClusterFlowRulesCommandHandler implements CommandHandler<Stri
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
data = URLDecoder.decode(data, "UTF-8");
|
data = URLDecoder.decode(data, "UTF-8");
|
||||||
RecordLog.info("[ModifyClusterFlowRulesCommandHandler] Receiving cluster flow rules for namespace <{0}>: {1}", namespace, data);
|
RecordLog.info("[ModifyClusterFlowRulesCommandHandler] Receiving cluster flow rules for namespace <{}>: {}", namespace, data);
|
||||||
|
|
||||||
List<FlowRule> flowRules = JSONArray.parseArray(data, FlowRule.class);
|
List<FlowRule> flowRules = JSONArray.parseArray(data, FlowRule.class);
|
||||||
ClusterFlowRuleManager.loadRules(namespace, flowRules);
|
ClusterFlowRuleManager.loadRules(namespace, flowRules);
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ public class ModifyClusterParamFlowRulesCommandHandler implements CommandHandler
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
data = URLDecoder.decode(data, "UTF-8");
|
data = URLDecoder.decode(data, "UTF-8");
|
||||||
RecordLog.info("[ModifyClusterParamFlowRulesCommandHandler] Receiving cluster param rules for namespace <{0}>: {1}", namespace, data);
|
RecordLog.info("Receiving cluster param rules for namespace <{}> from command handler: {}", namespace, data);
|
||||||
|
|
||||||
List<ParamFlowRule> flowRules = JSONArray.parseArray(data, ParamFlowRule.class);
|
List<ParamFlowRule> flowRules = JSONArray.parseArray(data, ParamFlowRule.class);
|
||||||
ClusterParamFlowRuleManager.loadRules(namespace, flowRules);
|
ClusterParamFlowRuleManager.loadRules(namespace, flowRules);
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ public class ModifyClusterServerFlowConfigHandler implements CommandHandler<Stri
|
||||||
}
|
}
|
||||||
ClusterServerConfigManager.loadGlobalFlowConfig(config);
|
ClusterServerConfigManager.loadGlobalFlowConfig(config);
|
||||||
} else {
|
} else {
|
||||||
RecordLog.info("[ModifyClusterServerFlowConfigHandler] Receiving cluster server flow config for namespace <{0}>: {1}", namespace, data);
|
RecordLog.info("[ModifyClusterServerFlowConfigHandler] Receiving cluster server flow config for namespace <{}>: {}", namespace, data);
|
||||||
ServerFlowConfig config = JSON.parseObject(data, ServerFlowConfig.class);
|
ServerFlowConfig config = JSON.parseObject(data, ServerFlowConfig.class);
|
||||||
if (!ClusterServerConfigManager.isValidFlowConfig(config)) {
|
if (!ClusterServerConfigManager.isValidFlowConfig(config)) {
|
||||||
CommandResponse.ofFailure(new IllegalArgumentException("Bad flow config"));
|
CommandResponse.ofFailure(new IllegalArgumentException("Bad flow config"));
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ public final class ConnectionManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
group.removeConnection(address);
|
group.removeConnection(address);
|
||||||
RecordLog.info("[ConnectionManager] Client <{0}> disconnected and removed from namespace <{1}>", address, namespace);
|
RecordLog.info("[ConnectionManager] Client <{}> disconnected and removed from namespace <{}>", address, namespace);
|
||||||
}
|
}
|
||||||
NAMESPACE_MAP.remove(address);
|
NAMESPACE_MAP.remove(address);
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +87,7 @@ public final class ConnectionManager {
|
||||||
}
|
}
|
||||||
group.removeConnection(address);
|
group.removeConnection(address);
|
||||||
NAMESPACE_MAP.remove(address);
|
NAMESPACE_MAP.remove(address);
|
||||||
RecordLog.info("[ConnectionManager] Client <{0}> disconnected and removed from namespace <{1}>", address, namespace);
|
RecordLog.info("[ConnectionManager] Client <{}> disconnected and removed from namespace <{}>", address, namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConnectionGroup addConnection(String namespace, String address) {
|
public static ConnectionGroup addConnection(String namespace, String address) {
|
||||||
|
|
@ -96,7 +96,7 @@ public final class ConnectionManager {
|
||||||
ConnectionGroup group = getOrCreateGroup(namespace);
|
ConnectionGroup group = getOrCreateGroup(namespace);
|
||||||
group.addConnection(address);
|
group.addConnection(address);
|
||||||
NAMESPACE_MAP.put(address, namespace);
|
NAMESPACE_MAP.put(address, namespace);
|
||||||
RecordLog.info("[ConnectionManager] Client <{0}> registered with namespace <{1}>", address, namespace);
|
RecordLog.info("[ConnectionManager] Client <{}> registered with namespace <{}>", address, namespace);
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ public final class SentinelConfig {
|
||||||
}
|
}
|
||||||
return Integer.parseInt(v);
|
return Integer.parseInt(v);
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
RecordLog.warn("[SentinelConfig] Invalid statisticMaxRt value: {0}, using the default value instead: "
|
RecordLog.warn("[SentinelConfig] Invalid statisticMaxRt value: {}, using the default value instead: "
|
||||||
+ DEFAULT_STATISTIC_MAX_RT, v, throwable);
|
+ DEFAULT_STATISTIC_MAX_RT, v, throwable);
|
||||||
SentinelConfig.setConfig(STATISTIC_MAX_RT, String.valueOf(DEFAULT_STATISTIC_MAX_RT));
|
SentinelConfig.setConfig(STATISTIC_MAX_RT, String.valueOf(DEFAULT_STATISTIC_MAX_RT));
|
||||||
return DEFAULT_STATISTIC_MAX_RT;
|
return DEFAULT_STATISTIC_MAX_RT;
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ public final class SentinelConfigLoader {
|
||||||
String oldConfigValue = properties.getProperty(configKey);
|
String oldConfigValue = properties.getProperty(configKey);
|
||||||
properties.put(configKey, newConfigValue);
|
properties.put(configKey, newConfigValue);
|
||||||
if (oldConfigValue != null) {
|
if (oldConfigValue != null) {
|
||||||
RecordLog.info("[SentinelConfigLoader] JVM parameter overrides {0}: {1} -> {2}",
|
RecordLog.info("[SentinelConfigLoader] JVM parameter overrides {}: {} -> {}",
|
||||||
configKey, oldConfigValue, newConfigValue);
|
configKey, oldConfigValue, newConfigValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ public class DefaultNode extends StatisticNode {
|
||||||
*/
|
*/
|
||||||
public void addChild(Node node) {
|
public void addChild(Node node) {
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
RecordLog.warn("Trying to add null child to node <{0}>, ignored", id.getName());
|
RecordLog.warn("Trying to add null child to node <{}>, ignored", id.getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!childList.contains(node)) {
|
if (!childList.contains(node)) {
|
||||||
|
|
@ -91,7 +91,7 @@ public class DefaultNode extends StatisticNode {
|
||||||
childList = newSet;
|
childList = newSet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RecordLog.info("Add child <{0}> to node <{1}>", ((DefaultNode)node).id.getName(), id.getName());
|
RecordLog.info("Add child <{}> to node <{}>", ((DefaultNode)node).id.getName(), id.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -280,7 +280,7 @@ public abstract class AbstractSentinelAspectSupport {
|
||||||
&& returnType.isAssignableFrom(method.getReturnType())
|
&& returnType.isAssignableFrom(method.getReturnType())
|
||||||
&& Arrays.equals(parameterTypes, method.getParameterTypes())) {
|
&& Arrays.equals(parameterTypes, method.getParameterTypes())) {
|
||||||
|
|
||||||
RecordLog.info("Resolved method [{0}] in class [{1}]", name, clazz.getCanonicalName());
|
RecordLog.info("Resolved method [{}] in class [{}]", name, clazz.getCanonicalName());
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -290,7 +290,7 @@ public abstract class AbstractSentinelAspectSupport {
|
||||||
return findMethod(mustStatic, superClass, name, returnType, parameterTypes);
|
return findMethod(mustStatic, superClass, name, returnType, parameterTypes);
|
||||||
} else {
|
} else {
|
||||||
String methodType = mustStatic ? " static" : "";
|
String methodType = mustStatic ? " static" : "";
|
||||||
RecordLog.warn("Cannot find{0} method [{1}] in class [{2}] with parameters {3}",
|
RecordLog.warn("Cannot find{} method [{}] in class [{}] with parameters {}",
|
||||||
methodType, name, clazz.getCanonicalName(), Arrays.toString(parameterTypes));
|
methodType, name, clazz.getCanonicalName(), Arrays.toString(parameterTypes));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -157,11 +157,11 @@ public class ConsulDataSource<T> extends AbstractDataSource<String, T> {
|
||||||
String newValue = getValue.getDecodedValue();
|
String newValue = getValue.getDecodedValue();
|
||||||
try {
|
try {
|
||||||
getProperty().updateValue(parser.convert(newValue));
|
getProperty().updateValue(parser.convert(newValue));
|
||||||
RecordLog.info("[ConsulDataSource] New property value received for ({0}, {1}): {2}",
|
RecordLog.info("[ConsulDataSource] New property value received for ({}, {}): {}",
|
||||||
address, ruleKey, newValue);
|
address, ruleKey, newValue);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
// In case of parsing error.
|
// In case of parsing error.
|
||||||
RecordLog.warn("[ConsulDataSource] Failed to update value for ({0}, {1}), raw value: {2}",
|
RecordLog.warn("[ConsulDataSource] Failed to update value for ({}, {}), raw value: {}",
|
||||||
address, ruleKey, newValue);
|
address, ruleKey, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ public class EtcdDataSource<T> extends AbstractDataSource<String, T> {
|
||||||
RecordLog.warn("[EtcdDataSource] Failed to update config", e);
|
RecordLog.warn("[EtcdDataSource] Failed to update config", e);
|
||||||
}
|
}
|
||||||
} else if (eventType == WatchEvent.EventType.DELETE) {
|
} else if (eventType == WatchEvent.EventType.DELETE) {
|
||||||
RecordLog.info("[EtcdDataSource] Cleaning config for key <{0}>", key);
|
RecordLog.info("[EtcdDataSource] Cleaning config for key <{}>", key);
|
||||||
getProperty().updateValue(null);
|
getProperty().updateValue(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright 1999-2019 Alibaba Group Holding Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
package com.alibaba.csp.sentinel.datasource.spring.cloud.config;
|
package com.alibaba.csp.sentinel.datasource.spring.cloud.config;
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.log.RecordLog;
|
import com.alibaba.csp.sentinel.log.RecordLog;
|
||||||
|
|
||||||
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
|
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
|
||||||
import org.springframework.cloud.config.client.ConfigClientProperties;
|
import org.springframework.cloud.config.client.ConfigClientProperties;
|
||||||
import org.springframework.cloud.config.client.ConfigClientStateHolder;
|
import org.springframework.cloud.config.client.ConfigClientStateHolder;
|
||||||
|
|
@ -38,10 +54,11 @@ import static org.springframework.cloud.config.client.ConfigClientProperties.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* {@link SentinelRuleLocator} which pull sentinel rules from remote server.
|
* {@link SentinelRuleLocator} which pulls Sentinel rules from remote server.
|
||||||
* It retrieve configurations of spring-cloud-config client configurations from {@link org.springframework.core.env.Environment}
|
* It retrieves configurations of spring-cloud-config client configurations from
|
||||||
* Such as spring.cloud.config.uri=uri, spring.cloud.config.profile=profile .... and so on.
|
* {@link org.springframework.core.env.Environment}, such as {@code spring.cloud.config.uri=uri},
|
||||||
* When pull rules successfully, save to {@link SentinelRuleStorage} for ${@link SpringCloudConfigDataSource} retrieve.
|
* {@code spring.cloud.config.profile=profile}, and so on.
|
||||||
|
* When rules are pulled successfully, it will be stored to {@link SentinelRuleStorage}.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author lianglin
|
* @author lianglin
|
||||||
|
|
@ -50,17 +67,16 @@ import static org.springframework.cloud.config.client.ConfigClientProperties.*;
|
||||||
@Order(0)
|
@Order(0)
|
||||||
public class SentinelRuleLocator implements PropertySourceLocator {
|
public class SentinelRuleLocator implements PropertySourceLocator {
|
||||||
|
|
||||||
|
|
||||||
private RestTemplate restTemplate;
|
private RestTemplate restTemplate;
|
||||||
private ConfigClientProperties defaultProperties;
|
private ConfigClientProperties defaultProperties;
|
||||||
private org.springframework.core.env.Environment environment;
|
private org.springframework.core.env.Environment environment;
|
||||||
|
|
||||||
public SentinelRuleLocator(ConfigClientProperties defaultProperties, org.springframework.core.env.Environment environment) {
|
public SentinelRuleLocator(ConfigClientProperties defaultProperties,
|
||||||
|
org.springframework.core.env.Environment environment) {
|
||||||
this.defaultProperties = defaultProperties;
|
this.defaultProperties = defaultProperties;
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responsible for pull data from remote server
|
* Responsible for pull data from remote server
|
||||||
*
|
*
|
||||||
|
|
@ -107,8 +123,7 @@ public class SentinelRuleLocator implements PropertySourceLocator {
|
||||||
}
|
}
|
||||||
} catch (HttpServerErrorException e) {
|
} catch (HttpServerErrorException e) {
|
||||||
error = e;
|
error = e;
|
||||||
if (MediaType.APPLICATION_JSON
|
if (MediaType.APPLICATION_JSON.includes(e.getResponseHeaders().getContentType())) {
|
||||||
.includes(e.getResponseHeaders().getContentType())) {
|
|
||||||
errorBody = e.getResponseBodyAsString();
|
errorBody = e.getResponseBodyAsString();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -135,8 +150,7 @@ public class SentinelRuleLocator implements PropertySourceLocator {
|
||||||
RecordLog.info(String.format(
|
RecordLog.info(String.format(
|
||||||
"Located environment: name=%s, profiles=%s, label=%s, version=%s, state=%s",
|
"Located environment: name=%s, profiles=%s, label=%s, version=%s, state=%s",
|
||||||
result.getName(),
|
result.getName(),
|
||||||
result.getProfiles() == null ? ""
|
result.getProfiles() == null ? "" : Arrays.asList(result.getProfiles()),
|
||||||
: Arrays.asList(result.getProfiles()),
|
|
||||||
result.getLabel(), result.getVersion(), result.getState()));
|
result.getLabel(), result.getVersion(), result.getState()));
|
||||||
|
|
||||||
List<PropertySource> propertySourceList = result.getPropertySources();
|
List<PropertySource> propertySourceList = result.getPropertySources();
|
||||||
|
|
@ -145,16 +159,11 @@ public class SentinelRuleLocator implements PropertySourceLocator {
|
||||||
for (PropertySource propertySource : propertySourceList) {
|
for (PropertySource propertySource : propertySourceList) {
|
||||||
propertyCount += propertySource.getSource().size();
|
propertyCount += propertySource.getSource().size();
|
||||||
}
|
}
|
||||||
RecordLog.info(String.format(
|
RecordLog.info("[SentinelRuleLocator] Environment {} has {} property sources with {} properties",
|
||||||
"Environment %s has %d property sources with %d properties.",
|
result.getName(), result.getPropertySources().size(), propertyCount);
|
||||||
result.getName(), result.getPropertySources().size(),
|
|
||||||
propertyCount));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Environment getRemoteEnvironment(RestTemplate restTemplate,
|
private Environment getRemoteEnvironment(RestTemplate restTemplate,
|
||||||
ConfigClientProperties properties, String label, String state) {
|
ConfigClientProperties properties, String label, String state) {
|
||||||
String path = "/{name}/{profile}";
|
String path = "/{name}/{profile}";
|
||||||
|
|
@ -163,10 +172,11 @@ public class SentinelRuleLocator implements PropertySourceLocator {
|
||||||
String token = properties.getToken();
|
String token = properties.getToken();
|
||||||
int noOfUrls = properties.getUri().length;
|
int noOfUrls = properties.getUri().length;
|
||||||
if (noOfUrls > 1) {
|
if (noOfUrls > 1) {
|
||||||
RecordLog.info("Multiple Config Server Urls found listed.");
|
RecordLog.debug("[SentinelRuleLocator] Multiple Config Server Urls found listed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordLog.info("properties = {0},label={1}, state={2}", properties, label, state);
|
RecordLog.info("[SentinelRuleLocator] getRemoteEnvironment, properties={}, label={}, state={}",
|
||||||
|
properties, label, state);
|
||||||
|
|
||||||
Object[] args = new String[] {name, profile};
|
Object[] args = new String[] {name, profile};
|
||||||
if (StringUtils.hasText(label)) {
|
if (StringUtils.hasText(label)) {
|
||||||
|
|
@ -184,7 +194,7 @@ public class SentinelRuleLocator implements PropertySourceLocator {
|
||||||
String username = credentials.getUsername();
|
String username = credentials.getUsername();
|
||||||
String password = credentials.getPassword();
|
String password = credentials.getPassword();
|
||||||
|
|
||||||
RecordLog.info("Fetching config from server at : " + uri);
|
RecordLog.info("[SentinelRuleLocator] Fetching config from server at: " + uri);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
|
@ -204,8 +214,8 @@ public class SentinelRuleLocator implements PropertySourceLocator {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} catch (ResourceAccessException e) {
|
} catch (ResourceAccessException e) {
|
||||||
RecordLog.info("Connect Timeout Exception on Url - " + uri
|
RecordLog.warn("[SentinelRuleLocator] ConnectTimeoutException on url <{}>."
|
||||||
+ ". Will be trying the next url if available");
|
+ " Will be trying the next url if available", uri);
|
||||||
if (i == noOfUrls - 1) {
|
if (i == noOfUrls - 1) {
|
||||||
throw e;
|
throw e;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -224,7 +234,6 @@ public class SentinelRuleLocator implements PropertySourceLocator {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private RestTemplate getSecureRestTemplate(ConfigClientProperties client) {
|
private RestTemplate getSecureRestTemplate(ConfigClientProperties client) {
|
||||||
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
|
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
|
||||||
if (client.getRequestReadTimeout() < 0) {
|
if (client.getRequestReadTimeout() < 0) {
|
||||||
|
|
@ -267,7 +276,6 @@ public class SentinelRuleLocator implements PropertySourceLocator {
|
||||||
this.restTemplate = restTemplate;
|
this.restTemplate = restTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class GenericRequestHeaderInterceptor
|
public static class GenericRequestHeaderInterceptor
|
||||||
implements ClientHttpRequestInterceptor {
|
implements ClientHttpRequestInterceptor {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue