Skip to content

Conversation

abh1sar
Copy link
Collaborator

@abh1sar abh1sar commented Aug 29, 2025

Description

This PR fixes #10985

Some users have asked to show the virtualmachineid also in volume usage, to track it per instance.

There will be two kinds of records now.

  • Without the virtualmachineid - tracking the cumulative volume usage in the usage window. This is to be consistent with the current behaviour.
  • With virtualmachineid - tracking the volume usage for the time it was attached to the vm in the usage window.

If the volume was attached to multiple instances in the same usage window, we will have separate entries for each VM.

Schema changes

  • Add column vm_id to cloud.usage_event and cloud_usage.usage_event
  • Add column vm_id to cloud_usage.usage_volume

I have also done some code refactoring in createVolumeHelperEvent() to make it easier to follow.

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):

listUsageRecords for a volume in a 2 minute (0.033333 hours) window.
The volume was created, then attached to VM-00a42c28-74ae-4а0c-b38a-4e3b88f11241. It was then detached and attached to another VM QA-d6df4657-2fb4-4e26-b7de-21743c5463cd. So we have 3 records.

Screenshot 2025-08-29 at 2 42 20 AM

How Has This Been Tested?

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

@abh1sar
Copy link
Collaborator Author

abh1sar commented Aug 29, 2025

@blueorangutan package

@blueorangutan
Copy link

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

Copy link

codecov bot commented Aug 29, 2025

Codecov Report

❌ Patch coverage is 2.89017% with 168 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.50%. Comparing base (cd12fa5) to head (acef620).

Files with missing lines Patch % Lines
...rc/main/java/com/cloud/usage/UsageManagerImpl.java 0.00% 82 Missing ⚠️
...n/java/com/cloud/usage/dao/UsageVolumeDaoImpl.java 0.00% 20 Missing ⚠️
...ma/src/main/java/com/cloud/event/UsageEventVO.java 0.00% 17 Missing ⚠️
...java/com/cloud/usage/parser/VolumeUsageParser.java 0.00% 13 Missing ⚠️
...src/main/java/com/cloud/event/UsageEventUtils.java 0.00% 8 Missing ⚠️
...a/src/main/java/com/cloud/usage/UsageVolumeVO.java 0.00% 8 Missing ⚠️
...n/java/com/cloud/storage/VolumeApiServiceImpl.java 22.22% 7 Missing ⚠️
...er/src/main/java/com/cloud/hypervisor/KVMGuru.java 0.00% 4 Missing ⚠️
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 40.00% 3 Missing ⚠️
...stack/engine/orchestration/VolumeOrchestrator.java 0.00% 2 Missing ⚠️
... and 3 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #11531      +/-   ##
============================================
- Coverage     17.50%   17.50%   -0.01%     
  Complexity    15425    15425              
============================================
  Files          5894     5894              
  Lines        526877   526937      +60     
  Branches      64337    64341       +4     
============================================
+ Hits          92232    92233       +1     
- Misses       424269   424327      +58     
- Partials      10376    10377       +1     
Flag Coverage Δ
uitests 3.61% <ø> (ø)
unittests 18.56% <2.89%> (-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.

public UsageVolumeDaoImpl() {
}

@Override
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This kind of update method is not required since #5785 added auto-increment primary keys. We can directly use the GenericDao.update()

if (volumesVOs.size() > 0) {
//This is a safeguard to avoid double counting of volumes.
s_logger.error("Found duplicate usage entry for volume: " + volId + " assigned to account: " + event.getAccountId() + "; marking as deleted...");
if (event.getVmId() != null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

VOLUME_CREATE event will contain the vmId also when it is created during Instance deployment. Need to add a vm specific entry also in that case.

@blueorangutan
Copy link

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

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.

looks good, except for the upgrade path (and needs testing)

@sudo87
Copy link
Collaborator

sudo87 commented Aug 29, 2025

clgtm

@DaanHoogland
Copy link
Contributor

code looks good in isolation @abh1sar , but I see some bears on the road: what if someone upgrades from 20.1 to 21 and then on to 22; How do we guarantee they get the DB updates?
It may be wiser to put this in version 22.

Sorry, I overlooked this when I asked you to rebase earlier.

@weizhouapache weizhouapache added this to the 4.22.0 milestone Sep 1, 2025
@abh1sar abh1sar changed the base branch from 4.20 to main September 9, 2025 11:05
@abh1sar abh1sar closed this Sep 9, 2025
@abh1sar abh1sar reopened this Sep 9, 2025
@abh1sar
Copy link
Collaborator Author

abh1sar commented Sep 30, 2025

@blueorangutan package

@blueorangutan
Copy link

@abh1sar 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 ✔️ debian ✖️ suse15. SL-JID 15238

@abh1sar
Copy link
Collaborator Author

abh1sar commented Sep 30, 2025

@blueorangutan package

@blueorangutan
Copy link

@abh1sar 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 15241

@vishesh92
Copy link
Member

@blueorangutan test keepEnv

@apache apache deleted a comment from blueorangutan Oct 1, 2025
@apache apache deleted a comment from blueorangutan Oct 1, 2025
@blueorangutan
Copy link

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

Copy link
Member

@vishesh92 vishesh92 left a comment

Choose a reason for hiding this comment

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

code lgtm

@abh1sar
Copy link
Collaborator Author

abh1sar commented Oct 1, 2025

@blueorangutan package

@blueorangutan
Copy link

@abh1sar 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 15249

Copy link

github-actions bot commented Oct 1, 2025

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@abh1sar
Copy link
Collaborator Author

abh1sar commented Oct 1, 2025

@blueorangutan package

@blueorangutan
Copy link

@abh1sar 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 15257

@blueorangutan
Copy link

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

Test Result Time (s) Test File
test_02_upgrade_kubernetes_cluster Failure 334.74 test_kubernetes_clusters.py

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.

[cloud_usage] vm_instance_id is null for volume usage (usage_type = 6)
6 participants