-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
ISSUE TYPE
- Bug Report
COMPONENT NAME
API
CLOUDSTACK VERSION
4.13
4.14
CONFIGURATION
N/A
OS / ENVIRONMENT
N/A
SUMMARY
The count in listUsageRecords reponse is wrong; it is equal to the number of usage records in the returned set (a single page), and not the total amount of usage records for a given request.
This is a regression due to #3235 (specifically c0295ad).
STEPS TO REPRODUCE
Query the listUsageRecords API, and look at the field "count".
EXPECTED RESULTS
count is expected to be the total number of usage records with the specified filter.
This is the behaviour for the other CloudStack API commands; a recent fix (#3894) was done to align with this behaviour, following issue #3890.
With the wrong count value, an API user does not know if there's other pages in the result set.
Actually, the same bug was already fixed back in 2013 with commit 78b1ac4.
ACTUAL RESULTS
$ cmk list usageRecords startdate=2020-07-01 enddate=2020-07-01 pagesize=10 page=1 | jq ".count"
10
Additional issue
In the PR causing the issue (#3235), usage records of IP addresses on shared networks flagged "Hide IP address usage" were filtered out after the search. I guess that's why the count value was updated. However, it also mean that the number of returned results in a page is not always equal to the pagesize parameter.
E.g.:
$ cmk list usageRecords startdate=2020-07-01 enddate=2020-07-01 type=3 pagesize=10 page=25 | jq ".count"
6
$ cmk list usageRecords startdate=2020-07-01 enddate=2020-07-01 type=3 pagesize=10 page=26 | jq ".count"
4
$ cmk list usageRecords startdate=2020-07-01 enddate=2020-07-01 type=3 pagesize=10 page=27
Here, 4 usage records were filtered on page 25.
It is even possible to have all usages records filtered out on a page, which means that the result will be:
{"listusagerecordsresponse":{}}A page with all usage records filtered out is indistinguishable from a non-existing page (e.g. page 27 above), so there's absolutely no way to know how many pages must be fetched.