This is an automated email from the ASF dual-hosted git repository.

gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git


The following commit(s) were added to refs/heads/master by this push:
     new 7ee227196 [bugfix] fixed "Alert Threshold Association with Monitors" 
is invalid  bug #2105 (#2191)
7ee227196 is described below

commit 7ee227196d5c1c52704fd322b131ea65fa84e23a
Author: kangli <[email protected]>
AuthorDate: Thu Jul 4 19:11:17 2024 +0800

    [bugfix] fixed "Alert Threshold Association with Monitors" is invalid  bug 
#2105 (#2191)
    
    Co-authored-by: tomsun28 <[email protected]>
---
 .../alert/service/impl/AlertDefineServiceImpl.java | 25 +++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

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 21d07b2e1..b29add88a 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
@@ -26,14 +26,17 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.hertzbeat.alert.dao.AlertDefineBindDao;
 import org.apache.hertzbeat.alert.dao.AlertDefineDao;
+import org.apache.hertzbeat.alert.dao.AlertMonitorDao;
 import org.apache.hertzbeat.alert.service.AlertDefineImExportService;
 import org.apache.hertzbeat.alert.service.AlertDefineService;
 import org.apache.hertzbeat.common.entity.alerter.AlertDefine;
 import org.apache.hertzbeat.common.entity.alerter.AlertDefineMonitorBind;
+import org.apache.hertzbeat.common.entity.manager.Monitor;
 import org.apache.hertzbeat.common.util.JexlExpressionRunner;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -59,6 +62,9 @@ public class AlertDefineServiceImpl implements 
AlertDefineService {
     @Autowired
     private AlertDefineBindDao alertDefineBindDao;
 
+    @Autowired
+    private AlertMonitorDao alertMonitorDao;
+
     private final Map<String, AlertDefineImExportService> 
alertDefineImExportServiceMap = new HashMap<>();
 
     public AlertDefineServiceImpl(List<AlertDefineImExportService> 
alertDefineImExportServiceList) {
@@ -147,7 +153,24 @@ public class AlertDefineServiceImpl implements 
AlertDefineService {
 
     @Override
     public List<AlertDefineMonitorBind> getBindAlertDefineMonitors(long 
alertDefineId) {
-        return 
alertDefineBindDao.getAlertDefineBindsByAlertDefineIdEquals(alertDefineId);
+        List<AlertDefineMonitorBind> defineMonitorBinds = 
alertDefineBindDao.getAlertDefineBindsByAlertDefineIdEquals(alertDefineId);
+        if (defineMonitorBinds == null || defineMonitorBinds.isEmpty()) {
+            return defineMonitorBinds;
+        }
+        List<Long> needLoadMonitorIds = defineMonitorBinds.stream()
+                .filter(bind -> bind.getMonitor() == null)
+                .map(AlertDefineMonitorBind::getMonitorId).toList();
+        if (needLoadMonitorIds.isEmpty()) {
+            return defineMonitorBinds;
+        }
+        Map<Long, Monitor> monitorMap = 
alertMonitorDao.findAllById(needLoadMonitorIds)
+                .stream().collect(Collectors.toMap(Monitor::getId, 
Function.identity()));
+        for (AlertDefineMonitorBind bind : defineMonitorBinds) {
+            if (bind.getMonitor() == null) {
+                bind.setMonitor(monitorMap.get(bind.getMonitorId()));
+            }
+        }
+        return defineMonitorBinds;
     }
 
     @Override


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to