X Tutup
Skip to content

fix: exclude PageSpeed Insights API errors from retries.#2010

Merged
bshaffer merged 4 commits intogoogleapis:masterfrom
adamsilverstein:patch-2
Jan 19, 2021
Merged

fix: exclude PageSpeed Insights API errors from retries.#2010
bshaffer merged 4 commits intogoogleapis:masterfrom
adamsilverstein:patch-2

Conversation

@adamsilverstein
Copy link
Contributor

When retries are enabled in the client, the Runner class by default retries requests when the API returns a 500 error code. Unfortunately, the PageSpeed Insights API returns 5XX's for errors that should really be 4XX (specifically in Lighthouse for the errors ERRORED_DOCUMENT_REQUEST, FAILED_DOCUMENT_REQUEST). So 500 errors from this API shouldn't be retried, they will only increase load and fail again.

These errors are non-retryable user defined errors: for example requesting data for a url that doesn't go anywhere. This PR changes the default client behavior to avoid retrying requests the the reason lighthouseError, preventing unnecessary retries.

Steps to reproduce

  1. Visit the PageSpeed Insights API explorer page
  2. Enter a domain that does non exist in the URL field, for example https://notareal-websiteno.com, and run the report.
  3. Note the returned error response is a 500 error.

image

Additional Context

We recently added this change the the defaults used by Site Kit which relies on this library. Since we found this condition important enough to explicitly exclude, I thought it might be worth contributing upstream, although I'm not sure you want to add these types of API specific exceptions.

@adamsilverstein adamsilverstein requested a review from a team December 3, 2020 22:29
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Dec 3, 2020
@bshaffer
Copy link
Contributor

bshaffer commented Jan 6, 2021

@adamsilverstein thank you for this change!

I am not sure the implications of the reason lighthouseError, and if errors with this reason should never be retried. Do you know of any documentation for what lighthouseError means? If it's not always a result of a bad request, e.g. 400, then we may need something more robust.

Copy link
Contributor

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

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

Looking more into it, Lighthouse is our tool for analyzing / auditing the webpages. When this downstream library throws an error, the wrapping API throws a 500 and sets the reason as "lighthouseError".

Unfortunately, looking at possible error responses, some of them do correspond to 500 errors that should be retried. For example:

Lighthouse returned error: INTERNAL: APP::1: Lost browser connection.

In these cases, it would be best if the libraries retried this request. So is it better to retry all requests so that the ones that need retrying get it, or to not retry any requests, to prevent unnecessary retries? A third option would be to allow for certain "error" values to be configured.

I think the error above is not a common error, and results from a bug that shouldn't be retried anyway. So I approve this change.

@adamsilverstein
Copy link
Contributor Author

@bshaffer Thank you for reviewing and approving.

@jdpedrie jdpedrie changed the title Exclude PageSpeed Insights API errors from retries. fix: exclude PageSpeed Insights API errors from retries. Jan 19, 2021
@jdpedrie jdpedrie mentioned this pull request Jan 19, 2021
@bshaffer bshaffer merged commit 09028dc into googleapis:master Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup