-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support checkLimit for multiple pages #235
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need to iterate over all the pages to figure out how many volumes/snaps the user has. In the Response
object, we get the number of total pages, and we can control the number of volumes per page. If we set PerPage
to 1, we can make a single API call and use the total number of pages returned as the volume count.
Also wanted to note: the volumes API in particular also returns a
I think godo ignores this, but we could integrate it into godo and leverage it here rather than relying on the pagination data. |
Reviewed. No concerns other than those already raised by AWG. |
@adamwg I like the idea to use the page count in order to determine the number of volumes until the Looking more closely at things, however, it looks like the number of pages isn't directly available in godo but only through the I'd rather not implement / copy the parsing logic in(to) our repo, which makes an upstream contribution to godo exposing the (FWIW, there's no super urge to get this PR in, so we can wait a bit for any godo PR to get merged and released.) |
Submitted digitalocean/godo#286. |
750cbbf
to
5522c0f
Compare
my godo contribution was merged and released. This PR is now using godo 1.29.0 and leverages the @adamwg @jcodybaker would you mind taking a look again when you have a minute? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Have you verified that list volumes honors and correctly implements the per-page=1 option?
This change implements paging when listing volumes for account limit checking, thereby supporting limits beyond the size of a single page. We also refactor checkLimits to not return gRPC codes but leave that to the calling function. This also allows us to distinguish between true errors and limit violations, and better handle each case.
Also update the fake response to return a meta field.
5522c0f
to
2ee5ac0
Compare
That does seem to be the case: $ curl -sfX GET -H "Content-Type: application/json" -H "Authorization: Bearer <REDACTED>" "https://api.digitalocean.com/v2/volumes?per_page=1" | jq '. | {meta: .meta, numVolumes: .volumes | length}'
{
"meta": {
"total": 14
},
"numVolumes": 1
} |
Nice |
This change
implements paginguses theMeta.Total
field from the godo response when listing volumes for account limit checking, thereby supporting limits beyond the size of a single page.We also refactor
checkLimits
to not return gRPC codes but leave that to the calling function. This also allows us to distinguish between true errors and limit violations, and better handle each case.