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

handle rate limiter & github server-side errors #63

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

mredolatti
Copy link

@mredolatti mredolatti commented May 24, 2019

Two issues were found while using this library:

  • Random and isolated 502 errors from github make the whole job fail.
  • If the number of API calls exceeds github's limit, the whole job fails.

To deal with these scenarios, simple retry logic was added, and in the case of a rate limiting situation, we wait until the next reset time to move forward with the next retry.

@cmerrick
Copy link
Contributor

Hi @mredolatti, thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes.

@cmerrick
Copy link
Contributor

You did it @mredolatti!

Thank you for signing the Singer Contribution License Agreement.

raise AuthException(resp.text)
if resp.status_code == 404:
raise NotFoundException(resp.text)
for _ in range(0, 3): # 3 attempts
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't this be replaced with the backoff library?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Hi @luandy64 i'm not familiar with that library, but i'll look into it as soon as possible and tidy up the PR.

Thanks and sorry for the delay!

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

I'll take a look at this tonight and see if I can put the branch up to speed

Choose a reason for hiding this comment

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

@luandy64 @osterman could it be that the backoff library doesn't provide an easy way to use headers like: X-RateLimit-Remaining, X-RateLimit-Reset to determine how long to back off: litl/backoff#38?

@nehiljain
Copy link

Are there plans to work on this? @osterman or @mredolatti ? I am having the same issue as well

@henriblancke
Copy link

@cmerrick @mredolatti any way we can help to get this over the line?

@osterman
Copy link

osterman commented Jul 7, 2020

@nehiljain Sorry - no resources available on outside to put towards it at this time

@KBorders01
Copy link

@osterman @mredolatti @luandy64, what needs to happen to merge this PR? It looks like the code that's there already is much better than the current code, which has no retry capability. Also, it doesn't look like backoff will handle the rate limit headers anyway.

This issue is blocking me from using Stitch's hosted Github tap, and instead I have to run it on my own.

@antoine-lizee
Copy link

Up! Can we merge this?

@savicbo
Copy link

savicbo commented May 1, 2022

@luandy64 can we merge this PR or is has it been implemented elsewhere? Hitting the GitHub ratelimit is affection our ability to use Stitch as well

@mredolatti
Copy link
Author

is this still an issue? i took a look at backoff a while ago and didn't see a straightforward way to use it while relying on the response's headers to actually wait the correct amount of time. Do we need to add that behavior into backoff first and then update this?

@bgreen-litl
Copy link

@mredolatti latest backoff (2.0.1) has the backoff.runtime decorator which allows you to introspect the exception or response and yield a wait value based on that

@loeakaodas
Copy link
Contributor

@mredolatti @bgreen-litl basic backoff functionality was added in #143. This PR should probably be closed and a custom wait time functionality can be added in a new PR based on the latest version in master.

@luandy64
Copy link
Contributor

@savicbo @mredolatti @bgreen-litl @antoine-lizee @KBorders01 @henriblancke @nehiljain

Correct me if I'm wrong, but if you run v1.10.4 of this tap, there's already logic to handle the rate limit headers thanks to @loeakaodas

def rate_throttling(response):
if int(response.headers['X-RateLimit-Remaining']) == 0:
seconds_to_sleep = calculate_seconds(int(response.headers['X-RateLimit-Reset']))
if seconds_to_sleep > MAX_SLEEP_SECONDS:
message = "API rate limit exceeded, please try after {} seconds.".format(seconds_to_sleep)
raise RateLimitExceeded(message) from None
logger.info("API rate limit exceeded. Tap will retry the data collection after %s seconds.", seconds_to_sleep)
time.sleep(seconds_to_sleep)

@KBorders01
Copy link

@savicbo @mredolatti @bgreen-litl @antoine-lizee @KBorders01 @henriblancke @nehiljain

Correct me if I'm wrong, but if you run v1.10.4 of this tap, there's already logic to handle the rate limit headers thanks to @loeakaodas

def rate_throttling(response):
if int(response.headers['X-RateLimit-Remaining']) == 0:
seconds_to_sleep = calculate_seconds(int(response.headers['X-RateLimit-Reset']))
if seconds_to_sleep > MAX_SLEEP_SECONDS:
message = "API rate limit exceeded, please try after {} seconds.".format(seconds_to_sleep)
raise RateLimitExceeded(message) from None
logger.info("API rate limit exceeded. Tap will retry the data collection after %s seconds.", seconds_to_sleep)
time.sleep(seconds_to_sleep)

@luandy64 that is correct, it looks like this issue has been resolved in another PR.

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.