浏览代码

Fixes #20: Fix runtime port and heartbeat sending logic

- Sentinel should not send heartbeat to dashboard until the runtime port has been settled down

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao 6 年前
父节点
当前提交
1c9f1606ca
共有 3 个文件被更改,包括 10 次插入4 次删除
  1. +4
    -0
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/transport/config/TransportConfig.java
  2. +1
    -3
      sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java
  3. +5
    -1
      sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/SimpleHttpHeartbeatSender.java

+ 4
- 0
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/transport/config/TransportConfig.java 查看文件

@@ -42,6 +42,10 @@ public class TransportConfig {
return SentinelConfig.getConfig(CONSOLE_SERVER);
}

public static int getRuntimePort() {
return runtimePort;
}

/**
* Get Server port of this HTTP server.
*


+ 1
- 3
sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java 查看文件

@@ -124,9 +124,7 @@ public class SimpleHttpCommandCenter implements CommandCenter {
}
}

if (success) {
tmpPort = port;
} else {
if (!success) {
tmpPort = PORT_UNINITIALIZED;
}
TransportConfig.setRuntimePort(tmpPort);


+ 5
- 1
sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/SimpleHttpHeartbeatSender.java 查看文件

@@ -52,7 +52,7 @@ public class SimpleHttpHeartbeatSender implements HeartbeatSender {
public SimpleHttpHeartbeatSender() {
// Retrieve the list of default addresses.
List<InetSocketAddress> newAddrs = getDefaultConsoleIps();
RecordLog.info("Default console address list retrieved: " + newAddrs);
RecordLog.info("[SimpleHttpHeartbeatSender] Default console address list retrieved: " + newAddrs);
this.addressList = newAddrs;
// Set interval config.
String interval = System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS, String.valueOf(DEFAULT_INTERVAL));
@@ -61,6 +61,10 @@ public class SimpleHttpHeartbeatSender implements HeartbeatSender {

@Override
public boolean sendHeartbeat() throws Exception {
if (TransportConfig.getRuntimePort() <= 0) {
RecordLog.info("[SimpleHttpHeartbeatSender] Runtime port not initialized, won't send heartbeat");
return false;
}
InetSocketAddress addr = getAvailableAddress();
if (addr == null) {
return false;


正在加载...
取消
保存