Skip to content

Commit

Permalink
improve the code quality for naming healthcheck (#5932)
Browse files Browse the repository at this point in the history
  • Loading branch information
li-xiao-shuang committed Jun 3, 2021
1 parent e199a5e commit 7a7f267
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ public class FieldsConstants {

public static final String HEALTH_CHECKER = "healthChecker";

public static final String IP = "ip";

public static final String PORT = "port";

public static final String CLUSTER_NAME = "clusterName";

public static final String SERVICE_NAME = "serviceName";

public static final String EPHEMERAL = "ephemeral";

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.alibaba.nacos.common.utils.InternetAddressUtil;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.naming.consistency.KeyBuilder;
import com.alibaba.nacos.naming.constants.FieldsConstants;
import com.alibaba.nacos.naming.core.DistroMapper;
import com.alibaba.nacos.naming.core.Instance;
import com.alibaba.nacos.naming.core.Service;
Expand Down Expand Up @@ -48,6 +49,8 @@ public class ClientBeatCheckTask implements BeatCheckTask {

private Service service;

public static final String EPHEMERAL = "true";

public ClientBeatCheckTask(Service service) {
this.service = service;
}
Expand Down Expand Up @@ -138,12 +141,16 @@ private void deleteIp(Instance instance) {

try {
NamingProxy.Request request = NamingProxy.Request.newRequest();
request.appendParam("ip", instance.getIp()).appendParam("port", String.valueOf(instance.getPort()))
.appendParam("ephemeral", "true").appendParam("clusterName", instance.getClusterName())
.appendParam("serviceName", service.getName()).appendParam("namespaceId", service.getNamespaceId());
request.appendParam(FieldsConstants.IP, instance.getIp())
.appendParam(FieldsConstants.PORT, String.valueOf(instance.getPort()))
.appendParam(FieldsConstants.EPHEMERAL, EPHEMERAL)
.appendParam(FieldsConstants.CLUSTER_NAME, instance.getClusterName())
.appendParam(FieldsConstants.SERVICE_NAME, service.getName())
.appendParam(FieldsConstants.NAME_SPACE_ID, service.getNamespaceId());

String url = "http://" + InternetAddressUtil.localHostIP() + InternetAddressUtil.IP_PORT_SPLITER + EnvUtil.getPort() + EnvUtil
.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + "/instance?" + request.toUrl();
String url = "http://" + InternetAddressUtil.localHostIP() + InternetAddressUtil.IP_PORT_SPLITER + EnvUtil
.getPort() + EnvUtil.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT
+ UtilsAndCommons.NACOS_NAMING_INSTANCE_CONTEXT + "?" + request.toUrl();

// delete instance asynchronously:
HttpClient.asyncHttpDelete(url, null, null, new Callback<String>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
* Thread to update ephemeral instance triggered by client beat for v1.x.
Expand All @@ -36,8 +35,6 @@
*/
public class ClientBeatProcessor implements BeatProcessor {

public static final long CLIENT_BEAT_TIMEOUT = TimeUnit.SECONDS.toMillis(15);

private RsInfo rsInfo;

private Service service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void run() {
HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) client.getInstancePublishInfo(service);
if (instance.getIp().equals(ip) && instance.getPort() == port) {
if (Loggers.EVT_LOG.isDebugEnabled()) {
Loggers.EVT_LOG.debug("[CLIENT-BEAT] refresh beat: {}", rsInfo.toString());
Loggers.EVT_LOG.debug("[CLIENT-BEAT] refresh beat: {}", rsInfo);
}
instance.setLastHeartBeatTime(System.currentTimeMillis());
if (!instance.isHealthy()) {
Expand Down

0 comments on commit 7a7f267

Please sign in to comment.