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

[Rest] Support exponential backoff and retry #1339

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

flichtenheld
Copy link
Contributor

@flichtenheld flichtenheld commented Feb 26, 2024

Uses the urllib3 builtin Retry mechanism.
We only support retrying on HTTP return status,
not on any of the other retries that that class
defines (e.g. connection problems, redirects).

The usual use case for this is to handle 429
responses from the Atlassian Cloud API which
has request limits that are easily hit by
scripts iterating over objects like Jira
issues or Bitbucket pull requests.

Based on earlier work by @jp-harvey.

Replaces #904

@flichtenheld
Copy link
Contributor Author

The retries are only visible on DEBUG level logging. Example:

2024-02-26 16:25:45,497 DEBUG:curl --silent -X GET -H 'Content-Type: application/json' -H 'Accept: application/json'  'https://api.bitbucket.org/2.0/repositories/<workspace>/<repo>/refs/branches/flichtenheld/branch'
2024-02-26 16:25:45,721 DEBUG:https://api.bitbucket.org:443 "GET /2.0/repositories/<workspace>/<repo>/refs/branches/flichtenheld/branch HTTP/1.1" 429 46
2024-02-26 16:25:45,721 DEBUG:Incremented Retry for (url='/2.0/repositories/<workspace>/<repo>/refs/branches/flichtenheld/branch'): Retry(total=None, connect=None, read=None, redirect=None, status=999)
2024-02-26 16:25:45,721 DEBUG:Retry: /2.0/repositories/<workspace>/<repo>/refs/branches/flichtenheld/branch
2024-02-26 16:25:45,926 DEBUG:https://api.bitbucket.org:443 "GET /2.0/repositories/<workspace>/<repo>/refs/branches/flichtenheld/branch HTTP/1.1" 429 46
2024-02-26 16:25:45,926 DEBUG:Incremented Retry for (url='/2.0/repositories/<workspace>/<repo>/refs/branches/flichtenheld/branch'): Retry(total=None, connect=None, read=None, redirect=None, status=998)
2024-02-26 16:25:48,230 DEBUG:Retry: /2.0/repositories/<workspace>/<repo>/refs/branches/flichtenheld/branch
2024-02-26 16:25:48,473 DEBUG:https://api.bitbucket.org:443 "GET /2.0/repositories/<workspace>/<repo>/refs/branches/flichtenheld/branch HTTP/1.1" 200 None
2024-02-26 16:25:48,474 DEBUG:HTTP: GET flichtenheld/branch -> 200 OK
...

Uses the urllib3 builtin Retry mechanism.
We only support retrying on HTTP return status,
not on any of the other retries that that class
defines (e.g. connection problems, redirects).

The usual use case for this is to handle 429
responses from the Atlassian Cloud API which
has request limits that are easily hit by
scripts iterating over objects like Jira
issues or Bitbucket pull requests.

Based on earlier work by jp-harvey.

Co-authored-by: jp-harvey <jpharvey@cloudquarterback.com>
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 34.16%. Comparing base (5c54e5d) to head (b2383e6).
Report is 1 commits behind head on master.

Files Patch % Lines
atlassian/rest_client.py 40.00% 2 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1339   +/-   ##
=======================================
  Coverage   34.16%   34.16%           
=======================================
  Files          45       45           
  Lines        8368     8373    +5     
  Branches     1176     1177    +1     
=======================================
+ Hits         2859     2861    +2     
- Misses       5395     5397    +2     
- Partials      114      115    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gonchik gonchik merged commit 43363c7 into atlassian-api:master Feb 26, 2024
10 checks passed
@gonchik
Copy link
Member

gonchik commented Feb 26, 2024

@flichtenheld Thanks!

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.

None yet

3 participants