Search in sources :

Example 6 with HealthCheckInstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.

the class TcpHealthCheckProcessor method process.

@Override
public void process(HealthCheckTaskV2 task, Service service, ClusterMetadata metadata) {
    HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) task.getClient().getInstancePublishInfo(service);
    if (null == instance) {
        return;
    }
    // TODO handle marked(white list) logic like v1.x.
    if (!instance.tryStartCheck()) {
        SRV_LOG.warn("[HEALTH-CHECK-V2] tcp check started before last one finished, service: {} : {} : {}:{}", service.getGroupedServiceName(), instance.getCluster(), instance.getIp(), instance.getPort());
        healthCheckCommon.reEvaluateCheckRT(task.getCheckRtNormalized() * 2, task, switchDomain.getTcpHealthParams());
        return;
    }
    taskQueue.add(new Beat(task, service, metadata, instance));
    MetricsMonitor.getTcpHealthCheckMonitor().incrementAndGet();
}
Also used : HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)

Example 7 with HealthCheckInstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.

the class HealthCheckTaskInterceptWrapperTest method injectInstance.

private HealthCheckInstancePublishInfo injectInstance(boolean healthy, long heartbeatTime) {
    Service service = Service.newService(NAMESPACE, GROUP_NAME, SERVICE_NAME);
    HealthCheckInstancePublishInfo instance = new HealthCheckInstancePublishInfo(IP, PORT);
    instance.setHealthy(healthy);
    instance.setLastHeartBeatTime(heartbeatTime);
    client.addServiceInstance(service, instance);
    return instance;
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service) HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)

Example 8 with HealthCheckInstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.

the class MysqlHealthCheckProcessor method process.

@Override
public void process(HealthCheckTaskV2 task, Service service, ClusterMetadata metadata) {
    HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) task.getClient().getInstancePublishInfo(service);
    if (null == instance) {
        return;
    }
    SRV_LOG.debug("mysql check, ip:" + instance);
    try {
        // TODO handle marked(white list) logic like v1.x.
        if (!instance.tryStartCheck()) {
            SRV_LOG.warn("mysql check started before last one finished, service: {} : {} : {}:{}", service.getGroupedServiceName(), instance.getCluster(), instance.getIp(), instance.getPort());
            healthCheckCommon.reEvaluateCheckRT(task.getCheckRtNormalized() * 2, task, switchDomain.getMysqlHealthParams());
            return;
        }
        GlobalExecutor.executeMysqlCheckTask(new MysqlCheckTask(task, service, instance, metadata));
        MetricsMonitor.getMysqlHealthCheckMonitor().incrementAndGet();
    } catch (Exception e) {
        instance.setCheckRt(switchDomain.getMysqlHealthParams().getMax());
        healthCheckCommon.checkFail(task, service, "mysql:error:" + e.getMessage());
        healthCheckCommon.reEvaluateCheckRT(switchDomain.getMysqlHealthParams().getMax(), task, switchDomain.getMysqlHealthParams());
    }
}
Also used : HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) SQLException(java.sql.SQLException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 9 with HealthCheckInstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.

the class ClientBeatUpdateTask method run.

@Override
public void run() {
    long currentTime = System.currentTimeMillis();
    for (InstancePublishInfo each : client.getAllInstancePublishInfo()) {
        ((HealthCheckInstancePublishInfo) each).setLastHeartBeatTime(currentTime);
    }
    client.setLastUpdatedTime();
}
Also used : HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)

Example 10 with HealthCheckInstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.

the class HealthCheckCommonV2 method checkFailNow.

/**
 * Health check fail, set instance unhealthy directly.
 *
 * @param task    health check task
 * @param service service
 * @param msg     message
 */
public void checkFailNow(HealthCheckTaskV2 task, Service service, String msg) {
    try {
        HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) task.getClient().getInstancePublishInfo(service);
        if (null == instance) {
            return;
        }
        try {
            if (instance.isHealthy()) {
                String serviceName = service.getGroupedServiceName();
                String clusterName = instance.getCluster();
                if (switchDomain.isHealthCheckEnabled(serviceName) && !task.isCancelled() && distroMapper.responsible(task.getClient().getResponsibleId())) {
                    healthStatusSynchronizer.instanceHealthStatusChange(false, task.getClient(), service, instance);
                    Loggers.EVT_LOG.info("serviceName: {} {POS} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}", serviceName, instance.getIp(), instance.getPort(), clusterName, UtilsAndCommons.LOCALHOST_SITE, msg);
                }
            }
        } finally {
            instance.resetOkCount();
            instance.finishCheck();
        }
    } catch (Throwable t) {
        Loggers.SRV_LOG.error("[CHECK-FAIL] error when close check task.", t);
    }
}
Also used : HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)

Aggregations

HealthCheckInstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)13 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)4 Http (com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http)1 Header (com.alibaba.nacos.common.http.param.Header)1 ClientEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)1 ServiceEvent (com.alibaba.nacos.naming.core.v2.event.service.ServiceEvent)1 InstanceMetadata (com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)1 NamingMetadataManager (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)1 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)1 ConnectTimeoutException (io.netty.channel.ConnectTimeoutException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 URL (java.net.URL)1 SQLException (java.sql.SQLException)1 TimeoutException (java.util.concurrent.TimeoutException)1