This is an automated email from the ASF dual-hosted git repository. gongchao pushed a commit to branch bugfix-calculate in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
commit 729420337646316b84d027d7ad7db080b8c09987 Author: tomsun28 <[email protected]> AuthorDate: Mon Apr 29 13:25:37 2024 +0800 bugfix statistical metrics data matching fails Signed-off-by: tomsun28 <[email protected]> --- .../main/java/org/apache/hertzbeat/collector/util/CollectUtil.java | 2 +- .../java/org/apache/hertzbeat/collector/util/CollectUtilTest.java | 5 ++++- .../common/entity/manager/JsonLongListAttributeConverter.java | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/collector/src/main/java/org/apache/hertzbeat/collector/util/CollectUtil.java b/collector/src/main/java/org/apache/hertzbeat/collector/util/CollectUtil.java index 1eb8087c6..e0c1d7f54 100644 --- a/collector/src/main/java/org/apache/hertzbeat/collector/util/CollectUtil.java +++ b/collector/src/main/java/org/apache/hertzbeat/collector/util/CollectUtil.java @@ -113,7 +113,7 @@ public class CollectUtil { } catch (Exception e) { log.debug(e.getMessage()); } - return doubleAndUnit; + return null; } /** diff --git a/collector/src/test/java/org/apache/hertzbeat/collector/util/CollectUtilTest.java b/collector/src/test/java/org/apache/hertzbeat/collector/util/CollectUtilTest.java index da5ec6f72..66131d10a 100644 --- a/collector/src/test/java/org/apache/hertzbeat/collector/util/CollectUtilTest.java +++ b/collector/src/test/java/org/apache/hertzbeat/collector/util/CollectUtilTest.java @@ -18,6 +18,7 @@ package org.apache.hertzbeat.collector.util; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import com.fasterxml.jackson.core.JsonProcessingException; @@ -74,6 +75,7 @@ class CollectUtilTest { @Test void extractDoubleAndUnitFromStr() { CollectUtil.DoubleAndUnit res1 = CollectUtil.extractDoubleAndUnitFromStr("20.5%"); + assertNotNull(res1); assertEquals(20.5, res1.getValue()); assertEquals("%", res1.getUnit()); @@ -81,6 +83,7 @@ class CollectUtilTest { assertNull(res2); CollectUtil.DoubleAndUnit res3 = CollectUtil.extractDoubleAndUnitFromStr("KB"); + assertNotNull(res3); assertEquals(0, res3.getValue()); assertEquals("KB", res3.getUnit()); } @@ -156,4 +159,4 @@ class CollectUtilTest { void replaceUriSpecialChar() { assertEquals("google.com%20", CollectUtil.replaceUriSpecialChar("google.com ")); } -} \ No newline at end of file +} diff --git a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/JsonLongListAttributeConverter.java b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/JsonLongListAttributeConverter.java index f746adae4..e3b320bf4 100644 --- a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/JsonLongListAttributeConverter.java +++ b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/JsonLongListAttributeConverter.java @@ -43,6 +43,9 @@ public class JsonLongListAttributeConverter implements AttributeConverter<List<L if (StringUtils.isBlank(dbData)) { return List.of(); } + if (!JsonUtil.isJsonStr(dbData) && StringUtils.isNumeric(dbData)) { + return List.of(Long.parseLong(dbData)); + } TypeReference<List<Long>> typeReference = new TypeReference<>() { }; List<Long> longList = JsonUtil.fromJson(dbData, typeReference); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
