Skip to content

Commit

Permalink
Support config from system env in SentinelConfig and polish Transport…
Browse files Browse the repository at this point in the history
…Config (alibaba#2154)

- An improved method for obtaining IP address and port number from containers
  • Loading branch information
goodjava authored and taz committed Aug 16, 2021
1 parent 3607a2f commit 51a65e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ public static String getConfig(String key) {
AssertUtil.notNull(key, "key cannot be null");
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) {
AssertUtil.notNull(key, "key cannot be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static String getPort() {
if (runtimePort > 0) {
return String.valueOf(runtimePort);
}
return SentinelConfig.getConfig(SERVER_PORT);
return SentinelConfig.getConfig(SERVER_PORT, true);
}

/**
Expand All @@ -159,7 +159,7 @@ public static void setRuntimePort(int port) {
* @return the local ip.
*/
public static String getHeartbeatClientIp() {
String ip = SentinelConfig.getConfig(HEARTBEAT_CLIENT_IP);
String ip = SentinelConfig.getConfig(HEARTBEAT_CLIENT_IP, true);
if (StringUtil.isBlank(ip)) {
ip = HostNameUtil.getIp();
}
Expand Down

0 comments on commit 51a65e0

Please sign in to comment.