在 Spring Boot Actuator 中隐藏健康指标的详细信息

Hide details for health indicators in Spring Boot Actuator

我正在使用来自执行器的 Spring 启动运行状况指示器。到目前为止,示例响应如下所示:

{
   "status":"DOWN",
   "details": {
      "diskSpace": {
         "status":"UP",
         "details": {
            "total":499963170816,
            "free":250067189760,
            "threshold":10485760
         }
      }
   }
}

因为我需要制作 /actuator/health 端点 public,我需要隐藏健康指标的详细信息,所以我希望得到这样的东西:

{
   "status":"DOWN",
   "details": {
      "diskSpace": {
         "status":"UP"
      }
   }
}

对于磁盘 space 这不是一个大问题,但是例如对于数据库,我不想在发生中断时共享异常消息和详细信息。另外(正如我在开头提到的)它必须是 public 所以我不想让这个端点 'when-authorized'。最后 - 如果无需编写我自己的自定义端点就可以做到这一点,那就太好了。

有可能吗?

在撰写本文时(在 Spring Boot 2.1 及更早版本中)如果不编写您自己的自定义端点,这是不可能的。我已经打开 an issue 将其视为 Spring Boot.

未来版本的增强功能

有一种方法可以在 Spring 启动 2.X

中实现
management:
  health:
    db:
      enabled: false
    diskspace:
      enabled: false
    mongo:
      enabled: false
    refresh:
      enabled: false

可以在此处找到更多信息https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#_auto_configured_healthindicators