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 Retry() while using response iterator #12731

Open
ampkeegan opened this issue May 23, 2024 · 0 comments
Open

Support Retry() while using response iterator #12731

ampkeegan opened this issue May 23, 2024 · 0 comments
Assignees
Labels
api: cloudchannel Issues related to the Channel Services API. status: investigating The issue is under investigation, which is determined to be non-trivial.

Comments

@ampkeegan
Copy link

ampkeegan commented May 23, 2024

Per recommendation of support case GCP #51120117 I'm opening a ticket here. Not sure if this is a bug report, feature request, or I'm just doing something wrong, but it appears the basic Retry() functionality for google-cloud-channel (and maybe others) only works if the limit is reached when the initial request is made. If a limit is reached while paging through the response iterator, Retry() is not implemented.

Example code:

_RETRYABLE_REASONS = frozenset(
[StatusCode.RESOURCE_EXHAUSTED, ]
)
 
_UNSTRUCTURED_RETRYABLE_TYPES = (
	   ConnectionError,
	   exceptions.Aborted,
	   exceptions.DeadlineExceeded,
	   exceptions.InternalServerError,
	   exceptions.ResourceExhausted,
	   exceptions.ServiceUnavailable,
	   exceptions.Unknown,
	   exceptions.Cancelled,
	   exceptions.TooManyRequests
)

def _should_retry(exc):
	if not hasattr(exc, "errors") or len(exc.errors) == 0:
		# Check for unstructured error returns, e.g. from GFE
		return isinstance(exc, _UNSTRUCTURED_RETRYABLE_TYPES)
	reason = exc.errors[0].code()
	return reason in _RETRYABLE_REASONS
 
custom_retry = Retry(
			   initial=1, # seconds (default: 0.1)
			   maximum=90.0, # seconds (default: 60.0)
			   multiplier=5, # default: 1.3
			   deadline=300.0, # seconds (default: 60.0)
			   predicate=_should_retry,
	   )

request = channel_v1.ListCustomersRequest(parent="accounts/" + channelAccount, page_size=50)
response = client_v1.list_customers(request, retry=custom_retry)

c = 0
for x in response.pages:
	print(c)
	c += 1

Running three simultaneous executions of this script will result in a RESOURCE_EXHAUSTED error. Immediately running a single instance of the script (while still within the window to be rate limited) will properly implement the Retry() with exponential backoff until the limit is removed. Once it can progress, it will fail again shortly while paginating through response.pages with another RESOURCE_EXHAUSTED.

@parthea parthea self-assigned this May 30, 2024
@parthea parthea added status: investigating The issue is under investigation, which is determined to be non-trivial. api: cloudchannel Issues related to the Channel Services API. labels May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: cloudchannel Issues related to the Channel Services API. status: investigating The issue is under investigation, which is determined to be non-trivial.
Projects
None yet
Development

No branches or pull requests

2 participants