-
Notifications
You must be signed in to change notification settings - Fork 365
Description
Thanks for submitting an issue to cloud_controller_ng
. We are always trying to improve! To help us, please fill out the following template.
Issue
When paging through /v3/roles
, users have found inconsistencies in the results returned.
Context
The v3 roles endpoint is backed by a join across several tables, so the default pagination behavior of falling back on the id
doesn't paginate consistently as id
s can be duplicated.
Another thing to consider is that CC only stores timestamps to the second, so if roles are created within the same second ordering by created_ats
may result in inconsistent ordering as well. This is unavoidable unless CC starts storing more granular timestamps, but we should be aware of this edge case when considering solutions.
From Felisia Martini: I think we saw a similar issue happening for service credential bindings during development. That is also an endpoint that joins two tables and the default pagination by id (which was also overriding the user defined order by) is not good enough because the same id will exist in several tables. We did however rely on created_at
as a more deterministic ordering parameter, but looking at this issue that might have been just a temporary fix. Anyways, this is what we did: 309e311 and the different binding tables are joined in a View in this case. Also, when checking SQL statement we noticed that any ordering applied in the view will be overriden by the paginator order_by
later.
Steps to Reproduce
- Create a foundation with more than a given
per_page
query param - Query for pages of roles, note that the results on each page are not consistent and may contain duplicates
for the created_ats
concern:
- Create multiple roles within the same second
- See that the ordering of those roles in results is inconsistent
Expected result
Consistent default pagination order (when not using an order_by
query parameter) for the /v3/roles
endpoint
Current result
The intent that surfaced this bug was to compile a complete list of all the roles, but inconsistent ordering inhibits that list creation. For example if two roles are created within the same second, when curling page 1 role A may be on page 1 and role B on page 2, but when curling page 2 entry A and B may swap order and role A would be seen again on page 2. The result being role A would appear twice in the compiled list, and role B wouldn't appear at all.
Results come back in varying order, the following are two separate runs of a script against the same CAPI:
cf curl /v3/roles?order_by=%2Bcreated_at&page=1&per_page=3
Number of pages 8
Number of results 23
cf curl /v3/roles?order_by=%2Bcreated_at&page=2&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=3&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=4&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=5&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=6&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=7&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=8&per_page=3
Total roles 23
Unique roles 22
cf curl /v3/roles?order_by=%2Bcreated_at&page=1&per_page=3
Number of pages 8
Number of results 23
cf curl /v3/roles?order_by=%2Bcreated_at&page=2&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=3&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=4&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=5&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=6&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=7&per_page=3
cf curl /v3/roles?order_by=%2Bcreated_at&page=8&per_page=3
Total roles 23
Unique roles 20
Possible Fix
As a first step we could consider implementing something along the lines of what was done for service credential bindings. This doesn't address the issue of having multiple entries with the same created_ats
timestamps, but at least should reduce some volatility. We could also explore other ways to order, by guid
or some other field that is consistently unique.