From cb4e76bcd1dc4bde3495c556aed2070296567781 Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Tue, 6 Feb 2024 15:27:28 +0800 Subject: [PATCH] 2.6 aaa --- .../function/health/HealthCheckObjectConfig.java | 2 ++ .../console/function/health/HealthExecutor.java | 13 ++++++++++--- .../health/callback/HealthCheckCallback.java | 4 ++-- .../health/check/impl/StorageRedisCheck.java | 9 +++++---- .../console/function/health/HealthExecutorTest.java | 9 +++++---- .../console/function/health/HealthServiceTest.java | 2 +- .../health/check/impl/StorageRedisCheckTest.java | 4 ++-- 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthCheckObjectConfig.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthCheckObjectConfig.java index 8f99424d..044f8902 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthCheckObjectConfig.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthCheckObjectConfig.java @@ -46,4 +46,6 @@ public class HealthCheckObjectConfig { //mysql private String database; + + private Long requestTimeoutMillis; } \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutor.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutor.java index 08631430..9e49ca75 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutor.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutor.java @@ -55,15 +55,20 @@ public void execute(AbstractHealthCheckService service) { //The callback interface is used to pass the processing methods for checking success and failure. service.doCheck(new HealthCheckCallback() { @Override - public void success() { + public void onSuccess() { //when the health check is successful, the result is updated to the memory cache. + Long latency = System.currentTimeMillis() - startTime; + //todo config this + if (latency > 3000){ + + } memoryCache.update(service.getConfig().getHealthCheckResourceType(), service.getConfig().getInstanceId(), HealthCheckStatus.PASSED, "health check success", - System.currentTimeMillis() - startTime); + ); } @Override - public void fail(Exception e) { + public void onFail(Exception e) { //when the health check fails, the result is updated to the memory cache, passing in the exception message. log.error("Health check failed for reason: {}. Service config is {}", e, service.getConfig()); memoryCache.update(service.getConfig().getHealthCheckResourceType(), service.getConfig().getInstanceId(), @@ -88,6 +93,8 @@ public void startExecute() { memoryCache.getCacheMap().forEach((type, subMap) -> { subMap.forEach((instanceId, result) -> { if (result.getStatus() == HealthCheckStatus.CHECKING) { + //todo + result.getLatencyMilliSeconds(); result.setStatus(HealthCheckStatus.TIMEOUT); } addToResultList(result, resultList); diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/callback/HealthCheckCallback.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/callback/HealthCheckCallback.java index 3e504f59..541d30c6 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/callback/HealthCheckCallback.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/callback/HealthCheckCallback.java @@ -24,7 +24,7 @@ * @see HealthExecutor */ public interface HealthCheckCallback { - public void success(); + public void onSuccess(); - public void fail(Exception e); + public void onFail(Exception e); } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRedisCheck.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRedisCheck.java index d28adabd..a6bcec73 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRedisCheck.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRedisCheck.java @@ -41,19 +41,20 @@ public StorageRedisCheck(HealthCheckObjectConfig healthCheckObjectConfig) { @Override public void doCheck(HealthCheckCallback callback) { try { + //TODO timeout RedisAsyncCommands commands = redisClient.connect().async(); commands.ping().thenAccept(result -> { - callback.success(); + callback.onSuccess(); }).exceptionally(e -> { if (e instanceof Exception) { - callback.fail((Exception) e); + callback.onFail((Exception) e); } else { - callback.fail(new RuntimeException("Internal server error")); + callback.onFail(new RuntimeException("RedisCheck failed.")); } return null; }); } catch (Exception e) { - callback.fail(e); + callback.onFail(e); } } diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutorTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutorTest.java index 676dd7bb..a833761a 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutorTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthExecutorTest.java @@ -69,12 +69,12 @@ class HealthExecutorTest { public void initMock() { Mockito.lenient().doAnswer((Answer) invocation -> { HealthCheckCallback callback = invocation.getArgument(0); - callback.success(); + callback.onSuccess(); return null; }).when(successHealthCheckService).doCheck(any(HealthCheckCallback.class)); Mockito.lenient().doAnswer((Answer) invocation -> { HealthCheckCallback callback = invocation.getArgument(0); - callback.fail(new RuntimeException("TestRuntimeException")); + callback.onFail(new RuntimeException("TestRuntimeException")); return null; }).when(failHealthCheckService).doCheck(any(HealthCheckCallback.class)); Mockito.lenient().doAnswer((Answer) invocation -> { @@ -85,7 +85,7 @@ public void initMock() { } catch (InterruptedException e) { return; } - callback.fail(new RuntimeException("TestRuntimeException")); + callback.onFail(new RuntimeException("TestRuntimeException")); }); return null; }).when(timeoutHealthCheckService).doCheck(any(HealthCheckCallback.class)); @@ -161,11 +161,12 @@ public void testTimeout() { } @Test - public void fullTest() { + public void testFull() throws InterruptedException { healthExecutor.startExecute(); healthExecutor.execute(successHealthCheckService); healthExecutor.execute(failHealthCheckService); healthExecutor.endExecute(); + Thread.sleep(1000); healthExecutor.startExecute(); healthExecutor.execute(successHealthCheckService); healthExecutor.execute(failHealthCheckService); diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthServiceTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthServiceTest.java index b34b7213..1cf771c8 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthServiceTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/HealthServiceTest.java @@ -104,7 +104,7 @@ public TestHealthCheckService(HealthCheckObjectConfig healthCheckObjectConfig) { @Override public void doCheck(HealthCheckCallback callback) { - callback.success(); + callback.onSuccess(); } @Override diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRedisCheckTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRedisCheckTest.java index b2cc1715..ff5be18f 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRedisCheckTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRedisCheckTest.java @@ -42,12 +42,12 @@ public void init() { public void testDoCheck() { storageRedisCheck.doCheck(new HealthCheckCallback() { @Override - public void success() { + public void onSuccess() { System.out.println("success"); } @Override - public void fail(Exception e) { + public void onFail(Exception e) { System.out.println("fail"); } });