This is an automated email from the ASF dual-hosted git repository. gongchao pushed a commit to branch remove-cn-1 in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
commit b3aa901bc66c29d1e851439d0c5c2077259b4bf5 Author: tomsun28 <[email protected]> AuthorDate: Wed Apr 17 21:17:57 2024 +0800 [doc] translate alerter chinese to english Signed-off-by: tomsun28 <[email protected]> --- .../hertzbeat/alert/calculate/CalculateAlarm.java | 12 +++---- .../alert/config/AlerterAutoConfiguration.java | 1 - .../alert/controller/AlertConvergeController.java | 12 +++---- .../alert/controller/AlertConvergesController.java | 24 ++++++------- .../alert/controller/AlertDefineController.java | 30 ++++++++--------- .../alert/controller/AlertDefinesController.java | 32 +++++++++--------- .../alert/controller/AlertReportController.java | 28 +++++----------- .../alert/controller/AlertSilenceController.java | 12 +++---- .../alert/controller/AlertSilencesController.java | 24 ++++++------- .../alert/controller/AlertsController.java | 36 ++++++++++---------- .../org/apache/hertzbeat/alert/dao/AlertDao.java | 1 - .../apache/hertzbeat/alert/dao/AlertDefineDao.java | 2 -- .../apache/hertzbeat/alert/dto/AlertSummary.java | 9 ++--- .../alert/dto/GeneralCloudAlertReport.java | 7 +--- .../hertzbeat/alert/dto/TenCloudAlertReport.java | 4 +-- .../alert/service/AlertDefineImExportService.java | 14 +++----- .../alert/service/AlertDefineService.java | 5 --- .../hertzbeat/alert/service/AlertService.java | 2 -- .../AlertDefineAbstractImExportServiceImpl.java | 9 +++-- .../impl/AlertDefineExcelImExportServiceImpl.java | 28 ++++++++-------- .../alert/service/impl/AlertDefineServiceImpl.java | 2 -- .../service/impl/AlertSilenceServiceImpl.java | 2 +- .../hertzbeat/alert/util/AlertTemplateUtil.java | 2 -- .../controller/AlertDefineControllerTest.java | 8 ++--- .../controller/AlertDefinesControllerTest.java | 39 ++++------------------ .../controller/AlertReportControllerTest.java | 11 +++--- .../alert/controller/AlertsControllerTest.java | 6 ---- .../alert/util/AlertTemplateUtilTest.java | 6 +--- 28 files changed, 141 insertions(+), 227 deletions(-) diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/calculate/CalculateAlarm.java b/alerter/src/main/java/org/apache/hertzbeat/alert/calculate/CalculateAlarm.java index dfb2d1239..559670baf 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/calculate/CalculateAlarm.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/calculate/CalculateAlarm.java @@ -64,9 +64,8 @@ public class CalculateAlarm { /** * The alarm in the process is triggered - * 触发中告警信息 - * key - monitorId+alertDefineId+tags 为普通阈值告警 | The alarm is a common threshold alarm - * key - monitorId 为任务状态可用性可达性告警 | Indicates the monitoring status availability reachability alarm + * key - monitorId+alertDefineId+tags | The alarm is a common threshold alarm + * key - monitorId | Indicates the monitoring status availability reachability alarm */ private final Map<String, Alert> triggeredAlertMap; /** @@ -163,9 +162,8 @@ public class CalculateAlarm { try { if (match) { // If the threshold rule matches, the number of times the threshold has been triggered is determined and an alarm is triggered - // 阈值规则匹配,判断已触发阈值次数,触发告警 afterThresholdRuleMatch(currentTimeMilli, monitorId, app, metrics, "", fieldValueMap, define); - // 若此阈值已被触发,则其它数据行的触发忽略 + // if the threshold is triggered, ignore other data rows continue; } else { String alarmKey = String.valueOf(monitorId) + define.getId(); @@ -221,9 +219,8 @@ public class CalculateAlarm { try { if (match) { // If the threshold rule matches, the number of times the threshold has been triggered is determined and an alarm is triggered - // 阈值规则匹配,判断已触发阈值次数,触发告警 afterThresholdRuleMatch(currentTimeMilli, monitorId, app, metrics, tagBuilder.toString(), fieldValueMap, define); - // 若此阈值已被触发,则其它数据行的触发忽略 + // if the threshold is triggered, ignore other data rows break; } else { String alarmKey = String.valueOf(monitorId) + define.getId() + tagBuilder; @@ -399,7 +396,6 @@ public class CalculateAlarm { } else { // Check whether an availability or unreachable alarm is generated before the association monitoring // and send a clear alarm to clear the monitoring status - // 判断关联监控之前是否有可用性或者不可达告警,发送恢复告警进行任务状态恢复 triggeredAlertMap.remove(String.valueOf(monitorId)); String notResolvedAlertKey = monitorId + CommonConstants.AVAILABILITY; Alert notResolvedAlert = notRecoveredAlertMap.remove(notResolvedAlertKey); diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/config/AlerterAutoConfiguration.java b/alerter/src/main/java/org/apache/hertzbeat/alert/config/AlerterAutoConfiguration.java index 516bc7849..b0afa2c5b 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/config/AlerterAutoConfiguration.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/config/AlerterAutoConfiguration.java @@ -21,7 +21,6 @@ import org.springframework.context.annotation.ComponentScan; /** * Alert auto configuration. - * @version 2.1 */ @ComponentScan(basePackages = "org.apache.hertzbeat.alert") public class AlerterAutoConfiguration { diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertConvergeController.java b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertConvergeController.java index cd355f0f3..106ac72e6 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertConvergeController.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertConvergeController.java @@ -35,7 +35,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; /** * Alarm Converge management API */ -@Tag(name = "Alert Converge API | 告警收敛管理API") +@Tag(name = "Alert Converge API") @RestController @RequestMapping(path = "/api/alert/converge", produces = {APPLICATION_JSON_VALUE}) public class AlertConvergeController { @@ -44,7 +44,7 @@ public class AlertConvergeController { private AlertConvergeService alertConvergeService; @PostMapping - @Operation(summary = "New Alarm Converge | 新增告警收敛", description = "Added an alarm Converge | 新增一个告警收敛") + @Operation(summary = "New Alarm Converge", description = "Added an alarm Converge") public ResponseEntity<Message<Void>> addNewAlertConverge(@Valid @RequestBody AlertConverge alertConverge) { alertConvergeService.validate(alertConverge, false); alertConvergeService.addAlertConverge(alertConverge); @@ -52,7 +52,7 @@ public class AlertConvergeController { } @PutMapping - @Operation(summary = "Modifying an Alarm Converge | 修改告警收敛", description = "Modify an existing alarm Converge | 修改一个已存在告警收敛") + @Operation(summary = "Modifying an Alarm Converge", description = "Modify an existing alarm Converge") public ResponseEntity<Message<Void>> modifyAlertConverge(@Valid @RequestBody AlertConverge alertConverge) { alertConvergeService.validate(alertConverge, true); alertConvergeService.modifyAlertConverge(alertConverge); @@ -60,10 +60,10 @@ public class AlertConvergeController { } @GetMapping(path = "/{id}") - @Operation(summary = "Querying Alarm Converge | 查询告警收敛", - description = "You can obtain alarm Converge information based on the alarm Converge ID | 根据告警收敛ID获取告警收敛信息") + @Operation(summary = "Querying Alarm Converge", + description = "You can obtain alarm Converge information based on the alarm Converge ID") public ResponseEntity<Message<AlertConverge>> getAlertConverge( - @Parameter(description = "Alarm Converge ID | 告警收敛ID", example = "6565463543") @PathVariable("id") long id) { + @Parameter(description = "Alarm Converge ID", example = "6565463543") @PathVariable("id") long id) { AlertConverge alertConverge = alertConvergeService.getAlertConverge(id); if (alertConverge == null) { return ResponseEntity.ok(Message.fail(MONITOR_NOT_EXIST_CODE, "AlertConverge not exist.")); diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertConvergesController.java b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertConvergesController.java index e5f6c64f1..4b38a3818 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertConvergesController.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertConvergesController.java @@ -43,7 +43,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; /** * Converge the batch API for alarms */ -@Tag(name = "Alert Converge Batch API | 告警收敛管理API") +@Tag(name = "Alert Converge Batch API") @RestController @RequestMapping(path = "/api/alert/converges", produces = {APPLICATION_JSON_VALUE}) public class AlertConvergesController { @@ -52,15 +52,15 @@ public class AlertConvergesController { private AlertConvergeService alertConvergeService; @GetMapping - @Operation(summary = "Query the alarm converge list | 查询告警收敛列表", - description = "You can obtain the list of alarm converge by querying filter items | 根据查询过滤项获取告警收敛信息列表") + @Operation(summary = "Query the alarm converge list", + description = "You can obtain the list of alarm converge by querying filter items") public ResponseEntity<Message<Page<AlertConverge>>> getAlertConverges( - @Parameter(description = "Alarm Converge ID | 告警收敛ID", example = "6565463543") @RequestParam(required = false) List<Long> ids, - @Parameter(description = "Search Name | 模糊查询-名称", example = "x") @RequestParam(required = false) String search, - @Parameter(description = "Sort field, default id | 排序字段,默认id", example = "id") @RequestParam(defaultValue = "id") String sort, - @Parameter(description = "Sort mode: asc: ascending, desc: descending | 排序方式,asc:升序,desc:降序", example = "desc") @RequestParam(defaultValue = "desc") String order, - @Parameter(description = "List current page | 列表当前分页", example = "0") @RequestParam(defaultValue = "0") int pageIndex, - @Parameter(description = "Number of list pages | 列表分页数量", example = "8") @RequestParam(defaultValue = "8") int pageSize) { + @Parameter(description = "Alarm Converge ID", example = "6565463543") @RequestParam(required = false) List<Long> ids, + @Parameter(description = "Search Name", example = "x") @RequestParam(required = false) String search, + @Parameter(description = "Sort field, default id", example = "id") @RequestParam(defaultValue = "id") String sort, + @Parameter(description = "Sort mode: asc: ascending, desc: descending", example = "desc") @RequestParam(defaultValue = "desc") String order, + @Parameter(description = "List current page", example = "0") @RequestParam(defaultValue = "0") int pageIndex, + @Parameter(description = "Number of list pages", example = "8") @RequestParam(defaultValue = "8") int pageSize) { Specification<AlertConverge> specification = (root, query, criteriaBuilder) -> { List<Predicate> andList = new ArrayList<>(); @@ -90,10 +90,10 @@ public class AlertConvergesController { } @DeleteMapping - @Operation(summary = "Delete alarm converge in batches | 批量删除告警收敛", - description = "Delete alarm converge in batches based on the alarm converge ID list | 根据告警收敛ID列表批量删除告警收敛") + @Operation(summary = "Delete alarm converge in batches", + description = "Delete alarm converge in batches based on the alarm converge ID list") public ResponseEntity<Message<Void>> deleteAlertDefines( - @Parameter(description = "Alarm Converge IDs | 告警收敛IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids + @Parameter(description = "Alarm Converge IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids ) { if (ids != null && !ids.isEmpty()) { alertConvergeService.deleteAlertConverges(new HashSet<>(ids)); diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertDefineController.java b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertDefineController.java index 615b4950a..66e26b2fd 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertDefineController.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertDefineController.java @@ -46,7 +46,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; /** * Alarm definition management API */ -@Tag(name = "Alert Define API | 告警定义管理API") +@Tag(name = "Alert Define API") @RestController @RequestMapping(path = "/api/alert/define", produces = {APPLICATION_JSON_VALUE}) public class AlertDefineController { @@ -55,7 +55,7 @@ public class AlertDefineController { private AlertDefineService alertDefineService; @PostMapping - @Operation(summary = "New Alarm Definition | 新增告警定义", description = "Added an alarm definition | 新增一个告警定义") + @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); @@ -64,7 +64,7 @@ public class AlertDefineController { } @PutMapping - @Operation(summary = "Modifying an Alarm Definition | 修改告警定义", description = "Modify an existing alarm definition | 修改一个已存在告警定义") + @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); @@ -73,10 +73,10 @@ public class AlertDefineController { } @GetMapping(path = "/{id}") - @Operation(summary = "Querying Alarm Definitions | 查询告警定义", - description = "You can obtain alarm definition information based on the alarm definition ID | 根据告警定义ID获取告警定义信息") + @Operation(summary = "Querying Alarm Definitions", + description = "You can obtain alarm definition information based on the alarm definition ID") public ResponseEntity<Message<AlertDefine>> getAlertDefine( - @Parameter(description = "Alarm Definition ID | 告警定义ID", example = "6565463543") @PathVariable("id") long id) { + @Parameter(description = "Alarm Definition ID", example = "6565463543") @PathVariable("id") long id) { // Obtaining Monitoring Information AlertDefine alertDefine = alertDefineService.getAlertDefine(id); if (alertDefine == null) { @@ -87,30 +87,30 @@ public class AlertDefineController { } @DeleteMapping(path = "/{id}") - @Operation(summary = "Deleting an Alarm Definition | 删除告警定义", - description = "If the alarm definition does not exist, the alarm is deleted successfully | 根据告警定义ID删除告警定义,告警定义不存在也是删除成功") + @Operation(summary = "Deleting an Alarm Definition", + description = "If the alarm definition does not exist, the alarm is deleted successfully") public ResponseEntity<Message<Void>> deleteAlertDefine( - @Parameter(description = "Alarm Definition ID | 告警定义ID", example = "6565463543") @PathVariable("id") long id) { + @Parameter(description = "Alarm Definition 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")); } @PostMapping(path = "/{alertDefineId}/monitors") - @Operation(summary = "Application alarm definition is associated with monitoring | 应用告警定义与监控关联", - description = "Applies the association between specified alarm definitions and monitoring | 应用指定告警定义与监控关联关系") + @Operation(summary = "Application alarm definition is associated with monitoring", + description = "Applies the association between specified alarm definitions and monitoring") public ResponseEntity<Message<Void>> applyAlertDefineMonitorsBind( - @Parameter(description = "Alarm Definition ID | 告警定义ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId, + @Parameter(description = "Alarm Definition ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId, @RequestBody List<AlertDefineMonitorBind> alertDefineMonitorBinds) { alertDefineService.applyBindAlertDefineMonitors(alertDefineId, alertDefineMonitorBinds); return ResponseEntity.ok(Message.success("Apply success")); } @GetMapping(path = "/{alertDefineId}/monitors") - @Operation(summary = "Application alarm definition is associated with monitoring | 应用告警定义与监控关联", - description = "Applies the association between specified alarm definitions and monitoring | 应用指定告警定义与监控关联关系") + @Operation(summary = "Application alarm definition is associated with monitoring", + description = "Applies the association between specified alarm definitions and monitoring") public ResponseEntity<Message<List<AlertDefineMonitorBind>>> getAlertDefineMonitorsBind( - @Parameter(description = "Alarm Definition ID | 告警定义ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId) { + @Parameter(description = "Alarm Definition ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId) { List<AlertDefineMonitorBind> defineBinds = alertDefineService.getBindAlertDefineMonitors(alertDefineId); defineBinds = defineBinds.stream().filter(item -> item.getMonitor() != null).collect(Collectors.toList()); return ResponseEntity.ok(Message.success(defineBinds)); diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertDefinesController.java b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertDefinesController.java index f62ea286a..259309f02 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertDefinesController.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertDefinesController.java @@ -45,7 +45,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; /** * Define the batch API for alarms */ -@Tag(name = "Alert Define Batch API | 告警定义管理API") +@Tag(name = "Alert Define Batch API") @RestController @RequestMapping(path = "/api/alert/defines", produces = {APPLICATION_JSON_VALUE}) public class AlertDefinesController { @@ -54,16 +54,16 @@ public class AlertDefinesController { private AlertDefineService alertDefineService; @GetMapping - @Operation(summary = "Example Query the alarm definition list | 查询告警定义列表", - description = "You can obtain the list of alarm definitions by querying filter items | 根据查询过滤项获取告警定义信息列表") + @Operation(summary = "Example Query the alarm definition list", + description = "You can obtain the list of alarm definitions by querying filter items") public ResponseEntity<Message<Page<AlertDefine>>> getAlertDefines( - @Parameter(description = "Alarm Definition ID | 告警定义ID", example = "6565463543") @RequestParam(required = false) List<Long> ids, - @Parameter(description = "Search-Target Expr Template | 模糊查询-指标对象 表达式 通知模版", example = "x") @RequestParam(required = false) String search, - @Parameter(description = "Alarm Definition Severity | 告警定义级别", example = "6565463543") @RequestParam(required = false) Byte priority, - @Parameter(description = "Sort field, default id | 排序字段,默认id", example = "id") @RequestParam(defaultValue = "id") String sort, - @Parameter(description = "Sort mode: asc: ascending, desc: descending | 排序方式,asc:升序,desc:降序", example = "desc") @RequestParam(defaultValue = "desc") String order, - @Parameter(description = "List current page | 列表当前分页", example = "0") @RequestParam(defaultValue = "0") int pageIndex, - @Parameter(description = "Number of list pages | 列表分页数量", example = "8") @RequestParam(defaultValue = "8") int pageSize) { + @Parameter(description = "Alarm Definition ID", example = "6565463543") @RequestParam(required = false) List<Long> ids, + @Parameter(description = "Search-Target Expr Template", example = "x") @RequestParam(required = false) String search, + @Parameter(description = "Alarm Definition Severity", example = "6565463543") @RequestParam(required = false) Byte priority, + @Parameter(description = "Sort field, default id", example = "id") @RequestParam(defaultValue = "id") String sort, + @Parameter(description = "Sort mode: asc: ascending, desc: descending", example = "desc") @RequestParam(defaultValue = "desc") String order, + @Parameter(description = "List current page", example = "0") @RequestParam(defaultValue = "0") int pageIndex, + @Parameter(description = "Number of list pages", example = "8") @RequestParam(defaultValue = "8") int pageSize) { Specification<AlertDefine> specification = (root, query, criteriaBuilder) -> { List<Predicate> andList = new ArrayList<>(); @@ -113,10 +113,10 @@ public class AlertDefinesController { } @DeleteMapping - @Operation(summary = "Delete alarm definitions in batches | 批量删除告警定义", - description = "Delete alarm definitions in batches based on the alarm definition ID list | 根据告警定义ID列表批量删除告警定义") + @Operation(summary = "Delete alarm definitions in batches", + description = "Delete alarm definitions in batches based on the alarm definition ID list") public ResponseEntity<Message<Void>> deleteAlertDefines( - @Parameter(description = "Alarm Definition IDs | 告警定义IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids + @Parameter(description = "Alarm Definition IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids ) { if (ids != null && !ids.isEmpty()) { alertDefineService.deleteAlertDefines(new HashSet<>(ids)); @@ -125,16 +125,16 @@ public class AlertDefinesController { } @GetMapping("/export") - @Operation(summary = "export alertDefine config", description = "导出告警阀值配置") + @Operation(summary = "export alertDefine config", description = "export alarm definition configuration") public void export( - @Parameter(description = "AlertDefine ID List | 告警阀值ID列表", example = "656937901") @RequestParam List<Long> ids, + @Parameter(description = "AlertDefine ID List", example = "656937901") @RequestParam List<Long> ids, @Parameter(description = "Export Type:JSON,EXCEL,YAML") @RequestParam(defaultValue = "JSON") String type, HttpServletResponse res) throws Exception { alertDefineService.export(ids, type, res); } @PostMapping("/import") - @Operation(summary = "import alertDefine config", description = "导入告警阀值配置") + @Operation(summary = "import alertDefine config", description = "import alarm definition configuration") public ResponseEntity<Message<Void>> importDefines(MultipartFile file) throws Exception { alertDefineService.importConfig(file); return ResponseEntity.ok(Message.success("Import success")); diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertReportController.java b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertReportController.java index 106940a9e..af1e8486f 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertReportController.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertReportController.java @@ -39,7 +39,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; /** * Extern Alarm Manage API */ -@Tag(name = "Extern Alarm Manage API | 第三方告警管理API") +@Tag(name = "Extern Alarm Manage API") @RestController @RequestMapping(path = "/api/alerts/report", produces = {APPLICATION_JSON_VALUE}) @Slf4j @@ -49,21 +49,17 @@ public class AlertReportController { private AlertService alertService; @PostMapping("/{cloud}") - @Operation(summary = "Interface for reporting external alarm information of cloud service | 对外上报告警信息接口") + @Operation(summary = "Interface for reporting external alarm information of cloud service") public ResponseEntity<Message<Void>> addNewAlertReportFromCloud(@PathVariable("cloud") String cloudServiceName, @RequestBody String alertReport) { - // 根据枚举获取到对应的枚举对象 CloudServiceAlarmInformationEnum cloudService = CloudServiceAlarmInformationEnum .getEnumFromCloudServiceName(cloudServiceName); AlertReport alert = null; - // 校验是否存在对应的对象 if (cloudService != null) { try { - // 实例化对应的Class CloudAlertReportAbstract cloudAlertReport = JsonUtil .fromJson(alertReport, cloudService.getCloudServiceAlarmInformationEntity()); - // 模板填充 assert cloudAlertReport != null; alert = AlertReport.builder() .content(cloudAlertReport.getContent()) @@ -76,36 +72,28 @@ public class AlertReportController { .annotations(cloudAlertReport.getAnnotations()) .build(); } catch (Exception e) { - log.error("[AlertReportController]:解析云服务告警内容失败!云服务商:" + - cloudService.name() + ";传入JSON字符串:" + alertReport); + log.error("[alert report] parse cloud service alarm content failed! cloud service: {} conrent: {}", + cloudService.name(), alertReport); } } else { - // 用户异常使用第三方接入API告警 alert = AlertReport.builder() - .content("第三方告警API接入异常:不存在该API,详情请看文档") + .content("error do not has cloud service api") .alertName("/api/alerts/report/" + cloudServiceName) .alertTime(new Date().getTime()) .priority(1) .reportType(1) .build(); } - // 异常判断是否为空 Optional.ofNullable(alert).ifPresent(alertReportPresent -> alertService.addNewAlertReport(alertReportPresent)); return ResponseEntity.ok(Message.success("Add report success")); } @PostMapping - @Operation(summary = "Interface for reporting external and general alarm information | 对外上报告警信息 接口", - description = "对外 新增一个云服务通用告警") + @Operation(summary = "Interface for reporting external and general alarm information", + description = "The interface is used to report external and general alarm information") public ResponseEntity<Message<Void>> addNewAlertReport(@RequestBody GeneralCloudAlertReport alertReport) { - try { - alertReport.refreshAlertTime(); - } catch (Exception e) { - log.error("[AlertReportController]:" + e.getMessage() + - ",请求实体:" + JsonUtil.toJson(alertReport)); - throw e; - } + alertReport.refreshAlertTime(); alertService.addNewAlertReport(alertReport); return ResponseEntity.ok(Message.success("Add report success")); } diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertSilenceController.java b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertSilenceController.java index 20c818711..bd0b9d1b5 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertSilenceController.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertSilenceController.java @@ -36,7 +36,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; /** * Alarm Silence management API */ -@Tag(name = "Alert Silence API | 告警静默管理API") +@Tag(name = "Alert Silence API") @RestController @RequestMapping(path = "/api/alert/silence", produces = {APPLICATION_JSON_VALUE}) public class AlertSilenceController { @@ -45,7 +45,7 @@ public class AlertSilenceController { private AlertSilenceService alertSilenceService; @PostMapping - @Operation(summary = "New Alarm Silence | 新增告警静默", description = "Added an alarm Silence | 新增一个告警静默") + @Operation(summary = "New Alarm Silence", description = "Added an alarm Silence") public ResponseEntity<Message<Void>> addNewAlertSilence(@Valid @RequestBody AlertSilence alertSilence) { alertSilenceService.validate(alertSilence, false); alertSilenceService.addAlertSilence(alertSilence); @@ -53,7 +53,7 @@ public class AlertSilenceController { } @PutMapping - @Operation(summary = "Modifying an Alarm Silence | 修改告警静默", description = "Modify an existing alarm Silence | 修改一个已存在告警静默") + @Operation(summary = "Modifying an Alarm Silence", description = "Modify an existing alarm Silence") public ResponseEntity<Message<Void>> modifyAlertSilence(@Valid @RequestBody AlertSilence alertSilence) { alertSilenceService.validate(alertSilence, true); alertSilenceService.modifyAlertSilence(alertSilence); @@ -61,10 +61,10 @@ public class AlertSilenceController { } @GetMapping(path = "/{id}") - @Operation(summary = "Querying Alarm Silence | 查询告警静默", - description = "You can obtain alarm Silence information based on the alarm Silence ID | 根据告警静默ID获取告警静默信息") + @Operation(summary = "Querying Alarm Silence", + description = "You can obtain alarm Silence information based on the alarm Silence ID") public ResponseEntity<Message<AlertSilence>> getAlertSilence( - @Parameter(description = "Alarm Silence ID | 告警静默ID", example = "6565463543") @PathVariable("id") long id) { + @Parameter(description = "Alarm Silence ID", example = "6565463543") @PathVariable("id") long id) { AlertSilence alertSilence = alertSilenceService.getAlertSilence(id); if (alertSilence == null) { return ResponseEntity.ok(Message.fail(MONITOR_NOT_EXIST_CODE, "AlertSilence not exist.")); diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertSilencesController.java b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertSilencesController.java index 65b5c559c..c112cc55e 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertSilencesController.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertSilencesController.java @@ -43,7 +43,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; /** * Silence the batch API for alarms */ -@Tag(name = "Alert Silence Batch API | 告警静默管理API") +@Tag(name = "Alert Silence Batch API") @RestController @RequestMapping(path = "/api/alert/silences", produces = {APPLICATION_JSON_VALUE}) public class AlertSilencesController { @@ -52,15 +52,15 @@ public class AlertSilencesController { private AlertSilenceService alertSilenceService; @GetMapping - @Operation(summary = "Query the alarm silence list | 查询告警静默列表", - description = "You can obtain the list of alarm silence by querying filter items | 根据查询过滤项获取告警静默信息列表") + @Operation(summary = "Query the alarm silence list", + description = "You can obtain the list of alarm silence by querying filter items") public ResponseEntity<Message<Page<AlertSilence>>> getAlertSilences( - @Parameter(description = "Alarm Silence ID | 告警静默ID", example = "6565463543") @RequestParam(required = false) List<Long> ids, - @Parameter(description = "Search Name | 模糊查询-名称", example = "x") @RequestParam(required = false) String search, - @Parameter(description = "Sort field, default id | 排序字段,默认id", example = "id") @RequestParam(defaultValue = "id") String sort, - @Parameter(description = "Sort mode: asc: ascending, desc: descending | 排序方式,asc:升序,desc:降序", example = "desc") @RequestParam(defaultValue = "desc") String order, - @Parameter(description = "List current page | 列表当前分页", example = "0") @RequestParam(defaultValue = "0") int pageIndex, - @Parameter(description = "Number of list pages | 列表分页数量", example = "8") @RequestParam(defaultValue = "8") int pageSize) { + @Parameter(description = "Alarm Silence ID", example = "6565463543") @RequestParam(required = false) List<Long> ids, + @Parameter(description = "Search Name", example = "x") @RequestParam(required = false) String search, + @Parameter(description = "Sort field, default id", example = "id") @RequestParam(defaultValue = "id") String sort, + @Parameter(description = "Sort mode: asc: ascending, desc: descending", example = "desc") @RequestParam(defaultValue = "desc") String order, + @Parameter(description = "List current page", example = "0") @RequestParam(defaultValue = "0") int pageIndex, + @Parameter(description = "Number of list pages", example = "8") @RequestParam(defaultValue = "8") int pageSize) { Specification<AlertSilence> specification = (root, query, criteriaBuilder) -> { List<Predicate> andList = new ArrayList<>(); @@ -91,10 +91,10 @@ public class AlertSilencesController { } @DeleteMapping - @Operation(summary = "Delete alarm silence in batches | 批量删除告警静默", - description = "Delete alarm silence in batches based on the alarm silence ID list | 根据告警静默ID列表批量删除告警静默") + @Operation(summary = "Delete alarm silence in batches", + description = "Delete alarm silence in batches based on the alarm silence ID list") public ResponseEntity<Message<Void>> deleteAlertDefines( - @Parameter(description = "Alarm Silence IDs | 告警静默IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids + @Parameter(description = "Alarm Silence IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids ) { if (ids != null && !ids.isEmpty()) { alertSilenceService.deleteAlertSilences(new HashSet<>(ids)); diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertsController.java b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertsController.java index 80847ee8a..7d488e53f 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertsController.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/controller/AlertsController.java @@ -43,7 +43,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; /** * Alarm Management API */ -@Tag(name = "Alarm Manage Batch API | 告警批量管理API") +@Tag(name = "Alarm Manage Batch API") @RestController @RequestMapping(path = "/api/alerts", produces = {APPLICATION_JSON_VALUE}) public class AlertsController { @@ -52,17 +52,17 @@ public class AlertsController { private AlertService alertService; @GetMapping - @Operation(summary = "Get a list of alarm information based on query filter items", description = "根据查询过滤项获取告警信息列表") + @Operation(summary = "Get a list of alarm information based on query filter items", description = "according to the query filter items to obtain a list of alarm information") public ResponseEntity<Message<Page<Alert>>> getAlerts( - @Parameter(description = "Alarm ID List | 告警IDS", example = "6565466456") @RequestParam(required = false) List<Long> ids, - @Parameter(description = "Alarm monitor object ID | 告警监控对象ID", example = "6565463543") @RequestParam(required = false) Long monitorId, - @Parameter(description = "Alarm level | 告警级别", example = "6565463543") @RequestParam(required = false) Byte priority, - @Parameter(description = "Alarm Status | 告警状态", example = "6565463543") @RequestParam(required = false) Byte status, - @Parameter(description = "Alarm content fuzzy query | 告警内容模糊查询", example = "linux") @RequestParam(required = false) String content, - @Parameter(description = "Sort field, default id | 排序字段,默认id", example = "name") @RequestParam(defaultValue = "id") String sort, - @Parameter(description = "Sort Type | 排序方式,asc:升序,desc:降序", example = "desc") @RequestParam(defaultValue = "desc") String order, - @Parameter(description = "List current page | 列表当前分页", example = "0") @RequestParam(defaultValue = "0") int pageIndex, - @Parameter(description = "Number of list pagination | 列表分页数量", example = "8") @RequestParam(defaultValue = "8") int pageSize) { + @Parameter(description = "Alarm ID List", example = "6565466456") @RequestParam(required = false) List<Long> ids, + @Parameter(description = "Alarm monitor object ID", example = "6565463543") @RequestParam(required = false) Long monitorId, + @Parameter(description = "Alarm level", example = "6565463543") @RequestParam(required = false) Byte priority, + @Parameter(description = "Alarm Status", example = "6565463543") @RequestParam(required = false) Byte status, + @Parameter(description = "Alarm content fuzzy query", example = "linux") @RequestParam(required = false) String content, + @Parameter(description = "Sort field, default id", example = "name") @RequestParam(defaultValue = "id") String sort, + @Parameter(description = "Sort Type", example = "desc") @RequestParam(defaultValue = "desc") String order, + @Parameter(description = "List current page", example = "0") @RequestParam(defaultValue = "0") int pageIndex, + @Parameter(description = "Number of list pagination", example = "8") @RequestParam(defaultValue = "8") int pageSize) { Specification<Alert> specification = (root, query, criteriaBuilder) -> { List<Predicate> andList = new ArrayList<>(); @@ -101,9 +101,9 @@ public class AlertsController { } @DeleteMapping - @Operation(summary = "Delete alarms in batches", description = "根据告警ID列表批量删除告警") + @Operation(summary = "Delete alarms in batches", description = "according to the alarm ID list to delete the alarm information in batches") public ResponseEntity<Message<Void>> deleteAlerts( - @Parameter(description = "Alarm List ID | 告警IDs", example = "6565463543") @RequestParam(required = false) List<Long> ids) { + @Parameter(description = "Alarm List ID", example = "6565463543") @RequestParam(required = false) List<Long> ids) { if (ids != null && !ids.isEmpty()) { alertService.deleteAlerts(new HashSet<>(ids)); } @@ -112,7 +112,7 @@ public class AlertsController { } @DeleteMapping("/clear") - @Operation(summary = "Delete alarms in batches", description = "清空所有告警信息") + @Operation(summary = "Delete alarms in batches", description = "delete all alarm information") public ResponseEntity<Message<Void>> clearAllAlerts() { alertService.clearAlerts(); Message<Void> message = Message.success(); @@ -120,10 +120,10 @@ public class AlertsController { } @PutMapping(path = "/status/{status}") - @Operation(summary = "Batch modify alarm status, set read and unread", description = "批量修改告警状态,设置已读未读") + @Operation(summary = "Batch modify alarm status, set read and unread", description = "Batch modify alarm status, set read and unread") public ResponseEntity<Message<Void>> applyAlertDefinesStatus( - @Parameter(description = "Alarm status value | 告警状态值", example = "0") @PathVariable Byte status, - @Parameter(description = "Alarm List IDS | 告警IDS", example = "6565463543") @RequestParam(required = false) List<Long> ids) { + @Parameter(description = "Alarm status value", example = "0") @PathVariable Byte status, + @Parameter(description = "Alarm List IDS", example = "6565463543") @RequestParam(required = false) List<Long> ids) { if (ids != null && status != null && !ids.isEmpty()) { alertService.editAlertStatus(status, ids); } @@ -132,7 +132,7 @@ public class AlertsController { } @GetMapping(path = "/summary") - @Operation(summary = "Get alarm statistics", description = "获取告警统计信息") + @Operation(summary = "Get alarm statistics", description = "Get alarm statistics information") public ResponseEntity<Message<AlertSummary>> getAlertsSummary() { AlertSummary alertSummary = alertService.getAlertsSummary(); Message<AlertSummary> message = Message.success(alertSummary); diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/dao/AlertDao.java b/alerter/src/main/java/org/apache/hertzbeat/alert/dao/AlertDao.java index 96a825297..8dda5941f 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/dao/AlertDao.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/dao/AlertDao.java @@ -50,7 +50,6 @@ public interface AlertDao extends JpaRepository<Alert, Long>, JpaSpecificationEx /** * Query the number of unhandled alarms of each alarm severity - * 查询各个告警级别的未处理告警数量 * @return List of alerts num */ @Query("select new org.apache.hertzbeat.alert.dto.AlertPriorityNum(mo.priority, count(mo.id)) from Alert mo where mo.status = 0 group by mo.priority") diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/dao/AlertDefineDao.java b/alerter/src/main/java/org/apache/hertzbeat/alert/dao/AlertDefineDao.java index 8364b330c..15fe8c2c5 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/dao/AlertDefineDao.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/dao/AlertDefineDao.java @@ -39,7 +39,6 @@ public interface AlertDefineDao extends JpaRepository<AlertDefine, Long>, JpaSpe /** * Query the default alarm thresholds based on the monitoring metrics type - * 根据监控指标类型查询对应默认告警定义阈值 * @param app monitoring type * @param metric metrics * @return alarm defines @@ -56,7 +55,6 @@ public interface AlertDefineDao extends JpaRepository<AlertDefine, Long>, JpaSpe /** * Query the alarm definition list associated with the monitoring ID - * 根据监控任务ID查询与之关联的告警定义列表 * @param monitorId monitor id * @param app monitor type * @param metrics metrics diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/dto/AlertSummary.java b/alerter/src/main/java/org/apache/hertzbeat/alert/dto/AlertSummary.java index 2fc14a4fb..30c051877 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/dto/AlertSummary.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/dto/AlertSummary.java @@ -31,35 +31,30 @@ import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY; @Data @AllArgsConstructor @NoArgsConstructor -@Schema(description = "Alarm Statistics Information | 告警统计信息") +@Schema(description = "Alarm Statistics Information") public class AlertSummary { @Schema(title = "Total number of alerts (including processed and unprocessed alerts)", - description = "告警总数量(包括已处理未处理告警)", example = "134", accessMode = READ_ONLY) private long total; @Schema(title = "Number of alerts handled", - description = "已处理告警数量", example = "34", accessMode = READ_ONLY) private long dealNum; @Schema(title = "Alarm handling rate", - description = "告警处理率", example = "39.34", accessMode = READ_ONLY) private float rate; @Schema(title = "Number of alarms whose alarm severity is warning alarms (referring to unhandled alarms)", - description = "告警级别为警告告警的告警数量(指未处理告警)", example = "43", accessMode = READ_ONLY) private long priorityWarningNum; @Schema(title = "Number of alarms whose alarm severity is critical alarms (referring to unhandled alarms)", - description = "告警级别为严重告警的告警数量(指未处理告警)", example = "56", accessMode = READ_ONLY) private long priorityCriticalNum; @Schema(title = "Number of alarms whose alarm severity is urgent alarms (referring to unhandled alarms)", - description = "告警级别为紧急告警的告警数量(指未处理告警)", example = "23", accessMode = READ_ONLY) + example = "23", accessMode = READ_ONLY) private long priorityEmergencyNum; } diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/dto/GeneralCloudAlertReport.java b/alerter/src/main/java/org/apache/hertzbeat/alert/dto/GeneralCloudAlertReport.java index 34b5dc9dd..9178884b7 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/dto/GeneralCloudAlertReport.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/dto/GeneralCloudAlertReport.java @@ -45,28 +45,23 @@ public class GeneralCloudAlertReport extends AlertReport { * You can refresh the timestamp of the alarm time with enhanced properties */ public void refreshAlertTime() { - // 有时间戳,取时间戳 if (getAlertTime() != 0L) { return; } - // 没有时间戳,判断是否有字符串配置 if (StringUtils.isNotBlank(alertDateTime)) { Long timeStamp = null; - // 优先用户配置 if (StringUtils.isNotBlank(dateTimeFormat)) { timeStamp = DateUtil.getTimeStampFromFormat(alertDateTime, dateTimeFormat); } - // 默认支持日期格式 if (timeStamp == null) { timeStamp = DateUtil.getTimeStampFromSomeFormats(alertDateTime); } - // 解析成功 if (timeStamp != null) { setAlertTime(timeStamp); return; } } - throw new RuntimeException("告警时间解析异常"); + throw new RuntimeException("parse alarm time error"); } } diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/dto/TenCloudAlertReport.java b/alerter/src/main/java/org/apache/hertzbeat/alert/dto/TenCloudAlertReport.java index 25a396f63..cc8e71df1 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/dto/TenCloudAlertReport.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/dto/TenCloudAlertReport.java @@ -100,7 +100,7 @@ public class TenCloudAlertReport extends CloudAlertReportAbstract implements Ser @AllArgsConstructor @NoArgsConstructor public static class Conditions { - // 指标告警的参数 + // alarm metrics parameters private String metricName; private String metricShowName; private String calcType; @@ -114,7 +114,7 @@ public class TenCloudAlertReport extends CloudAlertReportAbstract implements Ser private String alarmNotifyType; private long alarmNotifyPeriod; - // 事件告警的参数 + // alarm event parameters private String productName; private String productShowName; private String eventName; diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertDefineImExportService.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertDefineImExportService.java index 85c116cf1..78bc4a19e 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertDefineImExportService.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertDefineImExportService.java @@ -28,30 +28,26 @@ import java.util.List; public interface AlertDefineImExportService { /** * Import Configuration - * 导入配置 - * @param is 输入流 + * @param is input stream */ void importConfig(InputStream is); /** * Export Configuration - * 导出配置 - * @param os 输出流 - * @param configList 配置列表 + * @param os output stream + * @param configList configuration list */ void exportConfig(OutputStream os, List<Long> configList); /** * Export file type - * 导出文件类型 - * @return 文件类型 + * @return file type */ String type(); /** * Get Export File Name - * 获取导出文件名 - * @return 文件名 + * @return file name */ String getFileName(); } diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertDefineService.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertDefineService.java index fa5427345..9e0efe58f 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertDefineService.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertDefineService.java @@ -96,7 +96,6 @@ public interface AlertDefineService { /** * Query the alarm definitions that match the specified metrics associated with the monitoring ID - * 查询与此监控任务ID关联的指定指标匹配的告警定义 * @param monitorId Monitor the ID * @param app Monitoring type * @param metrics metrics @@ -106,7 +105,6 @@ public interface AlertDefineService { /** * Query the alarm definitions that match the specified metrics associated with the monitoring ID - * 查询与此监控任务ID关联的可用性告警定义 * @param monitorId Monitor the ID * @param app Monitoring type * @param metrics metrics @@ -124,7 +122,6 @@ public interface AlertDefineService { /** * Query the associated monitoring list information based on the alarm definition ID - * 根据告警定义ID查询其关联的监控列表关联信息 * @param alertDefineId Alarm Definition ID * @return Associated information about the monitoring list */ @@ -132,7 +129,6 @@ public interface AlertDefineService { /** * Export file configuration of specified type based on ID list and export file type - * 根据ID列表、导出文件类型导出指定类型文件配置 * @param ids AlertDefine ID * @param type File Type * @param res Response @@ -142,7 +138,6 @@ public interface AlertDefineService { /** * Add alarm threshold rules based on the uploaded alarm threshold file - * 根据上传的告警阀值文件,增加告警阀值规则 * @param file Upload File * @throws Exception An exception was thrown during the importConfig */ diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertService.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertService.java index b8df04eaf..3db37ef8d 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertService.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertService.java @@ -49,7 +49,6 @@ public interface AlertService { /** * Delete alarms in batches according to the alarm ID list - * 根据告警ID列表批量删除告警 * @param ids Alarm ID List */ void deleteAlerts(HashSet<Long> ids); @@ -61,7 +60,6 @@ public interface AlertService { /** * Update the alarm status according to the alarm ID-status value - * 根据告警ID-状态值 更新告警状态 * @param status Alarm status to be modified * @param ids Alarm ID List to be modified */ diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineAbstractImExportServiceImpl.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineAbstractImExportServiceImpl.java index 9fb287078..ed98272db 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineAbstractImExportServiceImpl.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineAbstractImExportServiceImpl.java @@ -74,17 +74,16 @@ public abstract class AlertDefineAbstractImExportServiceImpl implements AlertDef /** * Parsing an input stream into a form - * 将输入流解析为表单 * - * @param is 输入流 - * @return 表单 + * @param is input stream + * @return form list */ abstract List<ExportAlertDefineDTO> parseImport(InputStream is); /** * Export Configuration to Output Stream - * @param exportAlertDefineList 配置列表 - * @param os 输出流 + * @param exportAlertDefineList configuration list + * @param os output stream */ abstract void writeOs(List<ExportAlertDefineDTO> exportAlertDefineList, OutputStream os); diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineExcelImExportServiceImpl.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineExcelImExportServiceImpl.java index 754299692..dcebc80b3 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineExcelImExportServiceImpl.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineExcelImExportServiceImpl.java @@ -42,7 +42,7 @@ public class AlertDefineExcelImExportServiceImpl extends AlertDefineAbstractImEx /** * Export file type - * @return 文件类型 + * @return file type */ @Override public String type() { @@ -51,7 +51,7 @@ public class AlertDefineExcelImExportServiceImpl extends AlertDefineAbstractImEx /** * Get Export File Name - * @return 文件名 + * @return file name */ @Override public String getFileName() { @@ -61,8 +61,8 @@ public class AlertDefineExcelImExportServiceImpl extends AlertDefineAbstractImEx /** * Parsing an input stream into a form - * @param is 输入流 - * @return 表单 + * @param is input stream + * @return form list */ @Override List<ExportAlertDefineDTO> parseImport(InputStream is) { @@ -174,8 +174,8 @@ public class AlertDefineExcelImExportServiceImpl extends AlertDefineAbstractImEx /** * Export Configuration to Output Stream - * @param exportAlertDefineList 配置列表 - * @param os 输出流 + * @param exportAlertDefineList exportAlertDefineList + * @param os output stream */ @Override void writeOs(List<ExportAlertDefineDTO> exportAlertDefineList, OutputStream os) { @@ -186,16 +186,16 @@ public class AlertDefineExcelImExportServiceImpl extends AlertDefineAbstractImEx sheet.setDefaultColumnWidth(20); sheet.setColumnWidth(9, 40 * 256); sheet.setColumnWidth(10, 40 * 256); - // 设置表头样式 + // set header style CellStyle headerCellStyle = workbook.createCellStyle(); Font headerFont = workbook.createFont(); headerFont.setBold(true); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(HorizontalAlignment.CENTER); - // 设置表格内容样式 + // set cell style CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(HorizontalAlignment.CENTER); - // 设置表头 + // set header String[] headers = {"app", "metric", "field", "preset", "expr", "priority", "times", "tags", "enable", "recoverNotice", "template"}; Row headerRow = sheet.createRow(0); @@ -205,14 +205,12 @@ public class AlertDefineExcelImExportServiceImpl extends AlertDefineAbstractImEx cell.setCellStyle(headerCellStyle); } - // 遍历阀值规则列表,每个阀值规则对象对应一行数据 + // Traverse the threshold rule list, each threshold rule object corresponds to a row of data int rowIndex = 1; for (ExportAlertDefineDTO alertDefine : exportAlertDefineList) { - // 获取阀值规则信息 AlertDefineDTO alertDefineDTO = alertDefine.getAlertDefine(); - // 阀值规则信息一行中 Row row = sheet.createRow(rowIndex++); - // 阀值规则信息只需要写一次 + // Threshold rule information only needs to be written once Cell appCell = row.createCell(0); appCell.setCellValue(alertDefineDTO.getApp()); appCell.setCellStyle(cellStyle); @@ -235,9 +233,9 @@ public class AlertDefineExcelImExportServiceImpl extends AlertDefineAbstractImEx Cell timesCell = row.createCell(6); timesCell.setCellValue(alertDefineDTO.getTimes()); Cell tagCell = row.createCell(7); - // 获取标签信息 + // get tags List<TagItem> tagList = alertDefineDTO.getTags(); - String tagValue = tagList == null || tagList.size() == 0 ? "" : JsonUtil.toJson(tagList); + String tagValue = tagList == null || tagList.isEmpty() ? "" : JsonUtil.toJson(tagList); tagCell.setCellValue(tagValue); tagCell.setCellStyle(cellStyle); Cell enableCell = row.createCell(8); diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineServiceImpl.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineServiceImpl.java index d8ba1dd5a..5869350ba 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineServiceImpl.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineServiceImpl.java @@ -107,7 +107,6 @@ public class AlertDefineServiceImpl implements AlertDefineService { @Override public void applyBindAlertDefineMonitors(Long alertId, List<AlertDefineMonitorBind> alertDefineBinds) { // todo checks whether the alarm definition and monitoring exist - // todo 校验此告警定义和监控是否存在 if (!alertDefineBindDao.existsById(alertId)){ alertDefineBindDao.deleteAlertDefineBindsByAlertDefineIdEquals(alertId); } @@ -125,7 +124,6 @@ public class AlertDefineServiceImpl implements AlertDefineService { Set<AlertDefine> defineSet = defines.stream().filter(item -> item.getField() != null).collect(Collectors.toSet()); // The alarm thresholds are defined in ascending order of the alarm severity from 0 to 3. // The lower the number, the higher the alarm is. That is, the alarm is calculated from the highest alarm threshold - // 将告警阈值定义从告警级别0-3数字升序排序,数字越小告警基本越高,即从最高的告警阈值开始匹配计算 return defineSet.stream().sorted(Comparator.comparing(AlertDefine::getPriority)) .collect(Collectors.groupingBy(AlertDefine::getField)); } diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertSilenceServiceImpl.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertSilenceServiceImpl.java index c171a6072..2f495eea0 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertSilenceServiceImpl.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertSilenceServiceImpl.java @@ -48,7 +48,7 @@ public class AlertSilenceServiceImpl implements AlertSilenceService { @Override public void validate(AlertSilence alertSilence, boolean isModify) throws IllegalArgumentException { // todo - // 兜底策略, 如果周期性情况下设置的告警静默选择日期为空, 视为全部勾选 + // if the alarm silent selection date set in periodic situations is empty, it will be deemed to be all checked. if (alertSilence.getType() == 1 && alertSilence.getDays() == null) { alertSilence.setDays(Arrays.asList((byte) 7, (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5, (byte) 6)); } diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/util/AlertTemplateUtil.java b/alerter/src/main/java/org/apache/hertzbeat/alert/util/AlertTemplateUtil.java index fe5feaf9c..3f8aea5cc 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/util/AlertTemplateUtil.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/util/AlertTemplateUtil.java @@ -25,14 +25,12 @@ import java.util.regex.Pattern; /** * Alarm template keyword matching replacement engine tool - * 告警模版关键字匹配替换引擎工具 */ @Slf4j public class AlertTemplateUtil { /** * Match the variable ${key} - * 匹配 ${key} 的变量 * eg: Alert, the instance: ${instance} metrics: ${metrics} is over flow. */ private static final Pattern PATTERN = Pattern.compile("\\$\\{(\\w+)\\}"); diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefineControllerTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefineControllerTest.java index 556763a34..9f19a0dab 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefineControllerTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefineControllerTest.java @@ -43,8 +43,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. /** * Test case for {@link AlertDefineController} - * - * */ @ExtendWith(MockitoExtension.class) class AlertDefineControllerTest { @@ -63,7 +61,7 @@ class AlertDefineControllerTest { @BeforeEach void setUp() { - // standaloneSetup: 独立安装, 不集成web环境测试 + // standaloneSetup this.mockMvc = MockMvcBuilders.standaloneSetup(alertDefineController).build(); this.alertDefine = AlertDefine.builder() @@ -99,7 +97,7 @@ class AlertDefineControllerTest { @Test void addNewAlertDefine() throws Exception { - // 模拟客户端往服务端发送请求 + // mock http request mockMvc.perform(MockMvcRequestBuilders.post("/api/alert/define") .contentType(MediaType.APPLICATION_JSON) .content(JsonUtil.toJson(this.alertDefine))) @@ -120,7 +118,7 @@ class AlertDefineControllerTest { @Test void getAlertDefine() throws Exception { - // 模拟getAlertDefine返回数据 + // mock getAlertDefine return data Mockito.when(alertDefineService.getAlertDefine(this.alertDefine.getId())) .thenReturn(this.alertDefine); diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefinesControllerTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefinesControllerTest.java index 58532f256..7c83fe3a3 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefinesControllerTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertDefinesControllerTest.java @@ -44,9 +44,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. /** * Test case for {@link AlertDefinesController} - * 测试mock处的数据是否正确,测试返回的数据格式是否正确 - * - * */ @ExtendWith(MockitoExtension.class) class AlertDefinesControllerTest { @@ -59,58 +56,36 @@ class AlertDefinesControllerTest { @Mock AlertDefineService alertDefineService; - // 参数如下,为了避免默认值干扰,默认值已经被替换 + // replace default value List<Long> ids = Stream.of(6565463543L, 6565463544L).collect(Collectors.toList()); Byte priority = Byte.parseByte("1"); String sort = "gmtCreate"; String order = "asc"; Integer pageIndex = 1; Integer pageSize = 7; - - // 参数集合 Map<String, Object> content = new HashMap<String, Object>(); - - // 用于mock的对象 PageRequest pageRequest; - - // 由于specification被使用于动态代理,所以无法mock - // 缺失的调试参数是ids、priority - // 缺失部分已经通过手动输出测试 + + // Since the specification is used for dynamic proxies, it cannot be mocked + //The missing debugging parameters are ids, priority + //The missing part has passed the manual output test @BeforeEach void setUp() { this.mockMvc = MockMvcBuilders.standaloneSetup(alertDefinesController).build(); - - // 配置测试内容 content.put("ids", ids); content.put("priority", priority); content.put("sort", sort); content.put("order", order); content.put("pageIndex", pageIndex); content.put("pageSize", pageSize); - - // mock的pageRequest Sort sortExp = Sort.by(new Sort.Order(Sort.Direction.fromString(content.get("order").toString()), content.get("sort").toString())); pageRequest = PageRequest.of(((Integer) content.get("pageIndex")).intValue(), ((Integer) content.get("pageSize")).intValue(), sortExp); } -// @Test -// todo: fix this test + // @Test + // todo: fix this test void getAlertDefines() throws Exception { - // 测试mock正确性 - // 虽然无法mock对象,但是可以用class文件去存根 -// Mockito.when(alertDefineService.getAlertDefines(Mockito.any(Specification.class), Mockito.argThat(new ArgumentMatcher<PageRequest>() { -// @Override -// public boolean matches(PageRequest pageRequestMidden) { -// // 看源码有三个方法要对比,分别是getPageNumber()、getPageSize()、getSort() -// if(pageRequestMidden.getPageSize() == pageRequest.getPageSize() && -// pageRequestMidden.getPageNumber() == pageRequest.getPageNumber() && -// pageRequestMidden.getSort().equals(pageRequest.getSort())) { -// return true; -// } -// return false; -// } -// }))).thenReturn(new PageImpl<AlertDefine>(new ArrayList<AlertDefine>())); AlertDefine define = AlertDefine.builder().id(9L).app("linux").metric("disk").field("usage").expr("x").times(1).tags(new LinkedList<>()).build(); Mockito.when(alertDefineService.getAlertDefines(Mockito.any(), Mockito.any())).thenReturn(new PageImpl<>(Collections.singletonList(define))); diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertReportControllerTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertReportControllerTest.java index b4cf822e6..2666364bc 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertReportControllerTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertReportControllerTest.java @@ -39,7 +39,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. /** * unit test for {@link AlertReportController } - * */ @ExtendWith(MockitoExtension.class) class AlertReportControllerTest { @@ -63,8 +62,8 @@ class AlertReportControllerTest { dimensions.setUnInstanceId("3333"); TenCloudAlertReport.AlarmObjInfo alarmObjInfo = new TenCloudAlertReport.AlarmObjInfo(); - alarmObjInfo.setRegion("广东"); - alarmObjInfo.setNamespace("广州节点1"); + alarmObjInfo.setRegion("Guangzhou"); + alarmObjInfo.setNamespace("Guangzhou1"); alarmObjInfo.setAppId("1111"); alarmObjInfo.setUin("2222"); alarmObjInfo.setDimensions(dimensions); @@ -78,13 +77,13 @@ class AlertReportControllerTest { conditions.setCurrentValue("b"); conditions.setCalcUnit("bb"); conditions.setProductName("guangzhou"); - conditions.setProductShowName("广州"); + conditions.setProductShowName("Guangzhou1"); conditions.setEventName("CVS"); - conditions.setEventShowName("内核异常"); + conditions.setEventShowName("Core error"); TenCloudAlertReport.AlarmPolicyInfo alarmPolicyInfo = new TenCloudAlertReport.AlarmPolicyInfo(); alarmPolicyInfo.setPolicyTypeCname("x"); - alarmPolicyInfo.setPolicyName("测试1"); + alarmPolicyInfo.setPolicyName("Test1"); alarmPolicyInfo.setConditions(conditions); TenCloudAlertReport report = TenCloudAlertReport.builder() diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertsControllerTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertsControllerTest.java index 9fff92556..144595f71 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertsControllerTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/controller/AlertsControllerTest.java @@ -70,17 +70,12 @@ class AlertsControllerTest { // @Test // todo: fix this test void getAlerts() throws Exception { - - //定义要用到的测试值 String sortField = "id"; String orderType = "asc"; int pageIndex = 0; int pageSize = 10; PageRequest pageRequest = PageRequest.of(pageIndex, pageSize, Sort.by(new Sort.Order(Sort.Direction.fromString(orderType), sortField))); Page<Alert> alertPage = new PageImpl<>(Collections.singletonList(Alert.builder().build())); - - - //打桩 Mockito.when( alertService.getAlerts( Mockito.any(Specification.class) @@ -153,7 +148,6 @@ class AlertsControllerTest { @Test void getAlertsSummary() throws Exception { - //打桩 Mockito.when(alertService.getAlertsSummary()).thenReturn(new AlertSummary()); mockMvc.perform( diff --git a/alerter/src/test/java/org/apache/hertzbeat/alert/util/AlertTemplateUtilTest.java b/alerter/src/test/java/org/apache/hertzbeat/alert/util/AlertTemplateUtilTest.java index 22862b504..cdff331b5 100644 --- a/alerter/src/test/java/org/apache/hertzbeat/alert/util/AlertTemplateUtilTest.java +++ b/alerter/src/test/java/org/apache/hertzbeat/alert/util/AlertTemplateUtilTest.java @@ -30,10 +30,6 @@ import static org.junit.jupiter.api.Assertions.*; */ class AlertTemplateUtilTest { - class TemplateValue { - - } - @BeforeEach void setUp() { } @@ -92,4 +88,4 @@ class AlertTemplateUtilTest { String expectedResult = "The price is $100 and the path is C:\\Users"; assertEquals(expectedResult, AlertTemplateUtil.render(template, param)); } -} \ No newline at end of file +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
