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

Bug fix + various code/logging improvements to retry code #643

Merged
merged 1 commit into from
Aug 1, 2018

Conversation

brandur
Copy link
Contributor

@brandur brandur commented Aug 1, 2018

This one is a variety of improvements to the retry code:

  • Fixed one bug whereby for a failed request, we were not reading the
    entire response body before trying to log it, which results in an
    uninformative output like &{409..... Here we add a ReadAll.
  • I denested some code so that we have less indentation.
  • I changed measuring request time to measuring individual requests
    around s.HTTPClient.Do instead of measuring the entire span
    including all the sleeping the retry block is doing.
  • I added logging for the amount of time the program is about to go to
    sleep before a retry. You can still get the total execution time by
    adding the time for all requests plus the time for all sleeps.
  • Generally changed some logs around for consistency around format,
    casing, and punctuation.

The impetus is that I was trying to understand the code to debug #642.
This might help get some visibility into a solution, but won't solve the
problem.

r? @remi-stripe
cc @stripe/api-libraries

@@ -329,7 +346,7 @@ func (s *BackendConfiguration) Do(req *http.Request, v interface{}) error {
}

if s.LogLevel > 2 {
s.Logger.Printf("Stripe Response: %q\n", resBody)
s.Logger.Printf("Response: %s\n", string(resBody))
Copy link
Contributor

Choose a reason for hiding this comment

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

Changed the %q to a %s with a string(...) cast because the %q produces lots of noisy escaping that's not really needed for anything and detrimental to legibility:

Stripe Response: \"{\\\\"id\\\": \\\"ch_*\\\",\

Copy link
Contributor

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

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

LGTM

This one is a variety of improvements to the retry code:

* Fixed one bug whereby for a failed request, we were not reading the
  entire response body before trying to log it, which results in an
  uninformative output like `&{409....`. Here we add a `ReadAll`.
* I denested some code so that we have less indentation.
* I changed measuring request time to measuring individual requests
  around `s.HTTPClient.Do` instead of measuring the entire span
  including all the sleeping the retry block is doing.
* I added logging for the amount of time the program is about to go to
  sleep before a retry. You can still get the total execution time by
  adding the time for all requests plus the time for all sleeps.
* Generally changed some logs around for consistency around format,
  casing, and punctuation.

The impetus is that I was trying to understand the code to debug #642.
This might help get some visibility into a solution, but won't solve the
problem.
@brandur-stripe brandur-stripe force-pushed the brandur-retry-improvements branch from b85fc2c to 3c4328a Compare August 1, 2018 18:15
@stripe-ci stripe-ci removed the approved label Aug 1, 2018
@brandur-stripe
Copy link
Contributor

Thanks Remi!

@brandur-stripe brandur-stripe merged commit a2d0799 into master Aug 1, 2018
@brandur-stripe brandur-stripe deleted the brandur-retry-improvements branch August 1, 2018 18:31
@brandur-stripe
Copy link
Contributor

Released as 38.1.0.

nadaismail-stripe pushed a commit that referenced this pull request Oct 18, 2024
Bumps [sorbet](https://github.com/sorbet/sorbet) from 0.5.10286 to 0.5.10297.
- [Release notes](https://github.com/sorbet/sorbet/releases)
- [Commits](https://github.com/sorbet/sorbet/commits)

---
updated-dependencies:
- dependency-name: sorbet
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

4 participants