Skip to content

Conversation

@sureshanaparti
Copy link
Contributor

@sureshanaparti sureshanaparti commented Jan 28, 2026

Description

This PR updates storage usage / size in backup usage response.

Fixes #12536

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?

@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@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.

@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.26%. Comparing base (35e6d7c) to head (fea7fa4).
⚠️ Report is 16 commits behind head on 4.20.

Files with missing lines Patch % Lines
...src/main/java/com/cloud/api/ApiResponseHelper.java 0.00% 5 Missing ⚠️
...java/com/cloud/usage/parser/BackupUsageParser.java 0.00% 1 Missing ⚠️
.../cloud/usage/parser/VMSnapshotOnPrimaryParser.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               4.20   #12539    +/-   ##
==========================================
  Coverage     16.26%   16.26%            
- Complexity    13418    13428    +10     
==========================================
  Files          5658     5660     +2     
  Lines        499494   499921   +427     
  Branches      60625    60698    +73     
==========================================
+ Hits          81232    81320    +88     
- Misses       409214   409529   +315     
- Partials       9048     9072    +24     
Flag Coverage Δ
uitests 4.16% <ø> (+0.13%) ⬆️
unittests 17.11% <0.00%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

Copilot AI left a comment

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 enhances the backup usage response to include storage size information that was previously stored but not exposed through the API.

Changes:

  • Removed unused rawUsage variable from BackupUsageParser
  • Modernized Double instantiation to use primitive casting in BackupUsageParser and VMSnapshotOnPrimaryParser
  • Added size and virtualSize fields to backup usage API response

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
usage/src/main/java/com/cloud/usage/parser/BackupUsageParser.java Removed unused variable and modernized Double casting for better code quality
usage/src/main/java/com/cloud/usage/parser/VMSnapshotOnPrimaryParser.java Modernized Double casting from new Double(usage) to (double) usage
server/src/main/java/com/cloud/api/ApiResponseHelper.java Added setSize() and setVirtualSize() calls to populate backup storage metrics in usage response

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@RosiKyu RosiKyu self-assigned this Jan 28, 2026
@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16596

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

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

clgtm

Copy link
Collaborator

@abh1sar abh1sar left a comment

Choose a reason for hiding this comment

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

