Skip to content

Conversation

@winterhazel
Copy link
Member

@winterhazel winterhazel commented Dec 18, 2025

Description

This PR fixes a regression in commit c8d44d9 that prevents non-admin accounts from listing the metrics of VMs and volumes that belong to a project (see #12237).

Previously, the following example condition was used in the listVirtualMachinesMetrics API in order to find VMs that could have their metrics listed by a user:

vm_instance.type='User' AND user_vm.id=88 AND vm_instance.removed IS NULL

In 4.20.2 and 4.22.0, the condition also restricts the result to VMs that belong to the calling account; hence, VMs that belong to a project are not returned:

WHERE vm_instance.type='User' AND vm_instance.account_id=6 AND user_vm.id=88 AND vm_instance.removed IS NULL

With this patch, the ID of projects that the user has access to is also included in the condition:

WHERE vm_instance.type='User' AND vm_instance.account_id IN (11,6)  AND user_vm.id=88 AND vm_instance.removed IS NULL

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

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

I manually verified that, using both the id and ids parameters:

  • Root admins can access the metrics of VMs/volumes belonging to other users and projects
  • Domain admins can access the metrics of VMs/volumes belonging to users and projects of their domain
  • Users can access the metrics of VMs/volumes belonging to them and to projects they have access to

@winterhazel
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@winterhazel 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 Dec 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 16.23%. Comparing base (ba26d95) to head (67c5241).
⚠️ Report is 1 commits behind head on 4.20.

Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #12284      +/-   ##
============================================
+ Coverage     16.22%   16.23%   +0.01%     
- Complexity    13358    13379      +21     
============================================
  Files          5657     5657              
  Lines        498692   498865     +173     
  Branches      60530    60545      +15     
============================================
+ Hits          80932    81011      +79     
- Misses       408738   408820      +82     
- Partials       9022     9034      +12     
Flag Coverage Δ
uitests 4.00% <ø> (ø)
unittests 17.09% <100.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.

@blueorangutan
Copy link

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

Copy link
Contributor

@kiranchavala kiranchavala left a comment

Choose a reason for hiding this comment

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

LGTM

  1. Created a user in a domain
  2. Login, as the user and Create a project
  3. Deploy a vm in the project and check the metrics tab

Before fix

the API listVirtualMachinesUsageHistory has no response

Screenshot 2025-12-18 at 4 02 27 PM

After fix

the API listVirtualMachinesUsageHistory has response

Screenshot 2025-12-18 at 4 53 35 PM

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, one remark/question though; two bits of code are repeated with a similar statement in between, Can we create a method for it?

@winterhazel
Copy link
Member Author

@kiranchavala thanks for testing :]

@DaanHoogland yup, I will do some refactoring (and some extra tests to be sure) before marking it as ready.

@winterhazel winterhazel changed the title Fix VM and volume metrics listing regression Fix VM and volume metrics listing regressions Dec 18, 2025
@winterhazel winterhazel marked this pull request as ready for review December 18, 2025 20:11
@winterhazel
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@winterhazel 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 16090

@winterhazel
Copy link
Member Author

@DaanHoogland I extracted the code that builds the parameters to a method. Tests are also ok.

I noticed that there was another regression in which admins were not able to list the metrics of VMs/volumes belonging to projects via the ids parameter. It should be fixed now too.

Example
<before>
(admin) 🐢 > list virtualmachinesusagehistory id=69ecb2a6-dc91-46b9-a5d9-06e8222c5084
{
  "count": 1,
  "virtualmachine": [
    {
      "displayname": "k",
      "id": "69ecb2a6-dc91-46b9-a5d9-06e8222c5084",
      "name": "i-2-88-VM",
      "stats": [
        {
          "cpuused": "0%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:21:54+0000"
        },
        {
          "cpuused": "20.77%",
          "diskiopstotal": 835,
          "diskioread": 640,
          "diskiowrite": 195,
          "diskkbsread": 10876,
          "diskkbswrite": 1612,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 2,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:22:54+0000"
        },
        {
          "cpuused": "13.52%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:23:54+0000"
        }
      ]
    }
  ]
}

(admin) 🐢 > list virtualmachinesusagehistory ids=69ecb2a6-dc91-46b9-a5d9-06e8222c5084
<empty>

