Skip to content

Commit

Permalink
fix and pass the checkstyle error in alerter module code (#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZY945 authored Feb 28, 2024
1 parent e450d20 commit 2103053
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public static class EntranceProperties {
*/
private KafkaProperties kafka;

/**
* kafka configuration information
*/
@Getter
@Setter
public static class KafkaProperties {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private void handlerAvailableMetrics(long monitorId, String app, CollectRep.Metr
return;
}
long currentTimeMill = System.currentTimeMillis();
if (metricsData.getCode() != CollectRep.Code.SUCCESS ) {
if (metricsData.getCode() != CollectRep.Code.SUCCESS) {
Alert preAlert = triggeredAlertMap.get(String.valueOf(monitorId));
Map<String, String> tags = new HashMap<>(6);
tags.put(CommonConstants.TAG_MONITOR_ID, String.valueOf(monitorId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ResponseEntity<Message<Page<AlertSilence>>> getAlertSilences(
};
Sort sortExp = Sort.by(new Sort.Order(Sort.Direction.fromString(order), sort));
PageRequest pageRequest = PageRequest.of(pageIndex, pageSize, sortExp);
Page<AlertSilence> alertSilencePage = alertSilenceService.getAlertSilences(specification,pageRequest);
Page<AlertSilence> alertSilencePage = alertSilenceService.getAlertSilences(specification, pageRequest);
Message<Page<AlertSilence>> message = Message.success(alertSilencePage);
return ResponseEntity.ok(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@


import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.dromara.hertzbeat.alert.util.DateUtil;

import java.io.Serializable;
Expand All @@ -28,6 +32,9 @@ public class TenCloudAlertReport extends CloudAlertReportAbstract implements Ser
private int durationTime;
private String recoverTime;

/**
* Alarm Object information
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
Expand All @@ -40,6 +47,9 @@ public static class AlarmObjInfo {
private Dimensions dimensions;
}

/**
* Uniform Resource ID information
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
Expand All @@ -49,6 +59,10 @@ public static class Dimensions {
@JsonProperty("objID")
private String objId;
}

/**
* Alarm policy information
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
Expand All @@ -61,6 +75,10 @@ public static class AlarmPolicyInfo {
private String policyTypeCname;
private Conditions conditions;
}

/**
* Parameters of indicator alarms
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ private AlertDefine convert(ExportAlertDefineDTO exportAlertDefineDTO) {
return alertDefine;
}

protected String
fileNamePrefix() {
protected String fileNamePrefix() {
return "hertzbeat_alertDefine_" + LocalDate.now();
}

/**
* Export data transfer objects for alert configurations
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
Expand All @@ -107,6 +109,9 @@ protected static class ExportAlertDefineDTO {
private AlertDefineDTO alertDefine;
}

/**
* Data transfer object for alert configuration
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public Map<String, List<AlertDefine>> getMonitorBindAlertDefines(long monitorId,
List<AlertDefine> defaultDefines = alertDefineDao.queryAlertDefinesByAppAndMetricAndPresetTrueAndEnableTrue(app, metrics);
defines.addAll(defaultDefines);
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
// 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ public List<Alert> getAlerts(Specification<Alert> specification) {
private Alert buildAlertData(AlertReport alertReport){
Map<String, String> annotations = alertReport.getAnnotations();
StringBuilder sb = new StringBuilder();
if(alertReport.getContent() == null || alertReport.getContent().length() <= 0){
if (alertReport.getContent() == null || alertReport.getContent().length() <= 0){
StringBuilder finalSb = sb;
annotations.forEach((k, v) -> {
finalSb.append(k).append(":").append(v).append("\n");
});
}else{
}else {
sb = new StringBuilder(alertReport.getContent());
}
LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(alertReport.getAlertTime()),
Expand Down

0 comments on commit 2103053

Please sign in to comment.