Need to fix the print statement in createUsageResponse

        } else if (usageRecord.getUsageType() == UsageTypes.BACKUP) {
            resourceType = ResourceObjectType.Backup;
            final StringBuilder builder = new StringBuilder();
            builder.append("Backup usage of size ").append(usageRecord.getUsageDisplay());
            if (vmInstance != null) {
                resourceId = vmInstance.getId();
                usageRecResponse.setResourceName(vmInstance.getInstanceName());
                usageRecResponse.setUsageId(vmInstance.getUuid());
                builder.append(" for VM ").append(vmInstance.getHostName())
                        .append(" (").append(vmInstance.getUuid()).append(")");
                final BackupOffering backupOffering = backupOfferingDao.findByIdIncludingRemoved(usageRecord.getOfferingId());
                if (backupOffering != null) {
                    builder.append(" and backup offering ").append(backupOffering.getName())
                            .append(" (").append(backupOffering.getUuid()).append(", user ad-hoc/scheduled backup allowed: ")
                            .append(backupOffering.isUserDrivenBackupAllowed()).append(")");
                }

            }

Is should say something like

Backup usage for VM .. and backup offering ... with size (usageRecord.getSize()

Currently it shows

Image

Snapshot usage for reference

Image

@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@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.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16625

@sureshanaparti
Copy link
Contributor Author

@blueorangutan test

@blueorangutan
Copy link

@sureshanaparti a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

Copy link
Collaborator

@RosiKyu RosiKyu left a comment

Choose a reason for hiding this comment

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

LGTM - Tested the fix for backup usage API response. The size and virtualsize fields are now correctly included in the listUsageRecords API response for usage type 28 (Backup), along with an updated description format showing both size and virtual size with human-readable formatting.

Test Environment

  • CloudStack Version: 4.20.3.0-SNAPSHOT
  • Backup Provider: Dummy plugin
  • Usage aggregation interval: 15 minutes

Test Setup

  • Created VM with backup offering assigned
  • Created backup for the VM
  • Waited for usage aggregation to process backup usage events

API Response Verification

{
  "account": "admin",
  "accountid": "61127bf6-fd41-11f0-98c7-1e00370002e0",
  "description": "Backup usage for VM backup-test-vm (8367f058-03de-4d85-9250-2d4ac1ca5f66) and backup offering test (bcc29bb8-b727-4fc1-abbe-e3a3d7899d69, user ad-hoc/scheduled backup allowed: true) with size (1000 bytes) 1000 and with virtual size (100 bytes) 100",
  "domain": "ROOT",
  "domainid": "1db1a70d-fd41-11f0-98c7-1e00370002e0",
  "domainpath": "/",
  "enddate": "2026-01-30T12:16:59+0000",
  "name": "i-2-3-VM",
  "rawusage": "0.25",
  "size": 1000,
  "startdate": "2026-01-30T12:02:00+0000",
  "tags": [],
  "usage": "0.25 Hrs",
  "usageid": "8367f058-03de-4d85-9250-2d4ac1ca5f66",
  "usagetype": 28,
  "virtualmachineid": "8367f058-03de-4d85-9250-2d4ac1ca5f66",
  "virtualsize": 100,
  "zoneid": "bdb1d48b-6c33-4484-882c-a0b61d4887c9"
}

Results

Test Result
size field in API response PASS - 1000
virtualsize field in API response PASS - 100
Description includes size PASS - "with size (1000 bytes) 1000"
Description includes virtual size PASS - "and with virtual size (100 bytes) 100"
rawusage still represents hours PASS - 0.25 Hrs

Database Verification

mysql> SELECT id, size, virtual_size FROM cloud_usage.cloud_usage WHERE usage_type=28 ORDER BY id DESC LIMIT 2;
+----+------+--------------+
| id | size | virtual_size |
+----+------+--------------+
| 50 | 1000 |          100 |
| 41 |    0 |            0 |
+----+------+--------------+

Test Result: PASS

@borisstoyanov
Copy link
Contributor

@sureshanaparti can you check @abh1sar 's comments and we can merge this

@sureshanaparti
Copy link
Contributor Author

@sureshanaparti can you check @abh1sar 's comments and we can merge this

done @borisstoyanov

@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@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.

@abh1sar
Copy link
Collaborator

abh1sar commented Jan 30, 2026

@sureshanaparti can you please test, what are the displayed values for size and virtual size. If they are correct?

@blueorangutan
Copy link

[SF] Trillian test result (tid-15339)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 55977 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12539-t15339-kvm-ol8.zip
Smoke tests completed. 140 look OK, 1 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_05_vmschedule_test_e2e Failure 361.92 test_vm_schedule.py

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16649

@RosiKyu
Copy link
Collaborator

RosiKyu commented Jan 30, 2026

@abh1sar , tested with the last changes. The size and virtualsize fields are now correctly included in the listUsageRecords API response for usage type 28 (Backup), along with an updated description format showing both size values.

API Response Verification

  • Created VM with backup offering assigned
  • Created backup for the VM
  • Waited for usage aggregation to process backup usage events
(localcloud) 🐱 > listUsageRecords usagetype=28 startdate=2026-01-30 enddate=2026-01-31 account=admin | python3 -c "import sys,json; d=json.load(sys.stdin); print(json.dumps([r for r in d.get('usagerecord',[]) if r.get('usagetype')==28][-1], indent=2))"
{
  "account": "admin",
  "accountid": "61127bf6-fd41-11f0-98c7-1e00370002e0",
  "description": "Backup usage for VM backup-test-vm (8367f058-03de-4d85-9250-2d4ac1ca5f66) and backup offering test (bcc29bb8-b727-4fc1-abbe-e3a3d7899d69, user ad-hoc/scheduled backup allowed: true) with size (1000 bytes) 1000 and with virtual size (100 bytes) 100",
  "domain": "ROOT",
  "domainid": "1db1a70d-fd41-11f0-98c7-1e00370002e0",
  "domainpath": "/",
  "enddate": "2026-01-30T12:16:59+0000",
  "name": "i-2-3-VM",
  "rawusage": "0.25",
  "size": 1000,
  "startdate": "2026-01-30T12:02:00+0000",
  "tags": [],
  "usage": "0.25 Hrs",
  "usageid": "8367f058-03de-4d85-9250-2d4ac1ca5f66",
  "usagetype": 28,
  "virtualmachineid": "8367f058-03de-4d85-9250-2d4ac1ca5f66",
  "virtualsize": 100,
  "zoneid": "bdb1d48b-6c33-4484-882c-a0b61d4887c9"
}

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.

listUsageRecords for backup usage (type 28) isn't returning the backup storage usage

6 participants