<with the patch>
(admin) 🐢 > list virtualmachinesusagehistory ids=69ecb2a6-dc91-46b9-a5d9-06e8222c5084
{
  "count": 1,
  "virtualmachine": [
    {
      "displayname": "k",
      "id": "69ecb2a6-dc91-46b9-a5d9-06e8222c5084",
      "name": "i-2-88-VM",
      "stats": [
        {
          "cpuused": "0%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:21:54+0000"
        },
        {
          "cpuused": "20.77%",
          "diskiopstotal": 835,
          "diskioread": 640,
          "diskiowrite": 195,
          "diskkbsread": 10876,
          "diskkbswrite": 1612,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 2,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:22:54+0000"
        },
        {
          "cpuused": "13.52%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:23:54+0000"
        },
        {
          "cpuused": "60.96%",
          "diskiopstotal": 1116,
          "diskioread": 902,
          "diskiowrite": 214,
          "diskkbsread": 67400,
          "diskkbswrite": 2040,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:24:55+0000"
        },
        {
          "cpuused": "40.05%",
          "diskiopstotal": 277,
          "diskioread": 110,
          "diskiowrite": 167,
          "diskkbsread": 13304,
          "diskkbswrite": 38524,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:25:56+0000"
        },
        {
          "cpuused": "26.1%",
          "diskiopstotal": 3,
          "diskioread": 0,
          "diskiowrite": 3,
          "diskkbsread": 0,
          "diskkbswrite": 16,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:26:58+0000"
        },
        {
          "cpuused": "25.4%",
          "diskiopstotal": 1,
          "diskioread": 0,
          "diskiowrite": 1,
          "diskkbsread": 0,
          "diskkbswrite": 4,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:27:59+0000"
        },
        {
          "cpuused": "24.83%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:29:02+0000"
        },
        {
          "cpuused": "24.91%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:30:04+0000"
        },
        {
          "cpuused": "25.87%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:31:09+0000"
        },
        {
          "cpuused": "25.24%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:32:11+0000"
        },
        {
          "cpuused": "20.79%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:33:12+0000"
        },
        {
          "cpuused": "6.03%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:34:13+0000"
        },
        {
          "cpuused": "5.77%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:35:13+0000"
        },
        {
          "cpuused": "5.78%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:36:13+0000"
        },
        {
          "cpuused": "7.01%",
          "diskiopstotal": 158,
          "diskioread": 103,
          "diskiowrite": 55,
          "diskkbsread": 412,
          "diskkbswrite": 472,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:37:13+0000"
        },
        {
          "cpuused": "8.05%",
          "diskiopstotal": 3,
          "diskioread": 0,
          "diskiowrite": 3,
          "diskkbsread": 0,
          "diskkbswrite": 16,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:38:14+0000"
        },
        {
          "cpuused": "8.79%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:39:14+0000"
        },
        {
          "cpuused": "6.4%",
          "diskiopstotal": 0,
          "diskioread": 0,
          "diskiowrite": 0,
          "diskkbsread": 0,
          "diskkbswrite": 0,
          "memoryintfreekbs": 353728,
          "memorykbs": 524288,
          "memorytargetkbs": 524288,
          "networkkbsread": 0,
          "networkkbswrite": 0,
          "networkread": "0.00 MiB",
          "networkwrite": "0.00 MiB",
          "timestamp": "2025-12-18T19:40:14+0000"
        }
      ]
    }
  ]
}

Also, passing the ids parameter to listVolumesUsageHistory was throwing an exception. I took the opportunity to fix this here as well.

@winterhazel
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@winterhazel 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 16091

@winterhazel
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@winterhazel 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 16092

@DaanHoogland
Copy link
Contributor

Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 16092

we hit the github API limit @winterhazel , don’t worry about this.


// If no ID was provided, then the listing will skip project resources (null); otherwise, project resources should
// be listed as well (any long allows this)
Long id = isIdProvided ? 1L : null;
Copy link
Member

Choose a reason for hiding this comment

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

is there side-effect when id is set to 1L ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The value itself is not used, com.cloud.user.AccountManagerImpl#buildACLSearchParameters just checks whether the ID is null in order to decide whether project resources should be skipped or not, so no.

if (id == null) {
domainIdRecursiveListProject.third(Project.ListProjectResourcesCriteria.SkipProjectResources);
}

@blueorangutan
Copy link

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

@DaanHoogland
Copy link
Contributor

@blueorangutan test

@blueorangutan
Copy link

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

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.

5 participants