server: fix NaN metrics for external resources#11302
server: fix NaN metrics for external resources#11302sureshanaparti merged 1 commit intoapache:mainfrom
Conversation
CPU and RAM values for external resource metrics was showing NaN values. This fixes the behaviour. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2437763 to
913655f
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11302 +/- ##
=========================================
Coverage 16.99% 16.99%
- Complexity 14715 14718 +3
=========================================
Files 5832 5832
Lines 517561 517562 +1
Branches 62982 62982
=========================================
+ Hits 87975 87984 +9
+ Misses 419651 419643 -8
Partials 9935 9935
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@blueorangutan package |
|
@sureshanaparti 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. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes NaN (Not a Number) values appearing in CPU and RAM metrics for external resources by adding zero-value checks before performing division operations. The fix prevents division by zero scenarios that were causing the NaN values to appear in the UI.
Key changes:
- Added a null/zero check in the
calculateResourceAllocatedPercentagemethod to return "0.00%" when either the resource or resourceWithOverProvision values are zero - Refactored existing inline percentage calculation to use the centralized
calculateResourceAllocatedPercentagemethod for consistency
| return "0.00%"; | ||
| } | ||
| DecimalFormat decimalFormat = new DecimalFormat("#.##"); | ||
| return decimalFormat.format(((float)resource / resourceWithOverProvision * 100.0f)) + "%"; |
There was a problem hiding this comment.
The cast to (float) is unnecessary since the parameters are already declared as float. This redundant cast reduces code readability.
| return decimalFormat.format(((float)resource / resourceWithOverProvision * 100.0f)) + "%"; | |
| return decimalFormat.format((resource / resourceWithOverProvision * 100.0f)) + "%"; |
There was a problem hiding this comment.
Can be a separate PR/change as not touched here
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 14408 |
DaanHoogland
left a comment
There was a problem hiding this comment.
I think both copilot’s remarks make sense. otherwise clgtm
@shwstppr can check if copilot's commits are relevant? |
|
@sureshanaparti I don't think Copilot's comment are completely relevant. I've added my comments in their reply |
CPU and RAM values for external resource metrics was showing NaN values. This fixes the behaviour. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>


Description
CPU and RAM values for external resource metrics was showing NaN values. This fixes the behaviour.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
Before:

After:

How Has This Been Tested?
How did you try to break this feature and the system with this change?