fix:fix heartbeat interval different configuration from polaris-java SDK. (#558)

pull/564/head
Haotian Zhang 2 years ago committed by GitHub
parent 31bbaa61fc
commit de91e16e1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,3 +29,4 @@
- [fix:set error handler named EnhancedRestTemplateReporter for RestTemplate](https://github.com/Tencent/spring-cloud-tencent/pull/544)
- [Optimize: add switch for report call result and default false](https://github.com/Tencent/spring-cloud-tencent/pull/549)
- [Report the labels in request when report the result of invocation by Feign](https://github.com/Tencent/spring-cloud-tencent/pull/555)
- [fix:fix heartbeat interval different configuration from polaris-java SDK.](https://github.com/Tencent/spring-cloud-tencent/pull/558)

@ -98,11 +98,11 @@ public class PolarisDiscoveryProperties {
private Boolean heartbeatEnabled = true;
/**
* Heart beat interval (The time interval must be greater than zero).
* Time unit: millisecond. Default: 5000.
* Heartbeat interval ( 0 < interval <= 60).
* Time unit: second. Default: 5.
* @see ContextConstant#DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL
*/
private Integer heartbeatInterval = 5000;
private Integer heartbeatInterval = DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL;
/**
* Custom health check url to override default.
@ -212,8 +212,8 @@ public class PolarisDiscoveryProperties {
}
public Integer getHeartbeatInterval() {
if (this.heartbeatEnabled && this.heartbeatInterval <= 0) {
return DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL;
if (this.heartbeatEnabled && (this.heartbeatInterval <= 0 || this.heartbeatInterval > 60)) {
heartbeatInterval = DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL;
}
return heartbeatInterval;
}

@ -41,7 +41,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
/**
@ -70,7 +70,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
if (polarisDiscoveryProperties.isHeartbeatEnabled()) {
this.heartbeatExecutor = Executors
.newSingleThreadScheduledExecutor(new NamedThreadFactory("spring-cloud-heartbeat"));
.newSingleThreadScheduledExecutor(new NamedThreadFactory("polaris-heartbeat"));
}
else {
this.heartbeatExecutor = null;
@ -209,13 +209,14 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
}
polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest);
log.trace("Polaris heartbeat is sent");
}
catch (PolarisException e) {
log.error("polaris heartbeat[{}]", e.getCode(), e);
log.error("polaris heartbeat error with code [{}]", e.getCode(), e);
}
catch (Exception e) {
log.error("polaris heartbeat runtime error", e);
}
}, polarisDiscoveryProperties.getHeartbeatInterval(), polarisDiscoveryProperties.getHeartbeatInterval(), MILLISECONDS);
}, polarisDiscoveryProperties.getHeartbeatInterval(), polarisDiscoveryProperties.getHeartbeatInterval(), SECONDS);
}
}

@ -27,8 +27,8 @@
{
"name": "spring.cloud.polaris.discovery.heartbeat-interval",
"type": "java.lang.Integer",
"defaultValue": "5000",
"description": "Millis interval of Heart beat. Default: 5000."
"defaultValue": "5",
"description": "Seconds interval of Heart beat. Default: 5."
},
{
"name": "spring.cloud.polaris.discovery.health-check-url",

@ -42,8 +42,12 @@ public class PolarisDiscoveryPropertiesTest {
assertThat(polarisDiscoveryProperties.isHeartbeatEnabled()).isTrue();
// HeartbeatEnabled
polarisDiscoveryProperties.setHeartbeatInterval(2000);
assertThat(polarisDiscoveryProperties.getHeartbeatInterval()).isEqualTo(2000);
polarisDiscoveryProperties.setHeartbeatInterval(200);
assertThat(polarisDiscoveryProperties.getHeartbeatInterval()).isEqualTo(5);
polarisDiscoveryProperties.setHeartbeatInterval(0);
assertThat(polarisDiscoveryProperties.getHeartbeatInterval()).isEqualTo(5);
polarisDiscoveryProperties.setHeartbeatInterval(20);
assertThat(polarisDiscoveryProperties.getHeartbeatInterval()).isEqualTo(20);
// Namespace
polarisDiscoveryProperties.setNamespace(NAMESPACE_TEST);
@ -100,7 +104,7 @@ public class PolarisDiscoveryPropertiesTest {
+ ", enabled=true"
+ ", registerEnabled=true"
+ ", heartbeatEnabled=true"
+ ", heartbeatInterval=2000"
+ ", heartbeatInterval=20"
+ ", healthCheckUrl='/health'"
+ ", serviceListRefreshInterval=1000}");
}

@ -37,9 +37,9 @@ public final class ContextConstant {
public static final String UTF_8 = StandardCharsets.UTF_8.name();
/**
* Default registry heartbeat time interval, default: 5000 (ms).
* Default registry heartbeat time interval: 5 (s).
*/
public static final Integer DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL = 5000;
public static final Integer DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL = 5;
private ContextConstant() {
}

Loading…
Cancel
Save