Merge branch '2021.0' of https://github.com/Tencent/spring-cloud-tencent into feature/multi_register

pull/693/head
wulingxiao 3 years ago
commit 555d9dcd04

@ -13,16 +13,20 @@ Other... Please describe:
## Adding the issue link (#xxx) if possible. ## Adding the issue link (#xxx) if possible.
<!--
fixes #
-->
## Note ## Note
## Checklist ## Checklist
- [ ] Add copyright holder at the beginning of .class file if it is new. - [ ] Coverage from `Codecov Report` should not decrease (which means adding junit tests for adding or updating code).
- [ ] Add information of this PR to CHANGELOG.md in root of project.
- [ ] All junit tests passing. - [ ] All junit tests passing.
- [ ] Coverage from `Codecov Report` should not decrease. - [ ] Add copyright holder at the beginning of .java file if it is new.
- [ ] Add information of this PR to CHANGELOG.md in root of project.
## Checklist (Optional) ## Checklist (Optional)
- [ ] Will Pull Request to branch of 2020.0 and hoxton. - [ ] Will Pull Request to branch of 2020.0 and hoxton.
- [ ] Add documentation in javadoc in code or comment below the PR if necessary. - [ ] Add documentation in javadoc or comment below the PR if necessary.

@ -0,0 +1,34 @@
name: Codecov
on:
push:
branches:
- hoxton
- 2021.0
- 2020.0
- greenwich
pull_request:
branches:
- hoxton
- 2021.0
- 2020.0
- greenwich
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout codes
uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
- name: Test with Maven
run: mvn -B test --file pom.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ${{ github.workspace }}/target/site/jacoco/jacoco.xml

