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

359 Views Asked by At

I have to implement readiness probe for every service in my spring boot app.

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?

  1. Write ServiceAHealthIndicator class, that will request service A liveness endpoint. And then include this health indicator in application.yml by property menagment.endpoint.health.group.readiness.include=ServiceA

  2. In Kubernetes configuration add endpoint serviceA/liveness to readiness. Maybe something like:

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

There are 1 best solutions below

2
On

In my opinion, liveness and readiness endpoints of service B should not be called by service A. These endpoints are there for Kubernetes to know how to handle specific containers.

So the service A should call service B business endpoints as usual. E.g. if B exposes an operation add(x, y), then that's the operation A should call.

To make sure failures (of degrade of service, like latency) of B are handled properly in 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.

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.