guard against stopping stats background threads#13659
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 4.20 #13659 +/- ##
=========================================
Coverage 16.26% 16.27%
- Complexity 13435 13437 +2
=========================================
Files 5667 5667
Lines 500731 500739 +8
Branches 60803 60803
=========================================
+ Hits 81430 81478 +48
+ Misses 410197 410155 -42
- Partials 9104 9106 +2
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();
Co-authored-by: dahn <daan.hoogland@gmail.com>
|
|
@blueorangutan package |
|
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18666 |
|
@DaanHoogland why does it say that you modified every single line from |
It is a glitch, I saw co-pilot’s comment having the same and (apart from not want exactly the same as the bot) tried to do it myself. It looked good before applying the suggestion. This strange view only appeared after I applied my version of the change. original suggestion: #13659 (comment) I blame github ;) |



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?