Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,6 @@ public void modifyMonitor(Monitor monitor, List<Param> params, String collector,
newJobId = collectJobScheduling.updateAsyncCollectJob(appDefine, collector);
}
monitor.setJobId(newJobId);

Comment thread
wilmerdooley marked this conversation as resolved.
// execute only in non paused status
try {
detectMonitor(monitor, params, collector);
} catch (Exception ignored) {
}
}

// After the update is successfully released, refresh the database
Expand All @@ -451,6 +445,8 @@ public void modifyMonitor(Monitor monitor, List<Param> params, String collector,
// force update gmtUpdate time, due the case: monitor not change, param change.
// we also think monitor change
monitor.setGmtUpdate(LocalDateTime.now());
// preserve the live status owned by the real-time collection path; the modify request must not overwrite it
monitor.setStatus(preMonitor.getStatus());
// update or open grafana dashboard
if (monitor.getApp().equals(CommonConstants.PROMETHEUS) && grafanaDashboard != null) {
if (grafanaDashboard.isEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
Expand Down Expand Up @@ -634,6 +635,46 @@ void modifyMonitor() {
() -> monitorService.modifyMonitor(dto.getMonitor(), dto.getParams(), null, null));
}

@Test
void testModifyMonitorPreservesLiveStatus() {
long monitorId = 1L;
List<Param> params = Collections.singletonList(Param.builder()
.field("field")
.paramValue("value")
.build());
Monitor preMonitor = Monitor.builder().jobId(1L).intervals(1).app("app").name("memory").instance("host")
.id(monitorId).status(CommonConstants.MONITOR_UP_CODE).build();
Monitor monitor = Monitor.builder().jobId(1L).intervals(1).app("app").name("memory").instance("host")
.id(monitorId).status(CommonConstants.MONITOR_PAUSED_CODE).build();
Job job = new Job();
job.setApp(monitor.getApp());
when(monitorDao.findById(monitorId)).thenReturn(Optional.of(preMonitor));
when(tagService.determineNewLabels(any())).thenReturn(Collections.emptyList());
when(appService.getAppDefine(monitor.getApp())).thenReturn(job);
when(collectJobScheduling.updateAsyncCollectJob(any(Job.class))).thenReturn(1L);

monitorService.modifyMonitor(monitor, params, null, null);

ArgumentCaptor<Monitor> monitorCaptor = ArgumentCaptor.forClass(Monitor.class);
verify(monitorDao).save(monitorCaptor.capture());
assertEquals(CommonConstants.MONITOR_UP_CODE, monitorCaptor.getValue().getStatus());

reset(monitorDao, tagService, appService, collectJobScheduling, paramDao, collectorMonitorBindDao);
long pausedMonitorId = 2L;
Monitor pausedPreMonitor = Monitor.builder().jobId(2L).intervals(1).app("app").name("memory").instance("host")
.id(pausedMonitorId).status(CommonConstants.MONITOR_PAUSED_CODE).build();
Monitor pausedMonitor = Monitor.builder().jobId(2L).intervals(1).app("app").name("memory").instance("host")
.id(pausedMonitorId).status(CommonConstants.MONITOR_UP_CODE).build();
when(monitorDao.findById(pausedMonitorId)).thenReturn(Optional.of(pausedPreMonitor));
when(tagService.determineNewLabels(any())).thenReturn(Collections.emptyList());

monitorService.modifyMonitor(pausedMonitor, params, null, null);

monitorCaptor = ArgumentCaptor.forClass(Monitor.class);
verify(monitorDao).save(monitorCaptor.capture());
assertEquals(CommonConstants.MONITOR_PAUSED_CODE, monitorCaptor.getValue().getStatus());
}

@Test
void deleteMonitor() {
Set<Long> ids = new HashSet<>();
Expand Down
Loading