Support config from system env in SentinelConfig and polish TransportConfig (#2154)
- An improved method for obtaining IP address and port number from containers
This commit is contained in:
parent
36b162cc70
commit
0d22aca591
|
|
@ -125,6 +125,24 @@ public final class SentinelConfig {
|
||||||
AssertUtil.notNull(key, "key cannot be null");
|
AssertUtil.notNull(key, "key cannot be null");
|
||||||
return props.get(key);
|
return props.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get config value of the specific key.
|
||||||
|
*
|
||||||
|
* @param key config key
|
||||||
|
* @param envVariableKey Get the value of the environment variable with the given key
|
||||||
|
* @return the config value.
|
||||||
|
*/
|
||||||
|
public static String getConfig(String key, boolean envVariableKey) {
|
||||||
|
AssertUtil.notNull(key, "key cannot be null");
|
||||||
|
if (envVariableKey) {
|
||||||
|
String value = System.getenv(key);
|
||||||
|
if (StringUtil.isNotEmpty(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getConfig(key);
|
||||||
|
}
|
||||||
|
|
||||||
public static void setConfig(String key, String value) {
|
public static void setConfig(String key, String value) {
|
||||||
AssertUtil.notNull(key, "key cannot be null");
|
AssertUtil.notNull(key, "key cannot be null");
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ public class TransportConfig {
|
||||||
if (runtimePort > 0) {
|
if (runtimePort > 0) {
|
||||||
return String.valueOf(runtimePort);
|
return String.valueOf(runtimePort);
|
||||||
}
|
}
|
||||||
return SentinelConfig.getConfig(SERVER_PORT);
|
return SentinelConfig.getConfig(SERVER_PORT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -159,7 +159,7 @@ public class TransportConfig {
|
||||||
* @return the local ip.
|
* @return the local ip.
|
||||||
*/
|
*/
|
||||||
public static String getHeartbeatClientIp() {
|
public static String getHeartbeatClientIp() {
|
||||||
String ip = SentinelConfig.getConfig(HEARTBEAT_CLIENT_IP);
|
String ip = SentinelConfig.getConfig(HEARTBEAT_CLIENT_IP, true);
|
||||||
if (StringUtil.isBlank(ip)) {
|
if (StringUtil.isBlank(ip)) {
|
||||||
ip = HostNameUtil.getIp();
|
ip = HostNameUtil.getIp();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue