mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Check nacos config health use configService
This commit is contained in:
@@ -51,7 +51,6 @@ public class NacosConfigEndpointAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public NacosConfigHealthIndicator nacosConfigHealthIndicator() {
|
||||
return new NacosConfigHealthIndicator(nacosConfigProperties,
|
||||
nacosConfigProperties.configServiceInstance());
|
||||
return new NacosConfigHealthIndicator(nacosConfigProperties.configServiceInstance());
|
||||
}
|
||||
}
|
||||
|
@@ -16,16 +16,9 @@
|
||||
|
||||
package com.alibaba.cloud.nacos.endpoint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||
import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySource;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
|
||||
/**
|
||||
@@ -33,41 +26,17 @@ import com.alibaba.nacos.api.config.ConfigService;
|
||||
*/
|
||||
public class NacosConfigHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
private final NacosConfigProperties nacosConfigProperties;
|
||||
|
||||
private final List<String> dataIds;
|
||||
|
||||
private final ConfigService configService;
|
||||
|
||||
public NacosConfigHealthIndicator(NacosConfigProperties nacosConfigProperties,
|
||||
ConfigService configService) {
|
||||
this.nacosConfigProperties = nacosConfigProperties;
|
||||
public NacosConfigHealthIndicator(ConfigService configService) {
|
||||
this.configService = configService;
|
||||
|
||||
this.dataIds = new ArrayList<>();
|
||||
for (NacosPropertySource nacosPropertySource : NacosPropertySourceRepository
|
||||
.getAll()) {
|
||||
this.dataIds.add(nacosPropertySource.getDataId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
for (String dataId : dataIds) {
|
||||
try {
|
||||
String config = configService.getConfig(dataId,
|
||||
nacosConfigProperties.getGroup(),
|
||||
nacosConfigProperties.getTimeout());
|
||||
if (StringUtils.isEmpty(config)) {
|
||||
builder.down().withDetail(String.format("dataId: '%s', group: '%s'",
|
||||
dataId, nacosConfigProperties.getGroup()), "config is empty");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
builder.down().withDetail(String.format("dataId: '%s', group: '%s'",
|
||||
dataId, nacosConfigProperties.getGroup()), e.getMessage());
|
||||
}
|
||||
}
|
||||
builder.up().withDetail("dataIds", dataIds);
|
||||
builder.up();
|
||||
|
||||
String status = configService.getServerStatus();
|
||||
builder.status(status);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user