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
14 changes: 12 additions & 2 deletions server/src/main/java/com/cloud/server/StatsCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -1285,14 +1285,24 @@ protected Point createInfluxDbPoint(Object metricsObject) {
* can be enabled/disabled independently.</p>
*/
class VmStatsCleaner extends ManagedContextRunnable{
@Override
protected void runInContext() {
cleanUpVirtualMachineStats();
try {
cleanUpVirtualMachineStats();
} catch (RuntimeException e) {
logger.error("Error trying to clean up VM stats", e);
}
}
}

class VolumeStatsCleaner extends ManagedContextRunnable{
@Override
protected void runInContext() {
cleanUpVolumeStats();
try {
cleanUpVolumeStats();
} catch (RuntimeException e) {
logger.error("Error trying to clean up Volume stats", e);
}
}
}

Expand Down
43 changes: 43 additions & 0 deletions server/src/test/java/com/cloud/server/StatsCollectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,49 @@ public void cleanUpVirtualMachineStatsTestIsEnabled() {
Mockito.verify(vmStatsDaoMock).removeAllByTimestampLessThan(Mockito.any(), Mockito.anyLong());
}

private void setVmDiskStatsMaxRetentionTimeValue(String value) {
StatsCollector.vmDiskStatsMaxRetentionTime = new ConfigKey<Integer>("Advanced", Integer.class, "vm.disk.stats.max.retention.time", value,
"The maximum time (in minutes) for keeping Volume stats records in the database. The Volume stats cleanup process will be disabled if this is set to 0 or less than 0.", true);
Comment thread
DaanHoogland marked this conversation as resolved.
}

@Test
public void cleanUpVolumeStatsTestIsDisabled() {
setVmDiskStatsMaxRetentionTimeValue("0");

statsCollector.cleanUpVolumeStats();

Mockito.verify(volumeStatsDao, Mockito.never()).removeAllByTimestampLessThan(Mockito.any(), Mockito.anyLong());
}

@Test
public void cleanUpVolumeStatsTestIsEnabled() {
setVmDiskStatsMaxRetentionTimeValue("1");

statsCollector.cleanUpVolumeStats();

Mockito.verify(volumeStatsDao).removeAllByTimestampLessThan(Mockito.any(), Mockito.anyLong());
}

@Test
public void vmStatsCleanerTestCatchesCloudRuntimeExceptionAndKeepsRunning() {
Mockito.doThrow(new CloudRuntimeException("Communications link failure")).when(statsCollector).cleanUpVirtualMachineStats();
StatsCollector.VmStatsCleaner vmStatsCleaner = statsCollector.new VmStatsCleaner();

vmStatsCleaner.run();

Mockito.verify(statsCollector).cleanUpVirtualMachineStats();
}

@Test
public void volumeStatsCleanerTestCatchesCloudRuntimeExceptionAndKeepsRunning() {
Mockito.doThrow(new CloudRuntimeException("Communications link failure")).when(statsCollector).cleanUpVolumeStats();
StatsCollector.VolumeStatsCleaner volumeStatsCleaner = statsCollector.new VolumeStatsCleaner();

volumeStatsCleaner.run();

Mockito.verify(statsCollector).cleanUpVolumeStats();
}

@Test
public void persistVirtualMachineStatsTestPersistsSuccessfully() {
statsCollector.msId = 1L;
Expand Down
Loading