Spring Actuator - 服务发现 -/health "description":"Discovery Client not initialized","status":"UNKNOWN" [英] Spring Actuator - Service discovery - /health "description":"Discovery Client not initialized","status":"UNKNOWN"

查看:63
本文介绍了Spring Actuator - 服务发现 -/health "description":"Discovery Client not initialized","status":"UNKNOWN"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于使用 Spring Boot Actuator 发现服务的问题,请结合 Spring Cloud Kubernetes.

Question related to service discovery with Spring Boot Actuator, combined with Spring Cloud Kubernetes please.

目前,我有一个 web 应用程序,它同时具有执行器和 spring boot kubernetes 依赖项.我也在使用 kubernetes 提供的发现客户端,一切正常.

Currently, I have a web app that has both the actuator and spring boot kubernetes dependencies. I am also using the discovery client provided by kubernetes, things are working fine.

然而,当我卷曲我的健康端点时,我确实看到了那些奇怪的陈述:

However, when I curl my health endpoint, I do see those strange statements:

discoveryComposite":{"description":"Discovery Client not initialized","status":"UNKNOWN","components":{"discoveryClient":{"description":"Discovery Client not initialized","status":"UNKNOWN"}}

"reactiveDiscoveryClients":{"description":"Discovery Client not initialized","status":"UNKNOWN","components":{"Kubernetes Reactive Discovery Client":{"description":"Discovery Client not initialized","status":"UNKNOWN"}

Simple Reactive Discovery Client":{"description":"Discovery Client not initialized","status":"UNKNOWN"}}}

"readinessState":{"status":"UP"},"refreshScope":{"status":"UP"}},"groups":["liveness","readiness"]}*

请问为什么是未知"?我本来希望这里的三个中的至少一个能解决问题,而且绝对不是发现客户端未初始化".

May I ask why is it "unknown"? I would have expected at least one of the three here to how up something, and definitely not "Discovery Client not initialized".

我忘记初始化了吗?要注册什么?配置一些东西?

Did I forget to initialize something? To register something? To configure something?

顺便说一句,这确实是一个关于使用 kubernetes 进行发现的问题.与 Eureka 无关,与 Consul 等无关.

Btw, this is really a question regarding discovery with kubernetes. Not related to Eureka, not related to Consul and such.

非常感谢

推荐答案

有同样的问题,我注意到 org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIndicator 有它的discoveryInitialized 字段设置为 false.这是因为没有人在应用程序上下文中触发 InstanceRegisteredEvent.通常事件应该从所谓的注册"的 start() 方法触发.- 负责在服务注册表中注册当前应用程序实例的 bean,例如EurekaAutoServiceRegistration 在 Eureka 的情况下.

Having the same issue, I've noticed that the org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIndicator has its discoveryInitialized field set to false. This is because no one triggered an InstanceRegisteredEvent in the application context. Usually the event should be triggered from the start() method of so called "registration" - a bean responsible for registration of current application instance in service registry, e.g. EurekaAutoServiceRegistration in case of Eureka.

关键是 Kubernetes 本身并不是一个服务注册中心,它不需要显式注册(因为由于编排的性质,其中的每个 pod 都是默认注册"的).这就是为什么 Spring Cloud Kubernetes 在默认情况下不会向 Kubernetes 注册应用程序实例的原因.

The point is that Kubernetes is not a service registry per se and it doesn't require explicit registration (because every pod within it is "registered" by default due to the nature of orchestration). That is why Spring Cloud Kubernetes does nothing by default to register the application instance with Kubernetes.

但是有 org.springframework.cloud.kubernetes.registry.KubernetesAutoServiceRegistration 类可以模拟"通过简单地向日志发送消息来自动注册的过程.从 v1.1.0 开始,这个类是 @Deprecated 并且在框架的其他地方没有使用.目前我看到使用它的唯一好处是它可以触发缺失的 InstanceRegisteredEvent 以初始化 DiscoveryClientHealthIndicator.您可以通过将以下 bean 声明添加到任何 @Configuration 类来使用它:

However there is org.springframework.cloud.kubernetes.registry.KubernetesAutoServiceRegistration class that can "emulate" the process of auto registration by simply emitting messages to the log. As of v1.1.0 this class is @Deprecated and has no usages in the framework elsewhere. The only profit I see of using it at the moment, is that it can trigger the missing InstanceRegisteredEvent for initializing the DiscoveryClientHealthIndicator. You can use it by adding the following bean declaration to any of your @Configuration classes:

@Bean
public KubernetesAutoServiceRegistration kubernetesAutoServiceRegistration(
         ApplicationContext context, 
         KubernetesServiceRegistry registry,
         KubernetesRegistration registration) {
  return new KubernetesAutoServiceRegistration(context, registry, registration);
}

但是请不要过度依赖它,因为它可能会在即将发布的框架版本中被删除.

But please do not rely on it heavily as it will likely be removed in forthcoming versions of the framework.

作为替代方案,您可以自己从代码中的某处发出 InstanceRegisteredEvent,但请确保在应用程序实际准备好与发现客户端一起使用时执行此操作.

As an alternative you can emit the InstanceRegisteredEvent by yourself somewhere from your code but make sure you do it when the application is actually ready to work with discovery client.

这篇关于Spring Actuator - 服务发现 -/health "description":"Discovery Client not initialized","status":"UNKNOWN"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