This is an automated email from the ASF dual-hosted git repository.
gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new bd52e0527 [bugfix] fix extract double and unit error when unit is Ki
(#2099)
bd52e0527 is described below
commit bd52e0527ead230315bf8bed15fcbdf98a192671
Author: liutianyou <[email protected]>
AuthorDate: Wed Jun 19 21:46:20 2024 +0800
[bugfix] fix extract double and unit error when unit is Ki (#2099)
---
.../java/org/apache/hertzbeat/collector/util/CollectUtil.java | 4 ++--
.../org/apache/hertzbeat/collector/util/CollectUtilTest.java | 9 +++++++++
2 files changed, 11 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 487a2e268..c7bf5022a 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
@@ -55,7 +55,7 @@ public final class CollectUtil {
private static final String CRYING_PLACEHOLDER_REX = "\\^o\\^";
private static final String CRYING_PLACEHOLDER_REGEX =
"(\\^o\\^)(\\w|-|$|\\.)+(\\^o\\^)";
private static final Pattern CRYING_PLACEHOLDER_REGEX_PATTERN =
Pattern.compile(CRYING_PLACEHOLDER_REGEX);
- private static final List<String> UNIT_SYMBOLS = Arrays.asList("%", "G",
"g", "M", "m", "K", "k", "B", "b");
+ private static final List<String> UNIT_SYMBOLS = Arrays.asList("%", "G",
"g", "M", "m", "K", "k", "B", "b", "Ki", "Mi", "Gi");
/**
* private constructor, not allow to create instance.
@@ -104,7 +104,7 @@ public final class CollectUtil {
log.debug(e.getMessage());
}
- if (!str.matches(DOUBLE_AND_UNIT_CHECK_REGEX)){
+ if (!str.matches(DOUBLE_AND_UNIT_CHECK_REGEX)) {
return doubleAndUnit;
}
// extract unit from str value, eg: 23.43GB, 33KB, 44.22G
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 f0f70cf14..1b85ddce8 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
@@ -81,6 +81,15 @@ class CollectUtilTest {
assertNull(res4.getValue());
assertNull(res4.getUnit());
+ CollectUtil.DoubleAndUnit res5 =
CollectUtil.extractDoubleAndUnitFromStr("200Ki");
+ assertEquals(200, res5.getValue());
+ assertEquals("Ki", res5.getUnit());
+ CollectUtil.DoubleAndUnit res6 =
CollectUtil.extractDoubleAndUnitFromStr("200Mi");
+ assertEquals(200, res6.getValue());
+ assertEquals("Mi", res6.getUnit());
+ CollectUtil.DoubleAndUnit res7 =
CollectUtil.extractDoubleAndUnitFromStr("200Gi");
+ assertEquals(200, res7.getValue());
+ assertEquals("Gi", res7.getUnit());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]