Add retry on get user when rate limited #17
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem -
/users/{id}
rate limited by auth0 on get auth0 userThis is coming from
func (authClient *AuthClient) GetUserById(id string) (*User, error) {
https://github.com/form3tech-oss/terraform-provider-auth0/blob/master/auth0/auth0_client.go#L116
Auth0 rate limits for -
/users/{id}
https://auth0.com/docs/policies/rate-limits#management-api-v2
Solution - retry with timed back off
Provider uses - https://github.com/parnurzeal/gorequest
This package supports - retries - https://github.com/parnurzeal/gorequest#retry
Changes
Retry on
Get*
calls when rate limited byAuth0
This is done by leveraging
https://github.com/parnurzeal/gorequest
retry functionality. We have decided to keep it simple and not addexponential back-off
for now.New optional provider parameters
auth0_request_max_retry_count
- max retry on requests to Auth0 - default: 2auth0_time_between_retries
- time to wait between retried requests to Auth0 (in milliseconds) - default: 1000Added acceptance test to verify
throttling
onGetUserById
This test is not perfect and fully reliable as it depends on burst generated by machine running it. To get the correct test we need to hit
50
requests per seconds on paid plan. It was still useful during local development to verify if retry helps withthrottling
. We can disable this test to run from the main test suite.Refactored
Auth0
client creationMoved token generation to within the
Auth0
client as it is used now in the new acceptance test.