Skip to content

guard against stopping stats background threads#13659

Open
DaanHoogland wants to merge 2 commits into
4.20from
ghi13648-guardWorkerThreadForStats
Open

guard against stopping stats background threads#13659
DaanHoogland wants to merge 2 commits into
4.20from
ghi13648-guardWorkerThreadForStats

Conversation

@DaanHoogland

@DaanHoogland DaanHoogland commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Description

This PR...

Fixes: #13648

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.26%. Comparing base (e8df87e) to head (ce7a866).

Files with missing lines Patch % Lines
...src/main/java/com/cloud/server/StatsCollector.java 60.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.20   #13659   +/-   ##
=========================================
  Coverage     16.26%   16.26%           
- Complexity    13435    13436    +1     
=========================================
  Files          5667     5667           
  Lines        500731   500739    +8     
  Branches      60803    60803           
=========================================
+ Hits          81430    81458   +28     
+ Misses       410197   410174   -23     
- Partials       9104     9107    +3     
Flag Coverage Δ
uitests 4.14% <ø> (ø)
unittests 17.12% <60.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vishesh92 vishesh92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm. didn't test

@sonarqubecloud

Copy link
Copy Markdown

@DaanHoogland DaanHoogland changed the title guard against stopping stats background threats guard against stopping stats background threads Jul 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 VmStatsCleaner and VolumeStatsCleaner cleanup 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.

Comment on lines +1289 to +1293
try {
cleanUpVirtualMachineStats();
} catch (CloudRuntimeException e) {
logger.error("Error trying to clean up VM stats", e);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try {
cleanUpVirtualMachineStats();
} catch (CloudRuntimeException e) {
logger.error("Error trying to clean up VM stats", e);
}
try {
cleanUpVirtualMachineStats();
} catch (RuntimeException e) {
logger.error("Error trying to clean up VM stats", e);
}

at best!

Comment on lines +1299 to +1303
try {
cleanUpVolumeStats();
} catch (CloudRuntimeException e) {
logger.error("Error trying to clean up Volume stats", e);
}
Comment thread server/src/test/java/com/cloud/server/StatsCollectorTest.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants