-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bugfix]auto config timezone for Jackson #2197
base: master
Are you sure you want to change the base?
Changes from all commits
0adf561
3d6f6c8
1eb5edd
30f8c03
ef5a9e5
36d0c25
1ce3d2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,14 @@ | |
|
||
package org.apache.hertzbeat.alert.reduce; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.hertzbeat.alert.dao.AlertSilenceDao; | ||
import org.apache.hertzbeat.common.cache.CacheFactory; | ||
import org.apache.hertzbeat.common.cache.CommonCacheService; | ||
|
@@ -36,6 +38,7 @@ | |
* silence alarm | ||
*/ | ||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class AlarmSilenceReduce { | ||
|
||
|
@@ -84,11 +87,11 @@ public boolean filterSilence(Alert alert) { | |
} | ||
} | ||
if (match) { | ||
LocalDateTime nowDate = LocalDateTime.now(); | ||
ZonedDateTime nowDate = ZonedDateTime.now(); | ||
if (alertSilence.getType() == 0) { | ||
// once time | ||
boolean startMatch = alertSilence.getPeriodStart() == null || nowDate.isAfter(alertSilence.getPeriodStart().toLocalDateTime()); | ||
boolean endMatch = alertSilence.getPeriodEnd() == null || nowDate.isBefore(alertSilence.getPeriodEnd().toLocalDateTime()); | ||
boolean startMatch = alertSilence.getPeriodStart() == null || nowDate.isAfter(alertSilence.getPeriodStart()); | ||
boolean endMatch = alertSilence.getPeriodEnd() == null || nowDate.isBefore(alertSilence.getPeriodEnd()); | ||
if (startMatch && endMatch) { | ||
int times = Optional.ofNullable(alertSilence.getTimes()).orElse(0); | ||
alertSilence.setTimes(times + 1); | ||
|
@@ -101,10 +104,13 @@ public boolean filterSilence(Alert alert) { | |
if (alertSilence.getDays() != null && !alertSilence.getDays().isEmpty()) { | ||
boolean dayMatch = alertSilence.getDays().stream().anyMatch(item -> item == currentDayOfWeek); | ||
if (dayMatch) { | ||
LocalTime nowTime = nowDate.toLocalTime(); | ||
boolean startMatch = alertSilence.getPeriodStart() == null || nowTime.isAfter(alertSilence.getPeriodStart().toLocalTime()); | ||
boolean endMatch = alertSilence.getPeriodEnd() == null || nowTime.isBefore(alertSilence.getPeriodEnd().toLocalTime()); | ||
if (startMatch && endMatch) { | ||
if (alertSilence.getPeriodStart() == null || alertSilence.getPeriodEnd() == null) { | ||
continue; | ||
} | ||
LocalTime silentStart = alertSilence.getPeriodStart().toLocalTime(); | ||
LocalTime silentEnd = alertSilence.getPeriodEnd().toLocalTime(); | ||
// 判断是否为静默时间段 | ||
if (isSilentPeriod(silentStart, silentEnd)) { | ||
int times = Optional.ofNullable(alertSilence.getTimes()).orElse(0); | ||
alertSilence.setTimes(times + 1); | ||
alertSilenceDao.save(alertSilence); | ||
|
@@ -117,4 +123,27 @@ public boolean filterSilence(Alert alert) { | |
} | ||
return true; | ||
} | ||
|
||
/** | ||
* 是否为静默时间段 | ||
* | ||
* @param silentStart 静默开始时间 | ||
* @param silentEnd 静默结束时间 | ||
* @return 是/否 | ||
*/ | ||
private boolean isSilentPeriod(LocalTime silentStart, LocalTime silentEnd) { | ||
if (null == silentStart || null == silentEnd) { | ||
return false; | ||
} | ||
LocalTime nowLocalTime = ZonedDateTime.now().toLocalTime(); | ||
log.info("nowLocalTime:{}, silentStart:{}, silentEnd:{}, SystemDefaultTimeZoneId:{}", nowLocalTime, silentStart, silentEnd, ZoneId.systemDefault()); | ||
// 如果静默结束时间小于静默开始时间,意味着静默期跨越了午夜 | ||
if (silentEnd.isBefore(silentStart)) { | ||
// 当前时间在午夜之前且大于等于静默开始时间,或者在午夜之后且小于静默结束时间 | ||
return nowLocalTime.isAfter(silentStart) || nowLocalTime.isBefore(silentEnd); | ||
} else { | ||
// 当前时间在静默开始和结束时间之间 | ||
return nowLocalTime.isAfter(silentStart) && nowLocalTime.isBefore(silentEnd); | ||
Comment on lines
+134
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hi the code comments need to be in English, and suggest use |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ spring: | |
static-path-pattern: /** | ||
jackson: | ||
default-property-inclusion: ALWAYS | ||
time-zone: ${TZ:Asia/Shanghai} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. due the #2122 support config time-zone in webui, can this be removed? @Calvin979 @cdphantom There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it can be removed. @cdphantom |
||
web: | ||
resources: | ||
static-locations: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be translated into Chinese.