I am running a rest service based on Eclipse Microprofile. My service provides a health check. The result of such a health check (which is providing a lot of information) looks for example like this:
http://localhost:9990/health
HTTP=OK
{
"status":"UP",
"checks":[
{"name":"imixs-workflow",
"status":"UP",
"data":
{
"engine.version":"5.1.11-SNAPSHOT",
"model.groups":30,
"model.versions":20
}
}
]
}
The service is healthy if the check named 'imixs-workflow' shows the 'status' 'UP'.
I already tried to configure this with a livenessprobe like this:
livenessProbe:
exec:
command: ["sh", "-c", "curl -s http://localhost:9990/health| grep -q imixs-workflow"]
initialDelaySeconds: 60
But this did not work.
How should I configure such a livenessprobe getting the status of a specific json field in a http result?
Your liveness probe command should return status different from 0 to indicate unhealthy container condition. Please see Configure Liveness, Readiness and Startup Probes.
If possible, I'd also recommend for better maintainability and readability to use the tool called jq - command-line JSON processor.
With it your probe should look something like this:
livenessProbe:
exec:
command: ["sh", "-c", "curl -s http://localhost:9990/health | jq -e '.checks[] | select(.name == "imixs-workflow") | .status == "UP"']
initialDelaySeconds: 60
Here -e
flag sets exit status to 1 if the last output value was false.