Skip to content

Commit

Permalink
update code comment and doc, bugfix concurrent exception (#1378)
Browse files Browse the repository at this point in the history
Signed-off-by: tomsun28 <tomsun28@outlook.com>
  • Loading branch information
tomsun28 authored Dec 4, 2023
1 parent e553dd2 commit 908ebe2
Show file tree
Hide file tree
Showing 357 changed files with 1,935 additions and 2,666 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
import org.springframework.stereotype.Component;

/**
* alerter config
*
* alerter prop config
* @author tom
*
*/
@Component
@ConfigurationProperties(prefix = "alerter")
Expand All @@ -35,7 +33,6 @@
public class AlerterProperties {

/**
* 告警内容控制台链接
* Alarm content console link
*/
private String consoleUrl = "https://console.tancloud.cn";
Expand Down Expand Up @@ -71,62 +68,40 @@ public class AlerterProperties {
private String serverChanNotifyUrl = "https://sctapi.ftqq.com/%s.send";

/**
* 告警评估时间间隔起始基数 每下一次乘2 单位毫秒
* base of alert eval interval time, unit:ms. The next time is 2 times the previous time.
*/
@Deprecated
private long alertEvalIntervalBase = 1000 * 60 * 10L;

/**
* 最大告警评估时间间隔 单位毫秒
* max of alert eval interval time, unit:ms
*/
@Deprecated
private long maxAlertEvalInterval = 1000 * 60 * 60 * 24L;

/**
* 系统内置告警(available alert, reachable alert...)触发次数
* system alert(available alert, reachable alert...) trigger times
*/
@Deprecated
private int systemAlertTriggerTimes = 1;

/**
* Data entry configuration properties 数据入口配置属性
* Data entry configuration properties
*/
private EntranceProperties entrance;

/**
* Data entry configuration properties 数据入口配置属性
* The entry can obtain data from messaging middleware such as kafka rabbitmq rocketmq 入口可以是从kafka rabbitmq rocketmq等消息中间件获取数据
* Data entry configuration properties
*/
@Getter
@Setter
public static class EntranceProperties {

/**
* kafka configuration information kafka配置信息
* kafka configuration information
*/
private KafkaProperties kafka;

@Getter
@Setter
public static class KafkaProperties {
/**
* Whether the kafka data entry is started kafka数据入口是否启动
* Whether the kafka data entry is started
*/
private boolean enabled = true;

/**
* kafka's connection server url kafka的连接服务器url
* kafka's connection server url
*/
private String servers = "127.0.0.1:9092";
/**
* The name of the topic that receives the data 接收数据的topic名称
* The name of the topic that receives the data
*/
private String topic;
/**
* Consumer Group ID 消费者组ID
* Consumer Group ID
*/
private String groupId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
import java.util.concurrent.TimeUnit;

/**
* warehouse 工作线程池
* alarm module thread pool
* @author tom
*
*/
@Component
@Slf4j
Expand All @@ -43,11 +42,11 @@ public AlerterWorkerPool() {
}

private void initWorkExecutor() {
// 线程工厂
ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setUncaughtExceptionHandler((thread, throwable) -> {
log.error("workerExecutor has uncaughtException.");
log.error(throwable.getMessage(), throwable); })
log.error(throwable.getMessage(), throwable);
})
.setDaemon(true)
.setNameFormat("alerter-worker-%d")
.build();
Expand All @@ -61,9 +60,9 @@ private void initWorkExecutor() {
}

/**
* Run the alerter task 运行alerter任务
* @param runnable task 任务
* @throws RejectedExecutionException when The thread pool is full of 线程池满
* Run the alerter task
* @param runnable task
* @throws RejectedExecutionException when The thread pool is full of
*/
public void executeJob(Runnable runnable) throws RejectedExecutionException {
workerExecutor.execute(runnable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@

/**
* Calculate alarms based on the alarm definition rules and collected data
* 根据告警定义规则和采集数据匹配计算告警
*
* @author tom
*/
@Component
Expand Down Expand Up @@ -96,7 +94,6 @@ public CalculateAlarm(AlerterWorkerPool workerPool, CommonDataQueue dataQueue,
this.triggeredAlertMap = new ConcurrentHashMap<>(128);
this.notRecoveredAlertMap = new ConcurrentHashMap<>(128);
// Initialize stateAlertMap
// 初始化stateAlertMap
List<Monitor> monitors = monitorDao.findMonitorsByStatus(CommonConstants.UN_AVAILABLE_CODE);
if (monitors != null) {
for (Monitor monitor : monitors) {
Expand Down Expand Up @@ -136,13 +133,12 @@ private void calculate(CollectRep.MetricsData metricsData) {
long monitorId = metricsData.getId();
String app = metricsData.getApp();
String metrics = metricsData.getMetrics();
// If the indicator group whose scheduling priority is 0 has the status of collecting response data UN_REACHABLE/UN_CONNECTABLE, the highest severity alarm is generated to monitor the status change
// 先判断调度优先级为0的指标组采集响应数据状态 UN_REACHABLE/UN_CONNECTABLE 则需发最高级别告警进行任务状态变更
// If the metrics whose scheduling priority is 0 has the status of collecting response data UN_REACHABLE/UN_CONNECTABLE,
// the highest severity alarm is generated to monitor the status change
if (metricsData.getPriority() == 0) {
handlerAvailableMetrics(monitorId, app, metricsData);
}
// Query the alarm definitions associated with the indicator set of the monitoring type
// 查出此监控类型下的此指标集合下关联配置的告警定义信息
// Query the alarm definitions associated with the metrics of the monitoring type
// field - define[]
Map<String, List<AlertDefine>> defineMap = alertDefineService.getMonitorBindAlertDefines(monitorId, app, metrics);
if (defineMap.isEmpty()) {
Expand Down Expand Up @@ -293,7 +289,6 @@ private void afterThresholdRuleMatch(long currentTimeMilli, long monitorId, Stri
.firstAlarmTime(currentTimeMilli)
.lastAlarmTime(currentTimeMilli)
// Keyword matching and substitution in the template
// 模板中关键字匹配替换
.content(AlertTemplateUtil.render(define.getTemplate(), fieldValueMap))
.build();
int defineTimes = define.getTimes() == null ? 1 : define.getTimes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
/**
* @author <a href="mailto:gcwm99@gmail.com">gcdd1993</a>
* @version 2.1
* Created by Musk.Chen on 2023/1/14
*/
@ComponentScan(basePackages = "org.dromara.hertzbeat.alert")
public class AlerterAutoConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

/**
* Alarm Converge management API
* 告警收敛管理API
*
* @author tom
*/
@Tag(name = "Alert Converge API | 告警收敛管理API")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

/**
* Converge the batch API for alarms
* 收敛告警批量API
*
* @author tom
*/
@Tag(name = "Alert Converge Batch API | 告警收敛管理API")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@

/**
* Alarm definition management API
* 告警定义管理API
*
* @author tom
*/
@Tag(name = "Alert Define API | 告警定义管理API")
Expand All @@ -61,7 +59,6 @@ public class AlertDefineController {
@Operation(summary = "New Alarm Definition | 新增告警定义", description = "Added an alarm definition | 新增一个告警定义")
public ResponseEntity<Message<Void>> addNewAlertDefine(@Valid @RequestBody AlertDefine alertDefine) {
// Verify request data
// 校验请求数据
alertDefineService.validate(alertDefine, false);
alertDefineService.addAlertDefine(alertDefine);
return ResponseEntity.ok(Message.success("Add success"));
Expand All @@ -71,7 +68,6 @@ public ResponseEntity<Message<Void>> addNewAlertDefine(@Valid @RequestBody Alert
@Operation(summary = "Modifying an Alarm Definition | 修改告警定义", description = "Modify an existing alarm definition | 修改一个已存在告警定义")
public ResponseEntity<Message<Void>> modifyAlertDefine(@Valid @RequestBody AlertDefine alertDefine) {
// Verify request data
// 校验请求数据
alertDefineService.validate(alertDefine, true);
alertDefineService.modifyAlertDefine(alertDefine);
return ResponseEntity.ok(Message.success("Modify success"));
Expand All @@ -83,7 +79,6 @@ public ResponseEntity<Message<Void>> modifyAlertDefine(@Valid @RequestBody Alert
public ResponseEntity<Message<AlertDefine>> getAlertDefine(
@Parameter(description = "Alarm Definition ID | 告警定义ID", example = "6565463543") @PathVariable("id") long id) {
// Obtaining Monitoring Information
// 获取监控信息
AlertDefine alertDefine = alertDefineService.getAlertDefine(id);
if (alertDefine == null) {
return ResponseEntity.ok(Message.fail(MONITOR_NOT_EXIST_CODE, "AlertDefine not exist."));
Expand All @@ -98,7 +93,6 @@ public ResponseEntity<Message<AlertDefine>> getAlertDefine(
public ResponseEntity<Message<Void>> deleteAlertDefine(
@Parameter(description = "Alarm Definition ID | 告警定义ID", example = "6565463543") @PathVariable("id") long id) {
// If the alarm definition does not exist or is deleted successfully, the deletion succeeds
// 删除告警定义不存在或删除成功都返回成功
alertDefineService.deleteAlertDefine(id);
return ResponseEntity.ok(Message.success("Delete success"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@

/**
* Define the batch API for alarms
* 告警定义批量API
*
* @author tom
*/
@Tag(name = "Alert Define Batch API | 告警定义管理API")
Expand Down Expand Up @@ -111,7 +109,6 @@ public ResponseEntity<Message<Page<AlertDefine>>> getAlertDefines(
Predicate[] predicates = new Predicate[andList.size()];
return criteriaBuilder.and(andList.toArray(predicates));
};
// 分页是必须的
Sort sortExp = Sort.by(new Sort.Order(Sort.Direction.fromString(order), sort));
PageRequest pageRequest = PageRequest.of(pageIndex, pageSize, sortExp);
Page<AlertDefine> alertDefinePage = alertDefineService.getAlertDefines(specification, pageRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

/**
* Extern Alarm Manage API
* @author zqr10159
* 第三方告警上报接口
*/
@Tag(name = "Extern Alarm Manage API | 第三方告警管理API")
@RestController
Expand All @@ -33,8 +33,7 @@ public class AlertReportController {
private AlertService alertService;

@PostMapping("/{cloud}")
@Operation(summary = "Interface for reporting external alarm information of cloud service | 对外上报告警信息 接口",
description = "对外 新增一个云服务告警")
@Operation(summary = "Interface for reporting external alarm information of cloud service | 对外上报告警信息接口")
public ResponseEntity<Message<Void>> addNewAlertReportFromCloud(@PathVariable("cloud") String cloudServiceName,
@RequestBody String alertReport) {
// 根据枚举获取到对应的枚举对象
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

/**
* Alarm Silence management API
* 告警静默管理API
*
* @author tom
*/
@Tag(name = "Alert Silence API | 告警静默管理API")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@

/**
* Silence the batch API for alarms
* 静默告警批量API
* @author tom
*
*/
@Tag(name = "Alert Silence Batch API | 告警静默管理API")
@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

/**
* Alarm Management API 告警管理API
*
* Alarm Management API
* @author tom
* @author <a href="mailto:1252532896@qq.com">Hua.Cheng</a>
*
*/
@Tag(name = "Alarm Manage Batch API | 告警批量管理API")
@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
import java.util.Set;

/**
* AlertConverge 数据库操作
* AlertConverge Dao
* @author tom
*
*/
public interface AlertConvergeDao extends JpaRepository<AlertConverge, Long>, JpaSpecificationExecutor<AlertConverge> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,21 @@
import java.util.Set;

/**
* Alert Database Operations Alert数据库表操作
*
* Alert Database Operations
* @author tom
*
*/
public interface AlertDao extends JpaRepository<Alert, Long>, JpaSpecificationExecutor<Alert> {

/**
* Delete alerts based on ID list 根据ID列表删除告警
*
* @param alertIds Alert ID List 告警ID列表
* Delete alerts based on ID list
* @param alertIds Alert ID List
*/
void deleteAlertsByIdIn(Set<Long> alertIds);

/**
* Updates the alarm status based on the alarm ID-status value
* 根据告警ID-状态值 更新告警状态
*
* @param status 状态值
* @param ids 告警ID列表
* @param status status value
* @param ids alarm ids
*/
@Modifying
@Query("update Alert set status = :status where id in :ids")
Expand All @@ -57,8 +52,7 @@ public interface AlertDao extends JpaRepository<Alert, Long>, JpaSpecificationEx
/**
* Query the number of unhandled alarms of each alarm severity
* 查询各个告警级别的未处理告警数量
*
* @return List of alerts num 告警数量
* @return List of alerts num
*/
@Query("select new org.dromara.hertzbeat.alert.dto.AlertPriorityNum(mo.priority, count(mo.id)) from Alert mo where mo.status = 0 group by mo.priority")
List<AlertPriorityNum> findAlertPriorityNum();
Expand Down
Loading

0 comments on commit 908ebe2

Please sign in to comment.