简体   繁体   English

如何在另一个就绪探测中测试一项服务?

[英]How to test one service in another's readiness probe?

I have to implement readiness probe for every service in my spring boot app.我必须为我的 spring 启动应用程序中的每项服务实施就绪探测。

Every of my services in application expose liveness and readiness endpoints.我在应用程序中的每个服务都公开了活跃性和就绪性端点。

Some of my services depends on others.我的一些服务依赖于其他服务。

The question is: How to check service A in readiness of service B?问题是:如何检查服务 A 是否准备好服务 B?

  1. Write ServiceAHealthIndicator class, that will request service A liveness endpoint.编写 ServiceAHealthIndicator class,它将请求服务 A 活性端点。 And then include this health indicator in application.yml by property menagment.endpoint.health.group.readiness.include=ServiceA然后通过属性 menagment.endpoint.health.group.readiness.include=ServiceA 在 application.yml 中包含此健康指标

  2. In Kube.netes configuration add endpoint serviceA/liveness to readiness.在 Kube.netes 配置中添加端点 serviceA/liveness 以准备就绪。 Maybe something like:也许是这样的:

readinessProbe:
   httpGet:
    path: serviceA/health/liveness
    port: 8000

In my opinion, liveness and readiness endpoints of service B should not be called by service A. These endpoints are there for Kube.netes to know how to handle specific containers.在我看来,服务 B 的活性和就绪端点不应该被服务 A 调用。这些端点是为了让 Kube.netes 知道如何处理特定的容器。

So the service A should call service B business endpoints as usual.所以服务 A 应该像往常一样调用服务 B 业务端点。 Eg if B exposes an operation add(x, y), then that's the operation A should call.例如,如果 B 公开了一个操作 add(x, y),那么这就是 A 应该调用的操作。

To make sure failures (of degrade of service, like latency) of B are handled properly in A;确保 B 的故障(服务降级,如延迟)在 A 中得到妥善处理; A should use Circuit Breaker pattern ( https://en.wikipedia.org/wiki/Circuit_breaker_design_pattern ) - this will allow A to handle B's failures in more predictable way. A 应该使用断路器模式 ( https://en.wikipedia.org/wiki/Circuit_breaker_design_pattern ) - 这将允许 A 以更可预测的方式处理 B 的故障。

Usually, services don't check their dependencies health with a dedicated call.通常,服务不会通过专门的调用来检查它们的依赖项健康状况。 This is because the logic around making those checks is both complicated and slow.这是因为进行这些检查的逻辑既复杂又缓慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM