Spring Boot 执行器健康组件检查是否将整个服务关闭?

Springboot actuator health component check puts whole service as down?

我们对我们的应用程序进行了多项健康检查,但如果其中一个组件健康检查失败 - 那么整个应用程序的状态将变为“DOWN”。

我们想要的是应用程序状态仍然是“UP”,即使单个组件失败。

如何防止单个失败的组件检查更改应用程序状态?

以下是我们的健康检查示例:

{
  "status": "UP",
  "components": {
    "db": {
      "status": "UP",
      "details": { "database": "MariaDB", "validationQuery": "isValid()" }
    },
    "discoveryComposite": {
      "description": "Discovery Client not initialized",
      "status": "UNKNOWN",
      "components": {
        "discoveryClient": {
          "description": "Discovery Client not initialized",
          "status": "UNKNOWN"
        }
      }
    },
    "diskSpace": {
      "status": "UP",
      "details": {
        "total": 117404147712,
        "free": 102471593984,
        "threshold": 10485760,
        "exists": true
      }
    },
    "linkFlow": {
      "status": "UP",
      "details": { "message": "LinkFLow er tilgjengelig" }
    },
    "nissy": {
      "status": "UP",
      "details": { "message": "Nissy er tilgjengelig" }
    },
    "ping": { "status": "UP" },
    "reactiveDiscoveryClients": {
      "description": "Discovery Client not initialized",
      "status": "UNKNOWN",
      "components": {
        "Simple Reactive Discovery Client": {
          "description": "Discovery Client not initialized",
          "status": "UNKNOWN"
        }
      }
    },
    "refreshScope": { "status": "UP" },
    "zisson": {
      "status": "UP",
      "details": { "message": "Zisson API er tilgjengelig" }
    }
  }
}

实施健康检查:

@Component
@Slf4j
public class ZissonHealthIndicator implements HealthIndicator {

    private final ZissonAPIGateway zissonAPIGateway;

    public ZissonHealthIndicator(ZissonAPIGateway zissonAPIGateway) {
        this.zissonAPIGateway = zissonAPIGateway;
    }

    @Override
    public Health health() {

        if (zissonAPIGateway.isAvailable()) {
            return Health.up().withDetail("message", "Zisson API er tilgjengelig").build();
        }

        log.warn("Helsesjekk: Zisson er utilgjengelig");
        return Health.down().withDetail("message", "Zisson er ikke tilgjengelig").build();
    }
}

是的,你可以。只需创建您自己的 StatusAggregator:

@Component
public class CustomHealthAggregator extends SimpleStatusAggregator {

    @Override
    public Status getAggregateStatus(Set<Status> statuses) {
        // or some othe logic here
        if (statuses.contains(Status.UP)) {
            return Status.UP;
        }
        return super.getAggregateStatus(statuses);
    }

}