Skip to content

Commit

Permalink
Improve logic for configuring the heartbeat API path in TransportConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Zhao <[email protected]>
  • Loading branch information
sczyh30 committed Dec 10, 2019
1 parent 9beb655 commit 9d02e84
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,20 @@ public static String getHeartbeatClientIp() {
}

/**
* Get dashboard heartbeat api path.
* If the context path not configured,it will be the default api path
* Get the heartbeat api path. If the machine registry path of the dashboard
* is modified, then the API path should also be consistent with the API path of the dashboard.
*
* @return api path.
* @return the heartbeat api path
* @since 1.7.1
*/
public static String getHeartbeatApiPath() {
String apiPath = SentinelConfig.getConfig(HEARTBEAT_API_PATH);
if (StringUtil.isBlank(apiPath)) {
return HEARTBEAT_DEFAULT_PATH;
}
return apiPath + HEARTBEAT_DEFAULT_PATH;
if (!apiPath.startsWith("/")) {
apiPath = "/" + apiPath;
}
return apiPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,20 @@ public void testGetHeartbeatClientIp() {
}

@Test
public void getHeartbeatApiPath() {
public void testGetHeartbeatApiPath() {
// use default heartbeat api path
assertTrue(StringUtil.isNotEmpty(TransportConfig.getHeartbeatApiPath()));
assertEquals(TransportConfig.HEARTBEAT_DEFAULT_PATH, TransportConfig.getHeartbeatApiPath());

// config heartbeat api path
SentinelConfig.setConfig(TransportConfig.HEARTBEAT_API_PATH, "/demo");
assertTrue(StringUtil.isNotEmpty(TransportConfig.getHeartbeatApiPath()));
assertEquals("/demo" + TransportConfig.HEARTBEAT_DEFAULT_PATH, TransportConfig.getHeartbeatApiPath());
assertEquals("/demo", TransportConfig.getHeartbeatApiPath());

SentinelConfig.setConfig(TransportConfig.HEARTBEAT_API_PATH, "demo/registry");
assertEquals("/demo/registry", TransportConfig.getHeartbeatApiPath());

SentinelConfig.removeConfig(TransportConfig.HEARTBEAT_API_PATH);
assertEquals(TransportConfig.HEARTBEAT_DEFAULT_PATH, TransportConfig.getHeartbeatApiPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public boolean sendHeartbeat() throws Exception {
return true;
}
} catch (Exception e) {
RecordLog.warn("[SimpleHttpHeartbeatSender] Failed to send heartbeat to " + addr + " : ", e);
RecordLog.warn("[SimpleHttpHeartbeatSender] Failed to send heartbeat to " + addr, e);
}
return false;
}
Expand Down

0 comments on commit 9d02e84

Please sign in to comment.