Browse Source

[alerter,manager]fixbug 初次探测后影响配置,采集任务状态处理,插入TdEngine时转义问题,开发环境读取探测配置文件时路径错误
Merge pull request !2 from random-chat/fixed_bug_20220209

tomsun28 4 năm trước cách đây
mục cha
commit
be050fbc83

+ 12 - 3
alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java

@@ -78,7 +78,13 @@ public class CalculateAlarm {
                         .priority(CommonConstants.ALERT_PRIORITY_CODE_EMERGENCY)
                         .status(CommonConstants.ALERT_STATUS_CODE_PENDING)
                         .times(1);
-                if (metricsData.getCode() == CollectRep.Code.UN_REACHABLE) {
+                if (metricsData.getCode() == CollectRep.Code.UN_AVAILABLE) {
+                    // 采集器不可用
+                    alertBuilder.target(CommonConstants.AVAILABLE)
+                            .content("监控紧急可用性告警: " + metricsData.getCode().name());
+                    triggeredMonitorStateAlertMap.put(monitorId, CollectRep.Code.UN_AVAILABLE);
+                    dataQueue.addAlertData(alertBuilder.build());
+                } else if (metricsData.getCode() == CollectRep.Code.UN_REACHABLE) {
                     // UN_REACHABLE 对端不可达(网络层icmp)
                     alertBuilder.target(CommonConstants.REACHABLE)
                             .content("监控紧急可达性告警: " + metricsData.getCode().name());
@@ -91,8 +97,11 @@ public class CalculateAlarm {
                     triggeredMonitorStateAlertMap.put(monitorId, CollectRep.Code.UN_CONNECTABLE);
                     dataQueue.addAlertData(alertBuilder.build());
                 } else {
-                    // todo 其它规范异常 TIMEOUT ...
-                    return;
+                    // 其他异常
+                    alertBuilder.target(CommonConstants.AVAILABLE)
+                            .content("监控紧急可用性告警: " + metricsData.getCode().name());
+                    triggeredMonitorStateAlertMap.put(monitorId, metricsData.getCode());
+                    dataQueue.addAlertData(alertBuilder.build());
                 }
                 return;
             } else {

+ 8 - 0
common/src/main/java/com/usthe/common/entity/job/Job.java

@@ -2,6 +2,7 @@ package com.usthe.common.entity.job;
 
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.google.gson.Gson;
 import com.usthe.common.entity.message.CollectRep;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -180,4 +181,11 @@ public class Job {
         }
         responseDataTemp.add(metricsData);
     }
+
+    private static final Gson GSON = new Gson();
+
+    public Job clone(){
+        // 深度克隆
+        return GSON.fromJson(GSON.toJsonTree(this), Job.class);
+    }
 }

+ 2 - 2
manager/src/main/java/com/usthe/manager/service/impl/AppServiceImpl.java

@@ -59,7 +59,7 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
         if (appDefine == null) {
             throw new IllegalArgumentException("The app " + app + " not support.");
         }
-        return appDefine;
+        return appDefine.clone();
     }
 
     @Override
@@ -123,7 +123,7 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
     public void run(String... args) throws Exception {
         // 读取app定义配置加载到内存中 define/app/*.yml
         Yaml yaml = new Yaml();
-        String classpath = this.getClass().getResource(File.separator).getPath();
+        String classpath = this.getClass().getClassLoader().getResource("").getPath();
         String defineAppPath = classpath + File.separator + "define" + File.separator + "app";
         File directory = new File(defineAppPath);
         if (!directory.exists() || directory.listFiles() == null) {

+ 4 - 2
warehouse/src/main/java/com/usthe/warehouse/store/TdEngineDataStorage.java

@@ -138,7 +138,7 @@ public class TdEngineDataStorage implements DisposableBean {
                     if (CommonConstants.NULL_VALUE.equals(value)) {
                         sqlRowBuffer.append("NULL");
                     } else {
-                        sqlRowBuffer.append("'").append(value).append("'");
+                        sqlRowBuffer.append("'").append(formatStringValue(value)).append("'");
                     }
                 }
                 if (index != fields.size() - 1) {
@@ -197,7 +197,9 @@ public class TdEngineDataStorage implements DisposableBean {
         }
     }
 
-
+    private String formatStringValue(String value){
+        return value.replaceAll("(\\\\)|(')","\\\\$0");
+    }
     @Override
     public void destroy() throws Exception {
         if (hikariDataSource != null) {