fix: fix lossless deregister failed when no healthcheck configured

pull/1279/head
andrewshan 1 year ago
parent 5951448749
commit 6a9f1b2255

@ -20,8 +20,9 @@ spring:
port: 28084 port: 28084
lossless: lossless:
enabled: true enabled: true
healthCheckPath: /lossless/callee/health port: 28084
healthCheckInterval: 5000 #healthCheckPath: /actuator/health
#healthCheckInterval: 5000
lossless: lossless:
healthy: healthy:
delay: delay:
@ -32,5 +33,4 @@ management:
exposure: exposure:
include: include:
- polaris-discovery - polaris-discovery
- polaris-ratelimit - health
- polaris-config

@ -6,23 +6,15 @@ spring:
cloud: cloud:
nacos: nacos:
discovery: discovery:
server-addr: 9.134.5.52:8848 server-addr: 127.0.0.1:8848
enabled: true enabled: true
namespace: "test1"
polaris: polaris:
lossless: lossless:
enabled: true enabled: true
healthCheckPath: /lossless/nacos/callee/health port: 28085
healthCheckPath: /actuator/health
healthCheckInterval: 5000 healthCheckInterval: 5000
lossless: lossless:
healthy: healthy:
delay: delay:
second: 20 second: 20
management:
endpoints:
web:
exposure:
include:
- polaris-discovery
- polaris-ratelimit
- polaris-config

@ -28,6 +28,12 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-lossless-plugin</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -33,6 +33,11 @@ spring:
enabled: true enabled: true
rejectRequestTipsFilePath: reject-tips.html rejectRequestTipsFilePath: reject-tips.html
maxQueuingTime: 500 maxQueuingTime: 500
lossless:
enabled: true
port: 28011
healthCheckPath: /actuator/health
healthCheckInterval: 5000
tencent: tencent:
metadata: metadata:
content: content:
@ -40,11 +45,14 @@ spring:
region: huanan region: huanan
management: management:
endpoints: endpoints:
health:
enabled: true
web: web:
exposure: exposure:
include: include:
- polaris-discovery - polaris-discovery
- polaris-ratelimit - polaris-ratelimit
- polaris-config - polaris-config
- health
label: label:
key-value: user:zhangsan key-value: user:zhangsan

@ -28,6 +28,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-lossless-plugin</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -32,6 +32,11 @@ spring:
ratelimit: ratelimit:
enabled: true enabled: true
maxQueuingTime: 500 maxQueuingTime: 500
lossless:
enabled: true
port: 28012
healthCheckPath: /actuator/health
healthCheckInterval: 5000
tencent: tencent:
metadata: metadata:
content: content:
@ -45,5 +50,6 @@ management:
- polaris-discovery - polaris-discovery
- polaris-ratelimit - polaris-ratelimit
- polaris-config - polaris-config
- health
label: label:
key-value: user2:lisi key-value: user2:lisi

@ -38,6 +38,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-lossless-plugin</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -28,6 +28,11 @@ spring:
# pushgateway: # pushgateway:
# enabled: true # enabled: true
# address: 127.0.0.1:9091 # address: 127.0.0.1:9091
lossless:
enabled: true
port: 28013
healthCheckPath: /actuator/health
healthCheckInterval: 5000
tencent: tencent:
rpc-enhancement: rpc-enhancement:
enabled: true enabled: true
@ -46,3 +51,4 @@ management:
include: include:
- polaris-discovery - polaris-discovery
- polaris-circuit-breaker - polaris-circuit-breaker
- health

@ -28,6 +28,16 @@
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId> <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-lossless-plugin</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -27,6 +27,11 @@ spring:
stat: stat:
enabled: true enabled: true
port: 28081 port: 28081
lossless:
enabled: true
port: 28014
healthCheckPath: /actuator/health
healthCheckInterval: 5000
gateway: gateway:
discovery: discovery:
locator: locator:

