-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Do not abort SAR loop on throttling #2240
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,6 +180,9 @@ def _handle_get_application_request(self, app_id, semver, key, logical_id): | |
| warning_message = "{}. Unable to verify access to {}/{}.".format(e, app_id, semver) | ||
| LOG.warning(warning_message) | ||
| self._applications[key] = {"Unable to verify"} | ||
| except ClientError as e: | ||
| LOG.exception(e) | ||
| raise e | ||
|
|
||
| def _handle_create_cfn_template_request(self, app_id, semver, key, logical_id): | ||
| """ | ||
|
|
@@ -194,7 +197,12 @@ def _handle_create_cfn_template_request(self, app_id, semver, key, logical_id): | |
| create_cfn_template = lambda app_id, semver: self._sar_client.create_cloud_formation_template( | ||
| ApplicationId=self._sanitize_sar_str_param(app_id), SemanticVersion=self._sanitize_sar_str_param(semver) | ||
| ) | ||
| response = self._sar_service_call(create_cfn_template, logical_id, app_id, semver) | ||
| try: | ||
| response = self._sar_service_call(create_cfn_template, logical_id, app_id, semver) | ||
| except ClientError as e: | ||
| LOG.exception(e) | ||
| raise e | ||
|
|
||
| LOG.info("Requested to create CFN template {}/{} in serverless application repo.".format(app_id, semver)) | ||
| self._applications[key] = response[self.TEMPLATE_URL_KEY] | ||
| if response["Status"] != "ACTIVE": | ||
|
|
@@ -308,6 +316,9 @@ def on_after_transform_template(self, template): | |
| while (time() - start_time) < self.TEMPLATE_WAIT_TIMEOUT_SECONDS: | ||
|
||
| temp = self._in_progress_templates | ||
| self._in_progress_templates = [] | ||
| # it's either our first time in this loop or we just slept SLEEP_TIME_SECONDS so we can | ||
| # try calling SAR | ||
| throttled = False | ||
|
||
|
|
||
| # Check each resource to make sure it's active | ||
| LOG.info("Checking resources in serverless application repo...") | ||
|
|
@@ -318,8 +329,26 @@ def on_after_transform_template(self, template): | |
| TemplateId=self._sanitize_sar_str_param(template_id), | ||
| ) | ||
| ) | ||
| response = self._sar_service_call(get_cfn_template, application_id, application_id, template_id) | ||
| response = {"Status": "PREPARING"} # default response if we can't reach SAR | ||
|
|
||
| try: | ||
| if not throttled: | ||
| response = self._sar_service_call( | ||
| get_cfn_template, application_id, application_id, template_id | ||
| ) | ||
|
||
| except ClientError as e: | ||
| error_code = e.response["Error"]["Code"] | ||
| if error_code == "TooManyRequestsException": | ||
|
||
| # We were throttled by SAR, don't hammer SAR with more calls in this for loop | ||
| throttled = True | ||
| LOG.debug("SAR call timed out for application id {}".format(application_id)) | ||
| # don't re-raise, fall through to regular processing as if the template wasn't ready yet | ||
| else: | ||
| LOG.exception(e) | ||
| raise e | ||
|
|
||
| self._handle_get_cfn_template_response(response, application_id, template_id) | ||
|
|
||
| LOG.info("Finished checking resources in serverless application repo.") | ||
|
|
||
| # Don't sleep if there are no more templates with PREPARING status | ||
|
|
@@ -372,9 +401,6 @@ def _sar_service_call(self, service_call_lambda, logical_id, *args): | |
| error_code = e.response["Error"]["Code"] | ||
| if error_code in ("AccessDeniedException", "NotFoundException"): | ||
| raise InvalidResourceException(logical_id, e.response["Error"]["Message"]) | ||
|
|
||
marekaiv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # 'ForbiddenException'- SAR rejects connection | ||
| LOG.exception(e) | ||
| raise e | ||
|
|
||
| def _resource_is_supported(self, resource_type): | ||
|
|
||
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.
Doesn't the exception get logged if this is raised and not caught? Any specific reason we added this here?
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.
I wondered the same thing -- I added this here to preserve the existing behavior. I removed
LOG.exceptionfrom_sar_service_callas throttles are not really exceptions forGetCloudFormation. I can do a bit more digging to see if we need that extra log.