tomsun28 commented on code in PR #3300:
URL: https://github.com/apache/hertzbeat/pull/3300#discussion_r2084065551


##########
hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/service/impl/MonitorServiceImpl.java:
##########
@@ -393,36 +430,14 @@ public void modifyMonitor(Monitor monitor, List<Param> 
params, String collector,
             labels = new HashMap<>(8);
             monitor.setLabels(labels);
         }
-
+        boolean isStatic = 
CommonConstants.SCRAPE_STATIC.equals(monitor.getScrape()) || 
!StringUtils.hasText(monitor.getScrape());
         if (preMonitor.getStatus() != CommonConstants.MONITOR_PAUSED_CODE) {
             // Construct the collection task Job entity
-            Job appDefine = appService.getAppDefine(monitor.getApp());
-            if (sdParam.isPresent()) {
-                // not allow to modify a sub monitor to main monitor
-                labels.entrySet()
-                        .stream()
-                        .filter(label -> 
org.apache.commons.lang3.StringUtils.equals(label.getKey(), 
CommonConstants.TAG_AUTO_CREATED))
-                        .findFirst()
-                        .ifPresent(label -> {
-                            final MonitorBind isSubMonitorBefore = 
monitorBindDao.findMonitorBindByBizIdAndMonitorIdAndType(Long.valueOf(label.getValue()),
-                                    monitorId, 
CommonConstants.MONITOR_BIND_TYPE_SD_SUB_MONITOR);
-                            if (Objects.nonNull(isSubMonitorBefore)) {
-                                throw new UnsupportedOperationException("Can 
not change a auto-created monitor to sd! ");
-                            }
-                        });
-                // create main monitor bind
-                final List<MonitorBind> mainMonitorBind = 
monitorBindDao.findMonitorBindByBizIdAndType(monitorId, 
CommonConstants.MONITOR_BIND_TYPE_SD_MAIN_MONITOR);
-                if (CollectionUtils.isEmpty(mainMonitorBind)) {
-                    monitorBindDao.save(Objects.requireNonNull(
-                            SdMonitorOperator.buildSdMainMonitorBind(
-                                    
SdMonitorParam.builder().sdParam(sdParam.get()).build(), monitorId
-                            )));
-                }
-
-                appDefine = SdMonitorOperator.constructSdJob(appDefine, 
sdParam.get());
-                labels.put(CommonConstants.TAG_SD_MAIN_MONITOR, 
ServiceDiscoveryProtocol.Type.getType(sdParam.get().getField()).name());
+            String app = isStatic ? monitor.getApp() : monitor.getScrape();
+            Job appDefine = appService.getAppDefine(app);
+            if (!isStatic) {
+                appDefine.setSd(true);

Review Comment:
   > My original thought is that when you enable a sd monitor, its sub-monitors 
should be enabled as well. The same on deleting sd monitor
   
   Hi, this is my oversight, it should be that the automatically discovered 
subtasks should be changed and deleted along with the changes to the main task.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to