olivierlemasle opened a new issue #4191:
URL: https://github.com/apache/cloudstack/issues/4191
##### 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
https://github.com/apache/cloudstack/pull/3235/commits/c0295ad20e19a2ddb0bfb7470220fbba17f41115).
##### 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
78b1ac4126aa1d.
##### 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:
```json
{"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.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]