@ -3,3 +3,5 @@
- [Optimize:optimize SpringValueProcessor.](https://github.com/Tencent/spring-cloud-tencent/pull/655) - [Optimize:optimize SpringValueProcessor.](https://github.com/Tencent/spring-cloud-tencent/pull/655)
- [Optimize/optimize annotation.](https://github.com/Tencent/spring-cloud-tencent/pull/672) - [Optimize/optimize annotation.](https://github.com/Tencent/spring-cloud-tencent/pull/672)
- [Optimize: Register the service with the ProviderAPI#registerInstance method.](https://github.com/Tencent/spring-cloud-tencent/pull/686)
- [docs:update PR template.](https://github.com/Tencent/spring-cloud-tencent/pull/690)

@ -84,12 +84,6 @@ public class PolarisDiscoveryProperties {
@Value("${spring.cloud.polaris.discovery.register:#{true}}") @Value("${spring.cloud.polaris.discovery.register:#{true}}")
private Boolean registerEnabled; private Boolean registerEnabled;
/**
* If heartbeat enabled.
*/
@Value("${spring.cloud.polaris.discovery.heartbeat.enabled:#{true}}")
private Boolean heartbeatEnabled = true;
/** /**
* Heartbeat interval ( 0 < interval <= 60). * Heartbeat interval ( 0 < interval <= 60).
* Time unit: second. Default: 5. * Time unit: second. Default: 5.
@ -108,15 +102,6 @@ public class PolarisDiscoveryProperties {
*/ */
private Long serviceListRefreshInterval = 60000L; private Long serviceListRefreshInterval = 60000L;
public boolean isHeartbeatEnabled() {
return heartbeatEnabled;
}
public void setHeartbeatEnabled(Boolean heartbeatEnabled) {
this.heartbeatEnabled = heartbeatEnabled;
}
public String getNamespace() { public String getNamespace() {
return namespace; return namespace;
} }
@ -206,7 +191,7 @@ public class PolarisDiscoveryProperties {
} }
public Integer getHeartbeatInterval() { public Integer getHeartbeatInterval() {
if (this.heartbeatEnabled && (this.heartbeatInterval <= 0 || this.heartbeatInterval > 60)) { if (this.heartbeatInterval <= 0 || this.heartbeatInterval > 60) {
heartbeatInterval = DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL; heartbeatInterval = DEFAULT_REGISTRY_HEARTBEAT_TIME_INTERVAL;
} }
return heartbeatInterval; return heartbeatInterval;
@ -228,10 +213,6 @@ public class PolarisDiscoveryProperties {
this.registerEnabled = registerEnabled; this.registerEnabled = registerEnabled;
} }
public Boolean getHeartbeatEnabled() {
return heartbeatEnabled;
}
@Override @Override
public String toString() { public String toString() {
return "PolarisDiscoveryProperties{" + return "PolarisDiscoveryProperties{" +
@ -244,7 +225,6 @@ public class PolarisDiscoveryProperties {
", port=" + port + ", port=" + port +
", enabled=" + enabled + ", enabled=" + enabled +
", registerEnabled=" + registerEnabled + ", registerEnabled=" + registerEnabled +
", heartbeatEnabled=" + heartbeatEnabled +
", heartbeatInterval=" + heartbeatInterval + ", heartbeatInterval=" + heartbeatInterval +
", healthCheckUrl='" + healthCheckUrl + '\'' + ", healthCheckUrl='" + healthCheckUrl + '\'' +
", serviceListRefreshInterval=" + serviceListRefreshInterval + ", serviceListRefreshInterval=" + serviceListRefreshInterval +

@ -68,7 +68,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
this.polarisDiscoveryHandler = polarisDiscoveryHandler; this.polarisDiscoveryHandler = polarisDiscoveryHandler;
this.staticMetadataManager = staticMetadataManager; this.staticMetadataManager = staticMetadataManager;
if (polarisDiscoveryProperties.isHeartbeatEnabled()) { if (StringUtils.isNotBlank(polarisDiscoveryProperties.getHealthCheckUrl())) {
this.heartbeatExecutor = Executors this.heartbeatExecutor = Executors
.newSingleThreadScheduledExecutor(new NamedThreadFactory("polaris-heartbeat")); .newSingleThreadScheduledExecutor(new NamedThreadFactory("polaris-heartbeat"));
} }
@ -95,26 +95,27 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
instanceRegisterRequest.setRegion(staticMetadataManager.getRegion()); instanceRegisterRequest.setRegion(staticMetadataManager.getRegion());
instanceRegisterRequest.setZone(staticMetadataManager.getZone()); instanceRegisterRequest.setZone(staticMetadataManager.getZone());
instanceRegisterRequest.setCampus(staticMetadataManager.getCampus()); instanceRegisterRequest.setCampus(staticMetadataManager.getCampus());
if (null != heartbeatExecutor) { instanceRegisterRequest.setTtl(polarisDiscoveryProperties.getHeartbeatInterval());
instanceRegisterRequest.setTtl(polarisDiscoveryProperties.getHeartbeatInterval());
}
instanceRegisterRequest.setMetadata(registration.getMetadata()); instanceRegisterRequest.setMetadata(registration.getMetadata());
instanceRegisterRequest.setProtocol(polarisDiscoveryProperties.getProtocol()); instanceRegisterRequest.setProtocol(polarisDiscoveryProperties.getProtocol());
instanceRegisterRequest.setVersion(polarisDiscoveryProperties.getVersion()); instanceRegisterRequest.setVersion(polarisDiscoveryProperties.getVersion());
try { try {
ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI(); ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI();
InstanceRegisterResponse instanceRegisterResponse = providerClient.register(instanceRegisterRequest); InstanceRegisterResponse instanceRegisterResponse;
registration.setInstanceId(instanceRegisterResponse.getInstanceId()); if (StringUtils.isBlank(polarisDiscoveryProperties.getHealthCheckUrl())) {
LOGGER.info("polaris registry, {} {} {}:{} {} register finished", polarisDiscoveryProperties.getNamespace(), instanceRegisterResponse = providerClient.registerInstance(instanceRegisterRequest);
registration.getServiceId(), registration.getHost(), registration.getPort(), }
staticMetadataManager.getMergedStaticMetadata()); else {
instanceRegisterResponse = providerClient.register(instanceRegisterRequest);
if (null != heartbeatExecutor) {
InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest(); InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest();
BeanUtils.copyProperties(instanceRegisterRequest, heartbeatRequest); BeanUtils.copyProperties(instanceRegisterRequest, heartbeatRequest);
// Start the heartbeat thread after the registration is successful. // Start the heartbeat thread after the registration is successful.
heartbeat(heartbeatRequest); heartbeat(heartbeatRequest);
} }
registration.setInstanceId(instanceRegisterResponse.getInstanceId());
LOGGER.info("polaris registry, {} {} {}:{} {} register finished", polarisDiscoveryProperties.getNamespace(),
registration.getServiceId(), registration.getHost(), registration.getPort(),
staticMetadataManager.getMergedStaticMetadata());
} }
catch (Exception e) { catch (Exception e) {
LOGGER.error("polaris registry, {} register failed...{},", registration.getServiceId(), registration, e); LOGGER.error("polaris registry, {} register failed...{},", registration.getServiceId(), registration, e);
@ -188,24 +189,19 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
heartbeatExecutor.scheduleWithFixedDelay(() -> { heartbeatExecutor.scheduleWithFixedDelay(() -> {
try { try {
String healthCheckEndpoint = polarisDiscoveryProperties.getHealthCheckUrl(); String healthCheckEndpoint = polarisDiscoveryProperties.getHealthCheckUrl();
// First determine whether health-check-url is configured.
// If configured, the service instance health check needs to be executed
// first.
// If the health check passes, the heartbeat will be reported. // If the health check passes, the heartbeat will be reported.
// If it does not pass, the heartbeat will not be reported. // If it does not pass, the heartbeat will not be reported.
if (StringUtils.isNotBlank(healthCheckEndpoint)) { if (!healthCheckEndpoint.startsWith("/")) {
if (!healthCheckEndpoint.startsWith("/")) { healthCheckEndpoint = "/" + healthCheckEndpoint;
healthCheckEndpoint = "/" + healthCheckEndpoint; }
}
String healthCheckUrl = String.format("http://%s:%s%s", heartbeatRequest.getHost(),
String healthCheckUrl = String.format("http://%s:%s%s", heartbeatRequest.getHost(), heartbeatRequest.getPort(), healthCheckEndpoint);
heartbeatRequest.getPort(), healthCheckEndpoint);
if (!OkHttpUtil.get(healthCheckUrl, null)) {
if (!OkHttpUtil.get(healthCheckUrl, null)) { LOGGER.error("backend service health check failed. health check endpoint = {}",
LOGGER.error("backend service health check failed. health check endpoint = {}", healthCheckEndpoint);
healthCheckEndpoint); return;
return;
}
} }
polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest); polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest);

@ -37,10 +37,6 @@ public class PolarisDiscoveryPropertiesTest {
public void testGetAndSet() { public void testGetAndSet() {
PolarisDiscoveryProperties polarisDiscoveryProperties = new PolarisDiscoveryProperties(); PolarisDiscoveryProperties polarisDiscoveryProperties = new PolarisDiscoveryProperties();
// HeartbeatEnabled
polarisDiscoveryProperties.setHeartbeatEnabled(true);
assertThat(polarisDiscoveryProperties.isHeartbeatEnabled()).isTrue();
// HeartbeatEnabled // HeartbeatEnabled
polarisDiscoveryProperties.setHeartbeatInterval(200); polarisDiscoveryProperties.setHeartbeatInterval(200);
assertThat(polarisDiscoveryProperties.getHeartbeatInterval()).isEqualTo(5); assertThat(polarisDiscoveryProperties.getHeartbeatInterval()).isEqualTo(5);
@ -103,7 +99,6 @@ public class PolarisDiscoveryPropertiesTest {
+ ", port=9091" + ", port=9091"
+ ", enabled=true" + ", enabled=true"
+ ", registerEnabled=true" + ", registerEnabled=true"
+ ", heartbeatEnabled=true"
+ ", heartbeatInterval=20" + ", heartbeatInterval=20"
+ ", healthCheckUrl='/health'" + ", healthCheckUrl='/health'"
+ ", serviceListRefreshInterval=1000}"); + ", serviceListRefreshInterval=1000}");

@ -61,7 +61,7 @@ public class RateLimitRuleLabelResolverTest {
} }
else { else {
ModelProto.MatchString matchString = ModelProto.MatchString.newBuilder() ModelProto.MatchString matchString = ModelProto.MatchString.newBuilder()
.setType(ModelProto.MatchString.MatchStringType.EXACT) .setType(ModelProto.Operation.EXACT)
.setValue(StringValue.of("value")) .setValue(StringValue.of("value"))
.setValueType(ModelProto.MatchString.ValueType.TEXT).build(); .setValueType(ModelProto.MatchString.ValueType.TEXT).build();
RateLimitProto.Rule rule = RateLimitProto.Rule.newBuilder() RateLimitProto.Rule rule = RateLimitProto.Rule.newBuilder()

@ -83,7 +83,7 @@ public class PolarisRateLimitRuleEndpointTests {
} }
else { else {
ModelProto.MatchString matchString = ModelProto.MatchString.newBuilder() ModelProto.MatchString matchString = ModelProto.MatchString.newBuilder()
.setType(ModelProto.MatchString.MatchStringType.EXACT) .setType(ModelProto.Operation.EXACT)
.setValue(StringValue.of("value")) .setValue(StringValue.of("value"))
.setValueType(ModelProto.MatchString.ValueType.TEXT).build(); .setValueType(ModelProto.MatchString.ValueType.TEXT).build();
RateLimitProto.Rule rule = RateLimitProto.Rule.newBuilder() RateLimitProto.Rule rule = RateLimitProto.Rule.newBuilder()

Loading…
Cancel
Save