From 06f10beb8743438a93497bcf84db99871e9263fd Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Tue, 27 Aug 2024 13:39:38 -0600 Subject: [PATCH] Refactored HealthService to use standard names for the liveness and readiness endpoints to livez and readyz Signed-off-by: Alfredo Gutierrez --- charts/hedera-block-node/values.yaml | 4 ++-- .../block/server/health/HealthService.java | 4 ++-- .../server/health/HealthServiceImpl.java | 12 +++++------ .../server/health/HealthServiceTest.java | 20 +++++++++---------- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/charts/hedera-block-node/values.yaml b/charts/hedera-block-node/values.yaml index 68b8d40b6..e36bd343f 100644 --- a/charts/hedera-block-node/values.yaml +++ b/charts/hedera-block-node/values.yaml @@ -84,6 +84,6 @@ blockNode: PRIVATE_KEY: "fake_private_key" health: readiness: - endpoint: "/healthz/readiness" + endpoint: "/healthz/readyz" liveness: - endpoint: "/healthz/liveness" + endpoint: "/healthz/livez" diff --git a/server/src/main/java/com/hedera/block/server/health/HealthService.java b/server/src/main/java/com/hedera/block/server/health/HealthService.java index 2581655d4..e18b37a17 100644 --- a/server/src/main/java/com/hedera/block/server/health/HealthService.java +++ b/server/src/main/java/com/hedera/block/server/health/HealthService.java @@ -37,7 +37,7 @@ public interface HealthService extends HttpService { * @param req the server request * @param res the server response */ - void handleLiveness(@NonNull final ServerRequest req, @NonNull final ServerResponse res); + void handleLivez(@NonNull final ServerRequest req, @NonNull final ServerResponse res); /** * Handles the request for readiness endpoint, that it most be defined on routing @@ -46,5 +46,5 @@ public interface HealthService extends HttpService { * @param req the server request * @param res the server response */ - void handleReadiness(@NonNull final ServerRequest req, @NonNull final ServerResponse res); + void handleReadyz(@NonNull final ServerRequest req, @NonNull final ServerResponse res); } diff --git a/server/src/main/java/com/hedera/block/server/health/HealthServiceImpl.java b/server/src/main/java/com/hedera/block/server/health/HealthServiceImpl.java index 0f622866d..8c0944823 100644 --- a/server/src/main/java/com/hedera/block/server/health/HealthServiceImpl.java +++ b/server/src/main/java/com/hedera/block/server/health/HealthServiceImpl.java @@ -28,8 +28,8 @@ @Singleton public class HealthServiceImpl implements HealthService { - private static final String LIVENESS_PATH = "/liveness"; - private static final String READINESS_PATH = "/readiness"; + private static final String LIVEZ_PATH = "/livez"; + private static final String READYZ_PATH = "/readyz"; private final ServiceStatus serviceStatus; @@ -56,9 +56,7 @@ public String getHealthRootPath() { */ @Override public void routing(@NonNull final HttpRules httpRules) { - httpRules - .get(LIVENESS_PATH, this::handleLiveness) - .get(READINESS_PATH, this::handleReadiness); + httpRules.get(LIVEZ_PATH, this::handleLivez).get(READYZ_PATH, this::handleReadyz); } /** @@ -68,7 +66,7 @@ public void routing(@NonNull final HttpRules httpRules) { * @param res the server response */ @Override - public final void handleLiveness( + public final void handleLivez( @NonNull final ServerRequest req, @NonNull final ServerResponse res) { if (serviceStatus.isRunning()) { res.status(200).send("OK"); @@ -85,7 +83,7 @@ public final void handleLiveness( * @param res the server response */ @Override - public final void handleReadiness( + public final void handleReadyz( @NonNull final ServerRequest req, @NonNull final ServerResponse res) { if (serviceStatus.isRunning()) { res.status(200).send("OK"); diff --git a/server/src/test/java/com/hedera/block/server/health/HealthServiceTest.java b/server/src/test/java/com/hedera/block/server/health/HealthServiceTest.java index df2aed07f..55f91197d 100644 --- a/server/src/test/java/com/hedera/block/server/health/HealthServiceTest.java +++ b/server/src/test/java/com/hedera/block/server/health/HealthServiceTest.java @@ -31,8 +31,8 @@ @ExtendWith(MockitoExtension.class) class HealthServiceTest { - private static final String READINESS_PATH = "/readiness"; - private static final String LIVENESS_PATH = "/liveness"; + private static final String READINESS_PATH = "/readyz"; + private static final String LIVENESS_PATH = "/livez"; private static final String HEALTH_PATH = "/healthz"; @Mock private ServiceStatus serviceStatus; @@ -42,7 +42,7 @@ class HealthServiceTest { @Mock ServerResponse serverResponse; @Test - public void testHandleLiveness() { + public void testHandleLivez() { // given when(serviceStatus.isRunning()).thenReturn(true); when(serverResponse.status(200)).thenReturn(serverResponse); @@ -50,7 +50,7 @@ public void testHandleLiveness() { HealthService healthService = new HealthServiceImpl(serviceStatus); // when - healthService.handleLiveness(serverRequest, serverResponse); + healthService.handleLivez(serverRequest, serverResponse); // then verify(serverResponse, times(1)).status(200); @@ -58,7 +58,7 @@ public void testHandleLiveness() { } @Test - public void testHandleLiveness_notRunning() { + public void testHandleLivez_notRunning() { // given when(serviceStatus.isRunning()).thenReturn(false); when(serverResponse.status(503)).thenReturn(serverResponse); @@ -66,7 +66,7 @@ public void testHandleLiveness_notRunning() { HealthService healthService = new HealthServiceImpl(serviceStatus); // when - healthService.handleLiveness(serverRequest, serverResponse); + healthService.handleLivez(serverRequest, serverResponse); // then verify(serverResponse, times(1)).status(503); @@ -74,7 +74,7 @@ public void testHandleLiveness_notRunning() { } @Test - public void testHandleReadiness() { + public void testHandleReadyz() { // given when(serviceStatus.isRunning()).thenReturn(true); when(serverResponse.status(200)).thenReturn(serverResponse); @@ -82,7 +82,7 @@ public void testHandleReadiness() { HealthService healthService = new HealthServiceImpl(serviceStatus); // when - healthService.handleReadiness(serverRequest, serverResponse); + healthService.handleReadyz(serverRequest, serverResponse); // then verify(serverResponse, times(1)).status(200); @@ -90,7 +90,7 @@ public void testHandleReadiness() { } @Test - public void testHandleReadiness_notRunning() { + public void testHandleReadyz_notRunning() { // given when(serviceStatus.isRunning()).thenReturn(false); when(serverResponse.status(503)).thenReturn(serverResponse); @@ -98,7 +98,7 @@ public void testHandleReadiness_notRunning() { HealthService healthService = new HealthServiceImpl(serviceStatus); // when - healthService.handleReadiness(serverRequest, serverResponse); + healthService.handleReadyz(serverRequest, serverResponse); // then verify(serverResponse, times(1)).status(503);