From 034b1939dfd90599db97b1aacab2bf2d9c1c434f Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Wed, 21 Feb 2024 17:52:27 +0800 Subject: [PATCH 1/5] fix: let HealthExecutor support async doCheck --- .../console/health/CheckResultCache.java | 6 +- .../console/health/HealthExecutor.java | 11 ++- .../console/health/HealthService.java | 21 ++++-- .../check/config/HealthCheckObjectConfig.java | 4 ++ .../health/check/impl/StorageRedisCheck.java | 2 +- .../health/HealthServiceIntegrateTest.java | 70 +++++++++++++++++++ .../{ => unit}/health/HealthExecutorTest.java | 7 +- .../{ => unit}/health/HealthServiceTest.java | 8 ++- .../check/impl/StorageRedisCheckTest.java | 3 +- pom.xml | 11 +++ 10 files changed, 126 insertions(+), 17 deletions(-) create mode 100644 eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/integration/health/HealthServiceIntegrateTest.java rename eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/{ => unit}/health/HealthExecutorTest.java (96%) rename eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/{ => unit}/health/HealthServiceTest.java (90%) rename eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/{ => unit}/health/check/impl/StorageRedisCheckTest.java (92%) diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java index 540e3832..3fdf9601 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java @@ -41,8 +41,10 @@ public void update(String type, Long typeId, HealthCheckStatus status, String re cacheMap.put(type, subMap); } CheckResult oldResult = subMap.get(typeId); - String oldDesc = Objects.isNull(oldResult.getResultDesc()) ? "" : oldResult.getResultDesc() + "\n"; - CheckResult result = new CheckResult(status, oldDesc + resultDesc, LocalDateTime.now(), + String oldDesc = Objects.isNull(oldResult.getResultDesc()) || oldResult.getResultDesc().isEmpty() ? "" : oldResult.getResultDesc() + "\n"; + String description = oldDesc + resultDesc; + description += " Latency: " + latency.toString() + "ms"; + CheckResult result = new CheckResult(status, description, LocalDateTime.now(), latency, oldResult.getConfig()); subMap.put(typeId, result); } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthExecutor.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthExecutor.java index 765bdab9..49d76e22 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthExecutor.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthExecutor.java @@ -26,6 +26,8 @@ import org.apache.eventmesh.dashboard.console.service.health.HealthDataService; import java.util.ArrayList; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import lombok.Getter; import lombok.Setter; @@ -44,6 +46,8 @@ public class HealthExecutor { @Setter private CheckResultCache memoryCache; + private final ExecutorService executorService = Executors.newCachedThreadPool(); + /** * execute function is where health check services work. * @@ -58,7 +62,7 @@ public void execute(AbstractHealthCheckService service) { memoryCache.update(service.getConfig().getHealthCheckResourceType(), service.getConfig().getInstanceId(), HealthCheckStatus.CHECKING, "", null, service.getConfig()); //The callback interface is used to pass the processing methods for checking success and failure. - service.doCheck(new HealthCheckCallback() { + executorService.submit(() -> service.doCheck(new HealthCheckCallback() { @Override public void onSuccess() { //when the health check is successful, the result is updated to the memory cache. @@ -66,7 +70,7 @@ public void onSuccess() { HealthCheckStatus status = latency > service.getConfig().getRequestTimeoutMillis() ? HealthCheckStatus.TIMEOUT : HealthCheckStatus.PASSED; memoryCache.update(service.getConfig().getHealthCheckResourceType(), service.getConfig().getInstanceId(), - status, "health check success", latency + status, "Health check succeed.", latency ); } @@ -78,7 +82,8 @@ public void onFail(Exception e) { HealthCheckStatus.FAILED, e.getMessage(), System.currentTimeMillis() - startTime); } - }); + })); + } catch (Exception e) { log.error("Health check failed for reason: {}. Service config is {}", e, service.getConfig()); memoryCache.update(service.getConfig().getHealthCheckResourceType(), service.getConfig().getInstanceId(), HealthCheckStatus.FAILED, diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthService.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthService.java index 39485e19..333fa995 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthService.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/HealthService.java @@ -68,7 +68,7 @@ private static void setClassCache(Class clazz) { * * @see AbstractHealthCheckService */ - private Map> checkServiceMap = new ConcurrentHashMap<>(); + private final Map> checkServiceMap = new ConcurrentHashMap<>(); private ScheduledThreadPoolExecutor scheduledExecutor; @@ -87,10 +87,13 @@ public void insertCheckService(HealthCheckObjectConfig config) { if (Objects.nonNull(config.getSimpleClassName())) { Class clazz = HEALTH_CHECK_CLASS_CACHE.get(config.getSimpleClassName()); healthCheckService = createCheckService(clazz, config); - //if simpleClassName is null, use type(storage) and subType(redis) to create healthCheckService + // you can pass an object to create a HealthCheckService(not commonly used) + } else if (Objects.nonNull(config.getCheckClass())) { + healthCheckService = createCheckService(config.getCheckClass(), config); + //if simpleClassName and CheckClass are both null, use type(storage) and subType(redis) to create healthCheckService + //This is the default create method. //healthCheckService is annotated with @HealthCheckType(type = "storage", subType = "redis") - } else if (Objects.isNull(config.getSimpleClassName()) - && Objects.nonNull(config.getHealthCheckResourceType()) && Objects.nonNull( + } else if (Objects.nonNull(config.getHealthCheckResourceType()) && Objects.nonNull( config.getHealthCheckResourceSubType())) { for (Entry> entry : HEALTH_CHECK_CLASS_CACHE.entrySet()) { Class clazz = entry.getValue(); @@ -101,9 +104,6 @@ public void insertCheckService(HealthCheckObjectConfig config) { break; } } - // you can pass an object to create a HealthCheckService(not commonly used) - } else if (Objects.nonNull(config.getCheckClass())) { - healthCheckService = createCheckService(config.getCheckClass(), config); } } catch (Exception e) { log.error("create healthCheckService failed, healthCheckObjectConfig:{}", config, e); @@ -113,6 +113,13 @@ public void insertCheckService(HealthCheckObjectConfig config) { if (Objects.isNull(healthCheckService)) { throw new RuntimeException("No construct method of Health Check Service is found, config is {}" + config); } + insertCheckService(healthCheckService); + } + + public void insertCheckService(AbstractHealthCheckService checkService) { + Map subMap = checkServiceMap.computeIfAbsent(checkService.getConfig().getHealthCheckResourceType(), + k -> new ConcurrentHashMap<>()); + subMap.put(checkService.getConfig().getInstanceId(), checkService); } public void deleteCheckService(String resourceType, Long resourceId) { diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/config/HealthCheckObjectConfig.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/config/HealthCheckObjectConfig.java index c33931b8..8c350b43 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/config/HealthCheckObjectConfig.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/config/HealthCheckObjectConfig.java @@ -17,6 +17,8 @@ package org.apache.eventmesh.dashboard.console.health.check.config; +import java.util.Properties; + import lombok.Data; @Data @@ -32,6 +34,8 @@ public class HealthCheckObjectConfig { private Class checkClass; + private Properties eventmeshProperties; + private Long clusterId; private String connectUrl; diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheck.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheck.java index dcf05827..00cfad8e 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheck.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheck.java @@ -77,6 +77,6 @@ public void init() { } redisUrl = builder.build().toString(); } - RedisClient redisClient = RedisClient.create(redisUrl); + redisClient = RedisClient.create(redisUrl); } } diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/integration/health/HealthServiceIntegrateTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/integration/health/HealthServiceIntegrateTest.java new file mode 100644 index 00000000..7afb52f0 --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/integration/health/HealthServiceIntegrateTest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.dashboard.console.integration.health; + +import java.util.List; +import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; +import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckType; +import org.apache.eventmesh.dashboard.console.health.CheckResultCache; +import org.apache.eventmesh.dashboard.console.health.HealthService; +import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; +import org.apache.eventmesh.dashboard.console.service.health.HealthDataService; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; + +@SpringBootTest +@ActiveProfiles("test") +@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:use-test-schema.sql", "classpath:eventmesh-dashboard.sql"}) +public class HealthServiceIntegrateTest { + HealthService healthService = new HealthService(); + + @Autowired + private HealthDataService healthDataService; + + private final CheckResultCache checkResultCache = new CheckResultCache(); + @BeforeEach + void init() { + healthService.createExecutor(healthDataService, checkResultCache); + } + + @Test + void testStorageRedis() throws InterruptedException { + HealthCheckObjectConfig config = new HealthCheckObjectConfig(); + config.setClusterId(1L); + config.setInstanceId(1L); + config.setHealthCheckResourceType("storage"); + config.setHealthCheckResourceSubType("redis"); + config.setConnectUrl("redis://localhost:6379"); + healthService.insertCheckService(config); + healthService.executeAll(); + Thread.sleep(1000); + healthService.executeAll(); + + HealthCheckResultEntity queryEntity = new HealthCheckResultEntity(); + queryEntity.setClusterId(1L); + queryEntity.setType(HealthCheckType.STORAGE.getNumber()); + queryEntity.setTypeId(1L); + List results = healthDataService.queryHealthCheckResultByClusterIdAndTypeAndTypeId(queryEntity); + Assertions.assertEquals(2,results.size()); + } +} diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthExecutorTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthExecutorTest.java similarity index 96% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthExecutorTest.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthExecutorTest.java index c2bc1780..32d27c3a 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthExecutorTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthExecutorTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health; +package org.apache.eventmesh.dashboard.console.unit.health; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -27,6 +27,8 @@ import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckStatus; import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckType; +import org.apache.eventmesh.dashboard.console.health.CheckResultCache; +import org.apache.eventmesh.dashboard.console.health.HealthExecutor; import org.apache.eventmesh.dashboard.console.health.callback.HealthCheckCallback; import org.apache.eventmesh.dashboard.console.health.check.AbstractHealthCheckService; import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; @@ -113,9 +115,10 @@ public void initMock() { } @Test - public void testExecute() { + public void testExecute() throws InterruptedException { healthExecutor.execute(successHealthCheckService); healthExecutor.execute(failHealthCheckService); + Thread.sleep(1000); assertEquals(2, memoryCache.getCacheMap().get("storage").size()); assertNotEquals(memoryCache.getCacheMap().get("storage").get(1L).getStatus(), memoryCache.getCacheMap().get("storage").get(2L).getStatus()); } diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthServiceTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthServiceTest.java similarity index 90% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthServiceTest.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthServiceTest.java index 278852fa..e630ab87 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthServiceTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthServiceTest.java @@ -15,10 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health; +package org.apache.eventmesh.dashboard.console.unit.health; import static org.junit.jupiter.api.Assertions.assertEquals; +import org.apache.eventmesh.dashboard.console.health.CheckResultCache; +import org.apache.eventmesh.dashboard.console.health.HealthService; import org.apache.eventmesh.dashboard.console.health.callback.HealthCheckCallback; import org.apache.eventmesh.dashboard.console.health.check.AbstractHealthCheckService; import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; @@ -60,6 +62,8 @@ void testInsertCheckServiceWithSimpleClassName() { HealthCheckObjectConfig config = new HealthCheckObjectConfig(); config.setInstanceId(1L); config.setSimpleClassName("StorageRedisCheck"); + config.setHealthCheckResourceType("storage"); + config.setHealthCheckResourceSubType("redis"); config.setClusterId(1L); config.setConnectUrl("redis://localhost:6379"); healthService.insertCheckService(config); @@ -69,6 +73,8 @@ void testInsertCheckServiceWithSimpleClassName() { void testInsertCheckServiceWithClass() { HealthCheckObjectConfig config = new HealthCheckObjectConfig(); config.setInstanceId(1L); + config.setHealthCheckResourceType("storage"); + config.setHealthCheckResourceSubType("redis"); config.setClusterId(1L); config.setCheckClass(TestHealthCheckService.class); healthService.insertCheckService(config); diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheckTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/check/impl/StorageRedisCheckTest.java similarity index 92% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheckTest.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/check/impl/StorageRedisCheckTest.java index d7c5a585..dbcc0605 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheckTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/check/impl/StorageRedisCheckTest.java @@ -15,10 +15,11 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.health.check.impl; +package org.apache.eventmesh.dashboard.console.unit.health.check.impl; import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; import org.apache.eventmesh.dashboard.console.health.callback.HealthCheckCallback; +import org.apache.eventmesh.dashboard.console.health.check.impl.StorageRedisCheck; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/pom.xml b/pom.xml index 59cb1874..68372bf7 100644 --- a/pom.xml +++ b/pom.xml @@ -135,6 +135,17 @@ + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.2 + + + **/org/apache/eventmesh/dashboard/console/integration/**/*.java + + + \ No newline at end of file From 403d2d4677c5550a24e6b64fb9c38a4c65ad012f Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Thu, 22 Feb 2024 15:05:22 +0800 Subject: [PATCH 2/5] chore: move test files out of unit folder --- .../console/{unit => }/health/HealthExecutorTest.java | 4 +--- .../console/{unit => }/health/HealthServiceTest.java | 6 +----- .../{unit => }/health/check/impl/StorageRedisCheckTest.java | 3 +-- 3 files changed, 3 insertions(+), 10 deletions(-) rename eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/{unit => }/health/HealthExecutorTest.java (97%) rename eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/{unit => }/health/HealthServiceTest.java (94%) rename eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/{unit => }/health/check/impl/StorageRedisCheckTest.java (92%) diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthExecutorTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthExecutorTest.java similarity index 97% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthExecutorTest.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthExecutorTest.java index 32d27c3a..2c5e49c8 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthExecutorTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthExecutorTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.unit.health; +package org.apache.eventmesh.dashboard.console.health; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -27,8 +27,6 @@ import org.apache.eventmesh.dashboard.console.entity.health.HealthCheckResultEntity; import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckStatus; import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckType; -import org.apache.eventmesh.dashboard.console.health.CheckResultCache; -import org.apache.eventmesh.dashboard.console.health.HealthExecutor; import org.apache.eventmesh.dashboard.console.health.callback.HealthCheckCallback; import org.apache.eventmesh.dashboard.console.health.check.AbstractHealthCheckService; import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthServiceTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthServiceTest.java similarity index 94% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthServiceTest.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthServiceTest.java index e630ab87..06343fd8 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/HealthServiceTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/HealthServiceTest.java @@ -15,12 +15,8 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.unit.health; +package org.apache.eventmesh.dashboard.console.health; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.apache.eventmesh.dashboard.console.health.CheckResultCache; -import org.apache.eventmesh.dashboard.console.health.HealthService; import org.apache.eventmesh.dashboard.console.health.callback.HealthCheckCallback; import org.apache.eventmesh.dashboard.console.health.check.AbstractHealthCheckService; import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/check/impl/StorageRedisCheckTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheckTest.java similarity index 92% rename from eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/check/impl/StorageRedisCheckTest.java rename to eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheckTest.java index dbcc0605..d7c5a585 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/health/check/impl/StorageRedisCheckTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/health/check/impl/StorageRedisCheckTest.java @@ -15,11 +15,10 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.unit.health.check.impl; +package org.apache.eventmesh.dashboard.console.health.check.impl; import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; import org.apache.eventmesh.dashboard.console.health.callback.HealthCheckCallback; -import org.apache.eventmesh.dashboard.console.health.check.impl.StorageRedisCheck; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; From 7db1411e16363dcb0d7bec000ff711a403018831 Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Fri, 23 Feb 2024 18:42:49 +0800 Subject: [PATCH 3/5] chore: add HealthConstant --- .../console/constant/HealthConstant.java | 22 +++++++++++++++++++ .../console/health/CheckResultCache.java | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/HealthConstant.java diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/HealthConstant.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/HealthConstant.java new file mode 100644 index 00000000..16052008 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/HealthConstant.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.dashboard.console.constant; + +public class HealthConstant { + public static final String HEALTH_NEW_LINE_ENDING = "\n"; +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java index 3fdf9601..135ba9f4 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java @@ -17,6 +17,8 @@ package org.apache.eventmesh.dashboard.console.health; +import static org.apache.eventmesh.dashboard.console.constant.HealthConstant.HEALTH_NEW_LINE_ENDING; + import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckStatus; import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; @@ -41,7 +43,8 @@ public void update(String type, Long typeId, HealthCheckStatus status, String re cacheMap.put(type, subMap); } CheckResult oldResult = subMap.get(typeId); - String oldDesc = Objects.isNull(oldResult.getResultDesc()) || oldResult.getResultDesc().isEmpty() ? "" : oldResult.getResultDesc() + "\n"; + String oldDesc = Objects.isNull(oldResult.getResultDesc()) || oldResult.getResultDesc().isEmpty() ? "" + : oldResult.getResultDesc() + HEALTH_NEW_LINE_ENDING; String description = oldDesc + resultDesc; description += " Latency: " + latency.toString() + "ms"; CheckResult result = new CheckResult(status, description, LocalDateTime.now(), From d276bff216fde0298057091f06d4a935dcdf5974 Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Mon, 26 Feb 2024 09:30:44 +0800 Subject: [PATCH 4/5] chore --- .../eventmesh/dashboard/console/constant/HealthConstant.java | 2 +- .../eventmesh/dashboard/console/health/CheckResultCache.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/HealthConstant.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/HealthConstant.java index 16052008..979f5783 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/HealthConstant.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/constant/HealthConstant.java @@ -18,5 +18,5 @@ package org.apache.eventmesh.dashboard.console.constant; public class HealthConstant { - public static final String HEALTH_NEW_LINE_ENDING = "\n"; + public static final String NEW_LINE_ENDING = "\n"; } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java index 135ba9f4..d84b6b8c 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java @@ -17,8 +17,7 @@ package org.apache.eventmesh.dashboard.console.health; -import static org.apache.eventmesh.dashboard.console.constant.HealthConstant.HEALTH_NEW_LINE_ENDING; - +import org.apache.eventmesh.dashboard.console.constant.HealthConstant; import org.apache.eventmesh.dashboard.console.enums.health.HealthCheckStatus; import org.apache.eventmesh.dashboard.console.health.check.config.HealthCheckObjectConfig; @@ -44,7 +43,7 @@ public void update(String type, Long typeId, HealthCheckStatus status, String re } CheckResult oldResult = subMap.get(typeId); String oldDesc = Objects.isNull(oldResult.getResultDesc()) || oldResult.getResultDesc().isEmpty() ? "" - : oldResult.getResultDesc() + HEALTH_NEW_LINE_ENDING; + : oldResult.getResultDesc() + HealthConstant.NEW_LINE_ENDING; String description = oldDesc + resultDesc; description += " Latency: " + latency.toString() + "ms"; CheckResult result = new CheckResult(status, description, LocalDateTime.now(), From 03be1d650200aad0fa8da31dca6cde9b5328032f Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Fri, 1 Mar 2024 13:58:50 +0800 Subject: [PATCH 5/5] style: rewrite description assign in CheckResultCache in if-else --- .../dashboard/console/health/CheckResultCache.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java index d84b6b8c..66dcd44d 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/health/CheckResultCache.java @@ -42,9 +42,10 @@ public void update(String type, Long typeId, HealthCheckStatus status, String re cacheMap.put(type, subMap); } CheckResult oldResult = subMap.get(typeId); - String oldDesc = Objects.isNull(oldResult.getResultDesc()) || oldResult.getResultDesc().isEmpty() ? "" - : oldResult.getResultDesc() + HealthConstant.NEW_LINE_ENDING; - String description = oldDesc + resultDesc; + String description = resultDesc; + if (oldResult.getResultDesc() != null && !oldResult.getResultDesc().isEmpty()) { + description = oldResult.getResultDesc() + HealthConstant.NEW_LINE_ENDING + resultDesc; + } description += " Latency: " + latency.toString() + "ms"; CheckResult result = new CheckResult(status, description, LocalDateTime.now(), latency, oldResult.getConfig()); @@ -57,7 +58,6 @@ public void update(String type, Long typeId, HealthCheckStatus status, String re subMap = new HashMap<>(); cacheMap.put(type, subMap); } - CheckResult resultToUpdate = subMap.get(typeId); subMap.put(typeId, new CheckResult(status, resultDesc, LocalDateTime.now(), latency, config)); }