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

[SDK-4224] Allow configuration and disabling of retry strategy #216

Merged
merged 9 commits into from
Jun 6, 2023

Conversation

ewanharris
Copy link
Contributor

@ewanharris ewanharris commented May 30, 2023

🔧 Changes

This improves upon the existing retry logic implemented in the package by expanding the retry
conditions, allowing configuration of the retry conditions and allowing disabling retries.

By default the Management Client will retry a request 2 times, when there is a 429 status code
or if there is an error returned (except for a select couple of errors that are not recoverable). The X-RateLimit-Reset is consulted to ensure that the request will work, unless the time until the request is more than the maximum wait time.

The configuration of the max retries and status codes that will be retried on by providing a
RetryOptions struct with the required values with the WithRetryOptions function, and retries
can be disabled by passing the WithNoRetries function

📚 References

🔬 Testing

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

⚠️ Breaking Change

The SDK will now retry a request a maximum of 2 times by default, and will also retry on certain errors.

@ewanharris ewanharris requested a review from a team as a code owner May 30, 2023 11:43
MIGRATION_GUIDE.md Outdated Show resolved Hide resolved
domain,
management.WithClientCredentials(context.Background(), id, secret),
management.WithNoRetries(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand it might be a bit late for this, but with this design it would be possible to use both WithRetries() and WithNoRetries() –even though the last used method would prevail. What about simply using management.WithRetries(RetryOptions{MaxRetries: 0}) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

(instead of WithNoRetries())

Copy link
Contributor

@Widcket Widcket May 30, 2023

Choose a reason for hiding this comment

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

Consider as well using factory methods if necessary, to reduce the verbosity and make the intent clearer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, what is the SDK already doing with other similar configuration options?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was a little undecided on this and initially had an Enabled property on the RetryOptions struct.

We currently have WithNoAuth0ClientInfo to disable the Auth0Client telemetry so that was part of the reason in going for WithNoRetries for this API

Copy link
Contributor

@Widcket Widcket May 30, 2023

Choose a reason for hiding this comment

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

Note that this being a new major version, it's an opportunity to go with the approach that makes the most sense for all methods involved (including WithNoAuth0ClientInfo), specially since that will set the pattern for any future API additions once the major is out. It's alright if you want to use WithNoRetries() anyway though.

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 think given that we'd most likely have keep WithNoAuth0ClientInfo (i.e. adding an Enabled flag to that struct isn't as straight forward), then I'd lean towards maintaining the existing WithX/WithNoX pattern as it does fit with Go

internal/client/client.go Outdated Show resolved Hide resolved
var redirectsErrorRe = regexp.MustCompile(`stopped after \d+ redirects\z`)

// Matches the error returned by net/http when the TLS certificate is not trusted.
// When version 1.20 is the minimum supported this can be replaced by tls.CertificateVerificationError.
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that if you're making a new major version it is acceptable to have it support only Go 1.20+. Specially since Go 1.21 is expected for August 2023, a mere 3 months away, which will drop support for 1.19.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think that's a fair shout, I'll maybe circle back to dropping 1.19 after checking one some of the users of this package have their compile target.

internal/client/client.go Outdated Show resolved Hide resolved
@ewanharris ewanharris requested a review from Widcket May 31, 2023 09:25
@codecov-commenter
Copy link

codecov-commenter commented May 31, 2023

Codecov Report

Patch coverage: 91.02% and project coverage change: -0.18 ⚠️

Comparison is base (3f8f5f7) 95.17% compared to head (3e9cc2e) 94.99%.

Additional details and impacted files
@@            Coverage Diff             @@
##             beta     #216      +/-   ##
==========================================
- Coverage   95.17%   94.99%   -0.18%     
==========================================
  Files          37       37              
  Lines        7192     7254      +62     
==========================================
+ Hits         6845     6891      +46     
- Misses        276      295      +19     
+ Partials       71       68       -3     
Impacted Files Coverage Δ
internal/client/client.go 66.47% <89.70%> (+1.47%) ⬆️
management/management.go 100.00% <100.00%> (ø)
management/management_option.go 62.71% <100.00%> (+5.84%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Widcket
Widcket previously approved these changes May 31, 2023
ewanharris and others added 7 commits June 2, 2023 17:53
This improves upon the existing retry logic implemented in the package by expanding the retry
conditions, allowing configuration of the retry conditions and allowing disabling retries.

By default the Management Client will retry a request 2 times, when there is a 429 status code
or if there is an error returned (except for a select couple of errors).

The configuration of the max retries and status codes that will be retried on by providing a
`RetryOptions` struct with the required values with the `WithRetryOptions` function, and retries
can be disabled by passing the `WithNoRetries` struct.
Co-authored-by: Rita Zerrizuela <zeta@widcket.com>
Co-authored-by: Rita Zerrizuela <zeta@widcket.com>
@ewanharris ewanharris force-pushed the feat/SDK-4224-retry-improvements branch from 7ba548e to 3e9cc2e Compare June 2, 2023 16:57
@ewanharris ewanharris requested a review from Widcket June 2, 2023 17:09
@ewanharris ewanharris merged commit 940dabd into beta Jun 6, 2023
@ewanharris ewanharris deleted the feat/SDK-4224-retry-improvements branch June 6, 2023 09:58
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.

3 participants