Skip to content

Commit

Permalink
bugfix: fix overflow of integers (apache#2029)
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin979 authored May 24, 2024
1 parent a78f71d commit ddf6daa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public boolean filterConverge(Alert currentAlert) {
}
}
if (match) {
long evalInterval = alertConverge.getEvalInterval() * 1000;
long evalInterval = alertConverge.getEvalInterval() * 1000L;
long now = System.currentTimeMillis();
if (evalInterval <= 0) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public class PushServiceImpl implements PushService {

private final Map<Long, Long> monitorIdCache; // key: monitorId, value: time stamp of last query

private static final long cacheTimeout = 5000; // ms
private static final long cacheTimeout = 5000L; // ms

private final Map<Long, PushMetricsDto.Metrics> lastPushMetrics;

private static final long deleteMetricsPeriod = 1000 * 60 * 60 * 12;
private static final long deleteMetricsPeriod = 1000 * 60 * 60 * 12L;

private static final long deleteBeforeTime = deleteMetricsPeriod / 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ private long getExpireTimeFromToken(String history) {
try {
TemporalAmount temporalAmount = TimePeriodUtil.parseTokenTime(history);
ZonedDateTime dateTime = ZonedDateTime.now().minus(temporalAmount);
expireTime = dateTime.toEpochSecond() * 1000;
expireTime = dateTime.toEpochSecond() * 1000L;
} catch (Exception e) {
log.error("parse history time error: {}. use default: 6h", e.getMessage());
ZonedDateTime dateTime = ZonedDateTime.now().minus(Duration.ofHours(6));
expireTime = dateTime.toEpochSecond() * 1000;
expireTime = dateTime.toEpochSecond() * 1000L;
}
return expireTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ public void expiredDataCleaner() {
log.warn("[jpa-metrics-store]-start running expired data cleaner."
+ "Please use time series db instead of jpa for better performance");
String expireTimeStr = jpaProperties.expireTime();
long expireTime = 0;
long expireTime;
try {
if (NumberUtils.isParsable(expireTimeStr)) {
expireTime = NumberUtils.toLong(expireTimeStr);
expireTime = (ZonedDateTime.now().toEpochSecond() + expireTime) * 1000;
expireTime = (ZonedDateTime.now().toEpochSecond() + expireTime) * 1000L;
} else {
TemporalAmount temporalAmount = TimePeriodUtil.parseTokenTime(expireTimeStr);
ZonedDateTime dateTime = ZonedDateTime.now().minus(temporalAmount);
expireTime = dateTime.toEpochSecond() * 1000;
expireTime = dateTime.toEpochSecond() * 1000L;
}
} catch (Exception e) {
log.error("expiredDataCleaner time error: {}. use default expire time to clean: 1h", e.getMessage());
ZonedDateTime dateTime = ZonedDateTime.now().minus(Duration.ofHours(1));
expireTime = dateTime.toEpochSecond() * 1000;
expireTime = dateTime.toEpochSecond() * 1000L;
}
try {
int rows = historyDao.deleteHistoriesByTimeBefore(expireTime);
Expand Down Expand Up @@ -217,7 +217,7 @@ public Map<String, List<Value>> getHistoryMetricData(Long monitorId, String app,
try {
TemporalAmount temporalAmount = TimePeriodUtil.parseTokenTime(history);
ZonedDateTime dateTime = ZonedDateTime.now().minus(temporalAmount);
long timeBefore = dateTime.toEpochSecond() * 1000;
long timeBefore = dateTime.toEpochSecond() * 1000L;
Predicate timePredicate = criteriaBuilder.ge(root.get("time"), timeBefore);
andList.add(timePredicate);
} catch (Exception e) {
Expand Down

0 comments on commit ddf6daa

Please sign in to comment.