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

[Python BQ] Retry get_table for quota errors #28820

Merged
merged 18 commits into from
Jan 8, 2024

Conversation

ahmedabu98
Copy link
Contributor

@ahmedabu98 ahmedabu98 commented Oct 4, 2023

Python SDK's BigQuery get table method is only retried for server and timeout errors. We should extend this to also retry for quota errors (403: quotaExceeded, rateLimitExceeded).

Also adding some logic to retry_on_server_errors_timeout_or_quota_issues_filter to make a best-effort attempt at retrying only for transient reasons. Note that BigQuery also returns error code 403 for non-transient errors like accessDenied.

@ahmedabu98
Copy link
Contributor Author

Run Python 3.8 Postcommit

@ahmedabu98
Copy link
Contributor Author

Run Python 3.10 PostCommit

Copy link
Contributor

@Abacn Abacn left a comment

Choose a reason for hiding this comment

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

LGTM

just a note - python postcommit currently failing bigquery read ITs: #28811

@codecov
Copy link

codecov bot commented Oct 4, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (0b93830) 72.22% compared to head (bfdc47c) 72.27%.
Report is 791 commits behind head on master.

❗ Current head bfdc47c differs from pull request most recent head 4992a83. Consider uploading reports for the commit 4992a83 to get more accurate results

Files Patch % Lines
sdks/python/apache_beam/utils/retry.py 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #28820      +/-   ##
==========================================
+ Coverage   72.22%   72.27%   +0.04%     
==========================================
  Files         684      684              
  Lines      101230   101248      +18     
==========================================
+ Hits        73117    73173      +56     
+ Misses      26534    26496      -38     
  Partials     1579     1579              
Flag Coverage Δ
python 82.83% <93.33%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@kennknowles
Copy link
Member

So obviously I have to ask - can you test it?

@liferoad
Copy link
Collaborator

liferoad commented Oct 4, 2023

@ahmedabu98
Copy link
Contributor Author

Yup, added some tests

@ahmedabu98
Copy link
Contributor Author

Run Python 3.8 Postcommit

@ahmedabu98
Copy link
Contributor Author

Run Python 3.10 Postcommit

sdks/python/apache_beam/utils/retry.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/utils/retry.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/utils/retry.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/utils/retry.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/utils/retry.py Outdated Show resolved Hide resolved
@ahmedabu98
Copy link
Contributor Author

Thanks for the review @satybald, PTAL

@ahmedabu98
Copy link
Contributor Author

@satybald sorry for the delay, PTAL

@ahmedabu98 ahmedabu98 marked this pull request as ready for review January 8, 2024 20:00
@ahmedabu98
Copy link
Contributor Author

@Abacn can you take another look at this?

@Abacn Abacn self-requested a review January 8, 2024 20:05
Copy link
Contributor

github-actions bot commented Jan 8, 2024

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @damccorm for label python.
R: @Abacn for label io.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@ahmedabu98
Copy link
Contributor Author

stop reviewer notifications

Copy link
Contributor

@Abacn Abacn left a comment

Choose a reason for hiding this comment

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

Thanks for adding the test. Just have thing to confirm about the assumption over response

content = exception.content
if not isinstance(content, dict):
content = json.loads(exception.content)
return content["error"]["errors"][0]["reason"] in _RETRYABLE_REASONS
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a deeply nested information. Is the response guaranteed (documented) to have this format? In any case, would you mind add a comment for the example error json loads, or is there an example error message could share?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm basing this off of the structure of the exception returned from get_table():

bq = bigquery_tools.BigQueryWrapper()
try:
  bq.get_table("google.com:clouddfe", "nonexistent", "nonexistent")
except Exception as e:
  print(type(e))                  # >>> <class 'apitools.base.py.exceptions.HttpNotFoundError'>
  print(e.status_code)              # >>> 404
  print(type(e.content))              # >>> <class 'bytes'>
  content = json.loads(e.content)

  print(content.keys())                   # >>> dict_keys(['error'])
  print(content['error'].keys())             # >>> dict_keys(['code', 'message', 'errors', 'status', 'details'])
  print(content['error']['errors'][0].keys())   # >>> dict_keys(['message', 'domain', 'reason', 'debugInfo'])
  print(content['error']['errors'][0]['reason'])  # >>> notFound

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the detail. Anyways this is wrapped in a a fail-safe try clause so LGTM

Copy link
Contributor

github-actions bot commented Jan 8, 2024

Stopping reviewer notifications for this pull request: requested by reviewer

@ahmedabu98 ahmedabu98 merged commit c9e036e into apache:master Jan 8, 2024
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants