improve the code quality for naming healthcheck (#5932)
This commit is contained in:
parent
e199a5ee64
commit
7a7f267ee9
@ -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";
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import com.alibaba.nacos.common.model.RestResult;
|
||||
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;
|
||||
@ -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;
|
||||
}
|
||||
@ -138,12 +141,16 @@ public class ClientBeatCheckTask implements BeatCheckTask {
|
||||
|
||||
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>() {
|
||||
|
@ -27,7 +27,6 @@ import com.alibaba.nacos.naming.push.UdpPushService;
|
||||
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.
|
||||
@ -36,8 +35,6 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class ClientBeatProcessor implements BeatProcessor {
|
||||
|
||||
public static final long CLIENT_BEAT_TIMEOUT = TimeUnit.SECONDS.toMillis(15);
|
||||
|
||||
private RsInfo rsInfo;
|
||||
|
||||
private Service service;
|
||||
|
@ -59,7 +59,7 @@ public class ClientBeatProcessorV2 implements BeatProcessor {
|
||||
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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user