-
Notifications
You must be signed in to change notification settings - Fork 23
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
added rate limit with exponential backoff and retry #286
Conversation
…r range notaion to a less ambiguous style
…o avoid hitting unauthenticated ratelimit (60/hour) on github
…s api, raw, and frontend
… api when testing
.gitignore
Outdated
@@ -9,3 +9,5 @@ | |||
|
|||
docs/_build | |||
docs/apidocs | |||
|
|||
secrets.yml |
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.
secrets.yml |
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.
done in upcoming commit
github_apikey_is_invalid = apikeys is not None and (apikeys.get("github-key") is None or | ||
apikeys.get("github-user") is None) | ||
|
||
if apikeys is None or github_apikey_is_invalid: |
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.
github_apikey_is_invalid = apikeys is not None and (apikeys.get("github-key") is None or | |
apikeys.get("github-user") is None) | |
if apikeys is None or github_apikey_is_invalid: | |
if apikeys is None or apikeys.get("github-key") is None or apikeys.get("github-user") is None: |
|
||
def get_from_gitlab(url, url_type, apikeys=None): | ||
|
||
if apikeys is None: |
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.
This code is much shorter than the equivalent code for github. Is it complete?
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.
fixed it same as github now
def get_from_gitlab_with_auth_api(url, apikeys): | ||
|
||
headers = { | ||
"Accept": "application/vnd.github.v3+json" |
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.
Probably github here should be changed
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.
changed to only json, also added headers to equivalent noauth gitlab case.
setup.py
Outdated
"ruamel.yaml == 0.16.*", | ||
"requests == 2.*", |
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.
these two lines are not in alphabetical order
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.
fixed it
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 went through the code and added some minor comments. Well done!
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.
Awesome sos! 🍜
A few suggestions which we should create issues about:
- We need to update the documentation to reflect this work.
- It is a good idea to raise some exceptions, e.g. when the authentication fails.
- If for some reason we cannot use authenticantion and use unathenticated method, we should warn the user.
- Number of calls are hardcoded. We can consider making them configurable.
Co-authored-by: Erik Tjong Kim Sang <[email protected]>
…airis into 93-rate-limit
Spawned
the remaining bullet point from #286 (review) is covered by #298 |
SonarCloud Quality Gate failed. |
Describe the changes made in this pull request
Added rate limit with exponential backoff and retry. Refs GitHub API rate limiting #93
Removed sleep from livetests and clitests
AddedNow reading from env vars-a
and--apikeys-filename
to cli. Refs add -a | --apikeys-filename option to have higher rate limit #263the functions with which to interact with github, gitlab, etc are in
requesting
and are organized as follows:This gives the developer control over the level at which to use the rate limiting decorators, for example different rates apply for each platform, a given platform may have different rate limits for unauthenticated/authenticated, as well as different rates for different parts of their service.
Instructions to review the pull request
Try running the unit tests
Now replace
get_calls()
in the decorator inrequesting/get_from_github_no_auth.py
with 60. Running the tests again will halt halfway through because of rate limits. It will continue very slowly due to exponential backoff and retry, but the retries happen too slow for the ratelimit of 60 per hour, therefore they all ultimately fail with a too-many-calls error.cli now has a-a | --apikeys-filename
option that can be used to point to a secrets file with api keysApikeys are read from env vars named
APIKEY_GITHUB
andAPIKEY_GITLAB,
e.g.:source secrets.txt howfairis https://github.com/fair-software/howfairis
Open questions / problems
How to bypass the ratelimit decorators when using mocksfixed it, but hides the next point aboutRepo
No longer needed now that we're reading from env varsRepo
might need to be extended withapikeys
arg as well, since it's making a request toraw
.Repo
withinChecker.__init__
?Checker
's constructor would then need additional argumentsurl
,branch
andpath
, and could droprepo
.raw
seems to have its own limits, not covered by api key increased rate limit.