java Spring Boot 致动器:缓存/执行器/运行状况/就绪和/执行器/运行状况/自定义运行状况检查结果

yv5phkfx  于 2023-04-19  发布在  Java
关注(0)|答案(2)|浏览(152)

因此,我将Sping Boot Actuator添加到我的应用程序中,并在application.properties属性中指定management.endpoint.health.cache.time-to-live=120s来缓存健康检查结果。因此,当我调用/actuator/health时,结果被缓存,并且很好。
当我调用/actuator/health/readiness或自定义创建的组/actuator/health/deep时,这个请求的结果没有被缓存。我浏览了Spring Docs,只找到了主健康端点的信息,没有特定组的信息。
所以我的问题是我错过了什么吗?或者我如何为特定的spring Boot actuator端点实现缓存?
谢谢

xytpbqjk

xytpbqjk1#

所以我没有找到开箱即用的解决方案,所以决定使用AOP方法。
我发现了一个管理健康休息端点的HealthEndpointWebExtension类。这个类有两个健康方法,其中一个调用了公共/health端点,第二个调用了health/<group name>
所以我围绕第二个方法创建了Aspect,它允许我为需要的端点添加缓存。

@Around("execution(@org.springframework.boot.actuate.endpoint.annotation.ReadOperation * org.springframework.boot.actuate.health.HealthEndpointWebExtension.health(..,java.lang.String...))) && args(.., path)")
public Object cache(ProceedingJoinPoint joinPoint, String... path) throws Throwable {
    // Logic to get cache per endpoint and process if cache specifed.
}

application.properties看起来像这样:

// out of the box
management.endpoint.health.cache.time-to-live=120s 

// customly created properties
management.endpoint.health.group.readiness.cache.time-to-live=60s
management.endpoint.health.group.deep.cache.time-to-live=120s
nhjlsmyf

nhjlsmyf2#

面对类似的挑战与React式堆栈ReactiveHealthEndpointWebExtension。这将是伟大的,如果你能够评论的方法,你使用的逻辑获得缓存每个端点和进程,如果缓存指定。

相关问题