This is an automated email from the ASF dual-hosted git repository.
cyyang 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 a138238994 [bugfix] Enhance expiration time parsing to support strict
day format (#3924)
a138238994 is described below
commit a138238994f2bf955ac4fc8a85c11c34b5151c9c
Author: Logic <[email protected]>
AuthorDate: Mon Dec 22 20:44:21 2025 +0800
[bugfix] Enhance expiration time parsing to support strict day format
(#3924)
---
.../tsdb/duckdb/DuckdbDatabaseDataStorage.java | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git
a/hertzbeat-warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/tsdb/duckdb/DuckdbDatabaseDataStorage.java
b/hertzbeat-warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/tsdb/duckdb/DuckdbDatabaseDataStorage.java
index ff414bfe11..d98c2ee7fb 100644
---
a/hertzbeat-warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/tsdb/duckdb/DuckdbDatabaseDataStorage.java
+++
b/hertzbeat-warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/tsdb/duckdb/DuckdbDatabaseDataStorage.java
@@ -49,6 +49,8 @@ import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* data storage by duckdb
@@ -64,6 +66,9 @@ public class DuckdbDatabaseDataStorage extends
AbstractHistoryDataStorage {
// Ideal number of data points for charting (avoids frontend lag)
private static final int TARGET_CHART_POINTS = 800;
+ // Regex to strictly match days format, e.g., "90d", "7D". Group 1
captures the digits.
+ private static final Pattern DAY_PATTERN = Pattern.compile("^(\\d+)[dD]$");
+
private final String expireTimeStr;
private final String dbPath;
private HikariDataSource dataSource;
@@ -136,11 +141,21 @@ public class DuckdbDatabaseDataStorage extends
AbstractHistoryDataStorage {
log.info("[duckdb] start data cleaner and checkpoint...");
long expireTime;
try {
- if (NumberUtils.isParsable(expireTimeStr)) {
- expireTime = NumberUtils.toLong(expireTimeStr);
+ // Ensure no whitespace issues
+ String cleanExpireStr = expireTimeStr == null ? "" :
expireTimeStr.trim();
+ Matcher dayMatcher = DAY_PATTERN.matcher(cleanExpireStr);
+
+ if (NumberUtils.isParsable(cleanExpireStr)) {
+ expireTime = NumberUtils.toLong(cleanExpireStr);
expireTime = (ZonedDateTime.now().toEpochSecond() -
expireTime) * 1000L;
+ } else if (dayMatcher.matches()) {
+ // Strictly matched "90d" or "90D" format
+ long days = Long.parseLong(dayMatcher.group(1));
+ ZonedDateTime dateTime =
ZonedDateTime.now().minus(Duration.ofDays(days));
+ expireTime = dateTime.toEpochSecond() * 1000L;
} else {
- TemporalAmount temporalAmount =
TimePeriodUtil.parseTokenTime(expireTimeStr);
+ // Fallback to existing utility for other units (h, m, s,
etc.)
+ TemporalAmount temporalAmount =
TimePeriodUtil.parseTokenTime(cleanExpireStr);
ZonedDateTime dateTime =
ZonedDateTime.now().minus(temporalAmount);
expireTime = dateTime.toEpochSecond() * 1000L;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]