guard against stopping stats background threads#13659
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.20 #13659 +/- ##
=========================================
Coverage 16.26% 16.26%
Complexity 13435 13435
=========================================
Files 5667 5667
Lines 500731 500739 +8
Branches 60803 60803
=========================================
+ Hits 81430 81452 +22
+ Misses 410197 410180 -17
- Partials 9104 9107 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent the periodic VM/Volume stats cleanup background tasks in StatsCollector from being permanently stopped when a cleanup run throws an exception (per #13648).
Changes:
- Wrapped
VmStatsCleanerandVolumeStatsCleanercleanup calls in try/catch blocks to avoid uncaught exceptions escaping the scheduled task. - Added unit tests for volume stats cleanup enable/disable behavior and for cleaner exception handling.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
server/src/main/java/com/cloud/server/StatsCollector.java |
Adds exception handling around scheduled cleanup runnables to prevent task termination. |
server/src/test/java/com/cloud/server/StatsCollectorTest.java |
Adds tests covering volume stats cleanup gating and cleaner exception scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: dahn <daan.hoogland@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (3)
server/src/main/java/com/cloud/server/StatsCollector.java:1299
- Add
@Overridefor runInContext() to match the other ManagedContextRunnable inner classes in this file and avoid accidentally changing the method signature without compiler errors.
class VolumeStatsCleaner extends ManagedContextRunnable{
protected void runInContext() {
try {
server/src/test/java/com/cloud/server/StatsCollectorTest.java:341
- The test helper recreates vmDiskStatsMaxRetentionTime with a description that refers to "Volume stats"; the production ConfigKey description is for "VM disks stats". Keeping the text consistent reduces confusion when reading test failures or generated config docs.
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);
}
server/src/test/java/com/cloud/server/StatsCollectorTest.java:373
- Same as the VM cleaner test: the name suggests only CloudRuntimeException is handled and that the task "keeps running", but the code catches RuntimeException and the test asserts non-propagation for a single run(). Rename to match the behavior under test.
@Test
public void volumeStatsCleanerTestCatchesCloudRuntimeExceptionAndKeepsRunning() {
Mockito.doThrow(new CloudRuntimeException("Communications link failure")).when(statsCollector).cleanUpVolumeStats();
| class VmStatsCleaner extends ManagedContextRunnable{ | ||
| protected void runInContext() { |
| } | ||
|
|
||
| @Test | ||
| public void vmStatsCleanerTestCatchesCloudRuntimeExceptionAndKeepsRunning() { |
|



Description
This PR...
Fixes: #13648
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?