Spring Boot Actuator端点配置似乎没有按预期工作

标签 spring spring-boot spring-boot-actuator

我有一个非常简单的 Spring Boot 应用程序。它只是一个zuul反向代理。除了通过 Eureka 和基于每个服务的路径映射发现我们的服务的基本设置之外,没有任何安全性或任何其他内容。我试图防止我们的执行器端点被公开暴露,但仍然希望健康检查端点用于我们的 ELB,但不希望它报告它所知道的所有服务的健康状况(我希望它灵敏)。在尝试找出需要设置哪些属性才能获得预期行为时,我遇到了非常意外的行为。

例如,当我设置属性 endpoints.sensitive=true 时,这不会将运行状况检查端点的默认值更改为敏感。这似乎与文档所说的不符。

http://docs.spring.io/spring-boot/docs/1.4.2.RELEASE/reference/htmlsingle/#production-ready-customizing-endpoints

Likewise, you can also choose to globally set the “sensitive” flag of all endpoints. By default, the sensitive flag depends on the type of endpoint (see the table above). For example, to mark all endpoints as sensitive except info:

endpoints.sensitive=true

endpoints.info.sensitive=false

事实上,在调试中运行时,我从未看到 org.springframework.boot.actuate.endpoint.EndpointProperties#isSensitive 被调用。

为了使运行状况端点变得敏感,我需要显式设置属性endpoints.health.sensitive=true。奇怪的是,当提供此设置时,现在会调用 org.springframework.boot.actuate.endpoint.EndpointProperties#isSensitive。

这太棒了,我的运行状况检查端点现在只报告 UP 或 DOWN,没有其他任何报告。但现在我希望健康检查端点成为唯一启用的端点。因此,我设置了 endpoints.enabled=falseendpoints.health.enabled=true 这应该禁用除健康之外的所有端点。然而,情况似乎并非如此。在我的实例中,我可以点击 /routes/resume/pause/hystrix.stream , 和别的。只有当我使用 endpoints.enabled=false 禁用所有端点,然后使用 endpoints.actuator.enabled=true 启用执行器端点时,我才能确定这一点,这允许我击中执行器端点,然后该端点报告这些端点已启用。

{
  "links": [
    {
      "rel": "self",
      "href": "http://localhost:9200/actuator"
    },
    {
      "rel": "resume",
      "href": "http://localhost:9200/resume"
    },
    {
      "rel": "pause",
      "href": "http://localhost:9200/pause"
    },
    {
      "rel": "hystrix.stream",
      "href": "http://localhost:9200/hystrix.stream"
    },
    {
      "rel": "env",
      "href": "http://localhost:9200/env"
    },
    {
      "rel": "routes",
      "href": "http://localhost:9200/routes"
    },
    {
      "rel": "health",
      "href": "http://localhost:9200/health"
    },
    {
      "rel": "refresh",
      "href": "http://localhost:9200/refresh"
    },
    {
      "rel": "restart",
      "href": "http://localhost:9200/restart"
    }
  ]
}

我希望只能看到我明确启用的两个端点。

{
  "links": [
    {
      "rel": "self",
      "href": "http://localhost:9200/actuator"
    },
    {
      "rel": "health",
      "href": "http://localhost:9200/health"
    }
  ]
}

单独禁用每个端点似乎不会将它们从执行器端点中删除,但现在当尝试访问时,我收到一条“此端点已禁用”消息,这是一个改进。然而,我似乎无法禁用 routes 或 `hystrix.stream* 端点,因为似乎没有配置可以公开此功能。

综上所述,我想知道这是预期的行为还是错误?

最佳答案

我遇到了与您在这里描述的相同的问题。 请先检查您的 Spring Boot 版本! 存在一个错误,全局“endpoints.sensitive”设置在某些指定的 Spring Boot 版本上生效。 (不确定确切的版本号。这似乎是 Spring Boot 中的重构回归。)

这里有一些引用。

将 Spring Boot 更新到版本 1.3.0 RELEASE 后,设置“endpoints.sensitive = true”对我来说可以正常工作。希望它也对你有用。祝你好运,伙计。

关于Spring Boot Actuator端点配置似乎没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40617489/

相关文章:

java - 如何在 Spring 中配置 JSR-330 @Provider 和 @Inject @Named ("foo") String **programmatically**?

java - Spring Boot上传文件大小限制

java - 配置自定义 HibernateItemWriter 时获取 "Either HibernateOperations or SessionFactory must be provided"

spring - 第三方健康端点最佳实践

java - 没有 @EnableAutoConfiguration 的 Spring Actuator 指标存在问题

spring - 如何运行独立/交互式 Spring Boot CRaSH Shell 应用程序?

java - 在 Spring Data JPA 中创建分页

java - 使用 spring mvc web 和 hibernate 更新表

java - Spring 的 RedirectAttributes 中 getFlashAttributes() 的使用

java - 所选方面不应使用 hibernate 搜索过滤自己的组