Skip to content
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

Merged
merged 3 commits into from
Dec 17, 2019

Conversation

timoreimann
Copy link
Contributor

@timoreimann timoreimann commented Dec 10, 2019

This change implements paging uses the Meta.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.

Copy link
Contributor

@adamwg adamwg left a 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.

@adamwg
Copy link
Contributor

adamwg commented Dec 10, 2019

Also wanted to note: the volumes API in particular also returns a meta field in the response, which explicitly says the total number of volumes the account has:

  "meta": {
    "total": 8316
  },

I think godo ignores this, but we could integrate it into godo and leverage it here rather than relying on the pagination data.

@jcodybaker
Copy link
Collaborator

Reviewed. No concerns other than those already raised by AWG.

@timoreimann
Copy link
Contributor Author

timoreimann commented Dec 10, 2019

@adamwg I like the idea to use the page count in order to determine the number of volumes until the meta field is available in godo.

Looking more closely at things, however, it looks like the number of pages isn't directly available in godo but only through the Last reference which seems to be a URL. The functionality godo uses to parse page numbers from the links seems non-exported.

I'd rather not implement / copy the parsing logic in(to) our repo, which makes an upstream contribution to godo exposing the meta field more desirable to me right now. But please let me know if I missed something.

(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.)

@timoreimann
Copy link
Contributor Author

Submitted digitalocean/godo#286.

@timoreimann timoreimann force-pushed the support-checklimit-for-multiple-pages branch from 750cbbf to 5522c0f Compare December 16, 2019 17:28
@timoreimann
Copy link
Contributor Author

my godo contribution was merged and released. This PR is now using godo 1.29.0 and leverages the Meta.Total field.

@adamwg @jcodybaker would you mind taking a look again when you have a minute?

Copy link
Contributor

@adamwg adamwg left a comment

Choose a reason for hiding this comment

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

lgtm.

Copy link
Collaborator

@jcodybaker jcodybaker left a 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?

Timo Reimann added 3 commits December 17, 2019 01:24
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.
@timoreimann timoreimann force-pushed the support-checklimit-for-multiple-pages branch from 5522c0f to 2ee5ac0 Compare December 17, 2019 00:24
@timoreimann
Copy link
Contributor Author

@jcodybaker

Have you verified that list volumes honors and correctly implements the per-page=1 option?

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
}

@jcodybaker
Copy link
Collaborator

Nice :shipit:

@timoreimann timoreimann merged commit dac7b9a into master Dec 17, 2019
@timoreimann timoreimann deleted the support-checklimit-for-multiple-pages branch December 17, 2019 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants