Skip to content

Commit

Permalink
fix: fix lossless deregister failed when no healthcheck configured
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewshan committed Apr 20, 2024
1 parent 5951448 commit 6a9f1b2
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ spring:
port: 28084
lossless:
enabled: true
healthCheckPath: /lossless/callee/health
healthCheckInterval: 5000
port: 28084
#healthCheckPath: /actuator/health
#healthCheckInterval: 5000
lossless:
healthy:
delay:
Expand All @@ -32,5 +33,4 @@ management:
exposure:
include:
- polaris-discovery
- polaris-ratelimit
- polaris-config
- health
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@ spring:
cloud:
nacos:
discovery:
server-addr: 9.134.5.52:8848
server-addr: 127.0.0.1:8848
enabled: true
namespace: "test1"
polaris:
lossless:
enabled: true
healthCheckPath: /lossless/nacos/callee/health
port: 28085
healthCheckPath: /actuator/health
healthCheckInterval: 5000
lossless:
healthy:
delay:
second: 20
management:
endpoints:
web:
exposure:
include:
- polaris-discovery
- polaris-ratelimit
- polaris-config
second: 20
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<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>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,26 @@ spring:
enabled: true
rejectRequestTipsFilePath: reject-tips.html
maxQueuingTime: 500
lossless:
enabled: true
port: 28011
healthCheckPath: /actuator/health
healthCheckInterval: 5000
tencent:
metadata:
content:
label1: value1
region: huanan
management:
endpoints:
health:
enabled: true
web:
exposure:
include:
- polaris-discovery
- polaris-ratelimit
- polaris-config
- health
label:
key-value: user:zhangsan
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<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>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ spring:
ratelimit:
enabled: true
maxQueuingTime: 500
lossless:
enabled: true
port: 28012
healthCheckPath: /actuator/health
healthCheckInterval: 5000
tencent:
metadata:
content:
Expand All @@ -45,5 +50,6 @@ management:
- polaris-discovery
- polaris-ratelimit
- polaris-config
- health
label:
key-value: user2:lisi
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<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>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ spring:
# pushgateway:
# enabled: true
# address: 127.0.0.1:9091
lossless:
enabled: true
port: 28013
healthCheckPath: /actuator/health
healthCheckInterval: 5000
tencent:
rpc-enhancement:
enabled: true
Expand All @@ -46,3 +51,4 @@ management:
include:
- polaris-discovery
- polaris-circuit-breaker
- health
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</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>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ spring:
stat:
enabled: true
port: 28081
lossless:
enabled: true
port: 28014
healthCheckPath: /actuator/health
healthCheckInterval: 5000
gateway:
discovery:
locator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,57 +158,7 @@ public static void innerConfigDestroy() {
}

public void init() {
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;
}
}

initService();
initConfig();
}

Expand All @@ -225,37 +175,37 @@ public static void setConfigSDKContext(SDKContext context) {
}

public SDKContext getSDKContext() {
init();
initService();
return serviceSdkContext;
}

public ProviderAPI getProviderAPI() {
init();
initService();
return providerAPI;
}

public LosslessAPI getLosslessAPI() {
init();
initService();
return losslessAPI;
}

public ConsumerAPI getConsumerAPI() {
init();
initService();
return consumerAPI;
}

public RouterAPI getRouterAPI() {
init();
initService();
return routerAPI;
}

public CircuitBreakAPI getCircuitBreakAPI() {
init();
initService();
return circuitBreakAPI;
}

public LimitAPI getLimitAPI() {
init();
initService();
return limitAPI;
}

Expand All @@ -268,6 +218,59 @@ public SDKContext getConfigSDKContext() {
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() {
// get modifiers for configuration.
List<PolarisConfigModifier> configModifierList = new ArrayList<>();
Expand Down

0 comments on commit 6a9f1b2

Please sign in to comment.