Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actuator healthcheck #1103

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

charlesmst
Copy link

This is the initial work for #1091.

It is only implementing the check now, but watch will be added later by pushing metrics every 30s as @ST-DDT suggested.

I was wondering if this should be the default behavior when the actuator is present, so I added a property to enable this instead of the GRPC standard health endpoint.

@charlesmst charlesmst changed the title Actuator healthcheck #1093 Actuator healthcheck #1091 May 2, 2024
@charlesmst charlesmst changed the title Actuator healthcheck #1091 Actuator healthcheck May 2, 2024
Copy link
Collaborator

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently buzy with work, so reviews will take a while.

public void check(HealthCheckRequest request, StreamObserver<HealthCheckResponse> responseObserver) {

if (!request.getService().isEmpty()) {
var health = healthEndpoint.healthForPath(request.getService());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of our code doesn't use var.

Comment on lines 63 to 70
if (Objects.equals(org.springframework.boot.actuate.health.Status.UP.getCode(), status.getCode())) {
return HealthCheckResponse.ServingStatus.SERVING;
}
if (Objects.equals(org.springframework.boot.actuate.health.Status.DOWN.getCode(), status.getCode()) || Objects
.equals(org.springframework.boot.actuate.health.Status.OUT_OF_SERVICE.getCode(), status.getCode())) {
return HealthCheckResponse.ServingStatus.NOT_SERVING;
}
return HealthCheckResponse.ServingStatus.UNKNOWN;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO these checks can be simplified to:

org.springframework.boot.actuate.health.Status.UP.equals(status)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to Status.UP.equals(status) in the UP condition, but I am not sure if you meant just replacing the object equals comparing code to use the class equals, or not having the DOWN and OUT_OF_SERVICE cases and just returning NOT_SERVING for everything else, can you clarify this part?

Comment on lines 23 to 30
/**
* Use the standard GRPC health service from io.grpc.
*/
GRPC,
/**
* Uses a bridge to the Spring Boot Actuator health service.
*/
ACTUATOR,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add @see / {@link} links to the implementation classes.

@@ -228,6 +228,14 @@ public class GrpcServerProperties {
*/
private boolean healthServiceEnabled = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe deprecate this in favor of HealthType.NONE

* @param healthServiceType The implementation of gRPC health service.
* @return GRPC or Actuator.
*/
private HealthType healthServiceType = HealthType.GRPC;
Copy link
Collaborator

@ST-DDT ST-DDT May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Should we create a nested object for this?
That would give the potential later update frequency a place for its property.
If we don't plan to add it for now, we can leave it as is for now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, maybe with Watch a new property will be necessary for the interval between checks. I will change to a nested object

docs/en/actuator.md Outdated Show resolved Hide resolved
docs/en/actuator.md Outdated Show resolved Hide resolved
var health = healthEndpoint.healthForPath(request.getService());
if (health == null) {
responseObserver.onError(new StatusException(
Status.NOT_FOUND.withDescription("unknown service " + request.getService())));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status is only used once here and maybe that can be avoided with statically importing NOT_FOUND, then you could import org.springframework.boot.actuate.health.Status instead and make it easier to read.

(I wish Java would support import aliasing)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Code changed accordingly

@ST-DDT ST-DDT added the enhancement A feature request or improvement label May 8, 2024
charlesmst and others added 7 commits May 10, 2024 14:30
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
…pc/server/autoconfigure/GrpcHealthServiceTrueActuatorConfigurationTest.java

Co-authored-by: ST-DDT <ST-DDT@gmx.de>
…pc/server/health/ActuatorGrpcHealthTest.java

Co-authored-by: ST-DDT <ST-DDT@gmx.de>
@charlesmst charlesmst force-pushed the actuator-healthcheck branch 2 times, most recently from 459c018 to dc3e521 Compare May 10, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature request or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants