0

我有一个部署在 PCF 上的 Spring Boot (2.3.3) 应用程序,它有 5 个实例正在运行。

为了监控这个应用程序的健康状况,我在我实现/覆盖执行器包的 ReactiveHealthIndicator 的地方添加了自定义健康指标。health() 方法调用会话服务来判断实例在特定计数后是启动还是关闭。

问题是,即使一个实例出现故障,PCF 运行状况检查也会关闭所有实例并重新启动。

我如何确保 PCF 运行状况检查仅重新启动那些已关闭的实例而不是所有实例。

我的自定义健康指标:

    @Component @Slf4j @ConditionalOnProperty(
            value = "app.custom.health.enabled",
            havingValue = "true",
            matchIfMissing = true) 
public class MyCustomHealthIndicator implements ReactiveHealthIndicator {
    
        private MyAsyncSessionHealthCheck myAsyncSessionHealthCheck;
    
        public MyCustomHealthIndicator(MyAsyncSessionHealthCheck myAsyncSessionHealthCheck) {
            this.myAsyncSessionHealthCheck = myAsyncSessionHealthCheck;
            log.info("Using Custom health indicator.");
        }
    
        @Override
        public Mono<Health> health() {
            Health health = Health.up().build();
    
            // Fire and forget async health check on session
            myAsyncSessionHealthCheck.checkSessionHealth();
    
            // Check counter and fail if greater than max
            if (myAsyncSessionHealthCheck.checkForSessionFailure()) {
                log.error("Health Down because of session service check failed.");
                health = Health.down().withDetail("REASON", "Session service failed.").build();
            }
            return Mono.just(health);
        } }
4

0 回答 0