@ -158,57 +158,7 @@ public class PolarisSDKContextManager {
} }
public void init() { public void init() {
if (null == serviceSdkContext) { initService();
try {
// init SDKContext
serviceSdkContext = SDKContext.initContextByConfig(properties.configuration(modifierList,
() -> environment.getProperty("spring.cloud.client.ip-address"),
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0)));
serviceSdkContext.init();
// init ProviderAPI
providerAPI = DiscoveryAPIFactory.createProviderAPIByContext(serviceSdkContext);
// init losslessAPI
losslessAPI = DiscoveryAPIFactory.createLosslessAPIByContext(serviceSdkContext);
// init ConsumerAPI
consumerAPI = DiscoveryAPIFactory.createConsumerAPIByContext(serviceSdkContext);
// init RouterAPI
routerAPI = RouterAPIFactory.createRouterAPIByContext(serviceSdkContext);
// init CircuitBreakAPI
circuitBreakAPI = CircuitBreakAPIFactory.createCircuitBreakAPIByContext(serviceSdkContext);
// init LimitAPI
limitAPI = LimitAPIFactory.createLimitAPIByContext(serviceSdkContext);
// init AssemblyAPI
assemblyAPI = AssemblyAPIFactory.createAssemblyAPIByContext(serviceSdkContext);
// add shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
long startTimestamp = System.currentTimeMillis();
long delay = 0;
while (true) {
if (!isRegistered || delay >= 60000) {
innerDestroy();
break;
}
else {
delay = System.currentTimeMillis() - startTimestamp;
}
}
}));
LOG.info("create Polaris SDK context successfully. properties: {}, ", properties);
}
catch (Throwable throwable) {
LOG.error("create Polaris SDK context failed. properties: {}, ", properties, throwable);
throw throwable;
}
}
initConfig(); initConfig();
} }
@ -225,37 +175,37 @@ public class PolarisSDKContextManager {
} }
public SDKContext getSDKContext() { public SDKContext getSDKContext() {
init(); initService();
return serviceSdkContext; return serviceSdkContext;
} }
public ProviderAPI getProviderAPI() { public ProviderAPI getProviderAPI() {
init(); initService();
return providerAPI; return providerAPI;
} }
public LosslessAPI getLosslessAPI() { public LosslessAPI getLosslessAPI() {
init(); initService();
return losslessAPI; return losslessAPI;
} }
public ConsumerAPI getConsumerAPI() { public ConsumerAPI getConsumerAPI() {
init(); initService();
return consumerAPI; return consumerAPI;
} }
public RouterAPI getRouterAPI() { public RouterAPI getRouterAPI() {
init(); initService();
return routerAPI; return routerAPI;
} }
public CircuitBreakAPI getCircuitBreakAPI() { public CircuitBreakAPI getCircuitBreakAPI() {
init(); initService();
return circuitBreakAPI; return circuitBreakAPI;
} }
public LimitAPI getLimitAPI() { public LimitAPI getLimitAPI() {
init(); initService();
return limitAPI; return limitAPI;
} }
@ -268,6 +218,59 @@ public class PolarisSDKContextManager {
return configSDKContext; return configSDKContext;
} }
public void initService() {
if (null == serviceSdkContext) {
try {
// init SDKContext
serviceSdkContext = SDKContext.initContextByConfig(properties.configuration(modifierList,
() -> environment.getProperty("spring.cloud.client.ip-address"),
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0)));
serviceSdkContext.init();
// init ProviderAPI
providerAPI = DiscoveryAPIFactory.createProviderAPIByContext(serviceSdkContext);
// init losslessAPI
losslessAPI = DiscoveryAPIFactory.createLosslessAPIByContext(serviceSdkContext);
// init ConsumerAPI
consumerAPI = DiscoveryAPIFactory.createConsumerAPIByContext(serviceSdkContext);
// init RouterAPI
routerAPI = RouterAPIFactory.createRouterAPIByContext(serviceSdkContext);
// init CircuitBreakAPI
circuitBreakAPI = CircuitBreakAPIFactory.createCircuitBreakAPIByContext(serviceSdkContext);
// init LimitAPI
limitAPI = LimitAPIFactory.createLimitAPIByContext(serviceSdkContext);
// init AssemblyAPI
assemblyAPI = AssemblyAPIFactory.createAssemblyAPIByContext(serviceSdkContext);
// add shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
long startTimestamp = System.currentTimeMillis();
long delay = 0;
while (true) {
if (!isRegistered || delay >= 60000) {
innerDestroy();
break;
}
else {
delay = System.currentTimeMillis() - startTimestamp;
}
}
}));
LOG.info("create Polaris SDK context successfully. properties: {}, ", properties);
}
catch (Throwable throwable) {
LOG.error("create Polaris SDK context failed. properties: {}, ", properties, throwable);
throw throwable;
}
}
}
public void initConfig() { public void initConfig() {
// get modifiers for configuration. // get modifiers for configuration.
List<PolarisConfigModifier> configModifierList = new ArrayList<>(); List<PolarisConfigModifier> configModifierList = new ArrayList<>();

Loading…
Cancel
Save