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

Issue 87 - Handle some RequestRateTooLarge (429) errors with retries #122

Closed
wants to merge 5 commits into from

Conversation

jasonchester
Copy link
Contributor

@jasonchester jasonchester commented Jun 18, 2018

  • Added -RetryOnRequestRateTooLarge parameter to handle Response Code 429 errors in Invoke-CosmosDbRequest, Get-CosmosDbDocument and Invoke-CosmosDbStoredProcedure. This resolves some of Issue #87
  • Added RU Output to Verbose Output Stream in Invoke-CosmosDbRequest with -UseWebRequest
    VERBOSE: Request Charge: 1570.5 RUs
    
  • Improved ScriptLogResults when using Invoke-CosmosDbStoredProcedure -Debug -Verbose
    VERBOSE: ScriptLogResults:
    enter my procedure
    some console.log() messages
    my procedure complete
    

This change is Reviewable

@jasonchester jasonchester changed the title Issue 87 - Handle Request Rate Too Large (429) Retries Issue 87 - Handle some RequestRateTooLarge (429) errors with retries Jun 18, 2018
@codecov
Copy link

codecov bot commented Jun 18, 2018

Codecov Report

Merging #122 into dev will decrease coverage by 3%.
The diff coverage is 20%.

Impacted file tree graph

@@        Coverage Diff         @@
##           dev   #122   +/-   ##
==================================
- Coverage   89%    85%   -4%     
==================================
  Files       11     11           
  Lines      690    698    +8     
==================================
- Hits       618    600   -18     
- Misses      72     98   +26

@PlagueHO PlagueHO self-assigned this Jun 19, 2018
@PlagueHO PlagueHO added the needs review The pull request needs a code review. label Jun 19, 2018
@PlagueHO
Copy link
Owner

Sorry about taking so long with this! I'll get this reviewed in the next couple of days. Thanks again!

@jasonchester
Copy link
Contributor Author

No problem @PlagueHO, definitely understand that this probably isn't your day job.

I know there are a lot of different ways this could be enhanced to handle retry counters and delays but I decided to start with the simplest implementation I could.

I have used this mvp a couple of times already and so far it has worked great for my use cases of getting all documents out in a continuation loop based on a simple query.

I have also been thinking about how to add unit tests as well and I would probably need to mock start-sleep in order to test. Do you know if there's any limitations on mocking built-in cmdlets? Any other ideas on testing would be welcome as well.

Thanks again for your work on this project, it's been extremely useful for me and I'm sure the rest of the community as well.

@PlagueHO
Copy link
Owner

I've been thinking about this one a bit and I think a more strategic model would be to allow the handling of the 429 to be governed by settings provided in the Context object. This would allow easy support for all functions rather than require this to be implemented on a per function basis (which will require a lot of work and many more unit tests to keep the coverage high). I've also got requirements from my performance test teams to be able to allow them to control this.

My plan for this was to allow a more feature rich retry (closer to the DocumentDB SDK) model with:

  1. Max retries to be specified (0 = unlimited)
  2. Back-off model: Linear, Logarithmic, Random
  3. Retry Rate: (initial retry rate for logarithmic)

I'd implement this by creating a new custom CosmosDBRetryProperties class containing the properties above and allow it to be attached to the Context object. It could also be possible (in future) to allow this object to also be passed into individual functions to override anything set in the Context.

Would this be something that would work for you?

Again, I am grateful for the help and support on this and happy it is useful 😁


Reviewed 1 of 1 files at r2.
Review status: 1 of 4 files reviewed, all discussions resolved (waiting on @PlagueHO)


Comments from Reviewable

@PlagueHO
Copy link
Owner

I'm also converting the whole module to stop using Invoke-RestMethod which is going to refactor all this code.

@PlagueHO
Copy link
Owner

I've actually now ended up merging the policy based model including documentation. So unfortunately it has superseded this one 😢

@jasonchester
Copy link
Contributor Author

@PlagueHO no worries, this looks like a much more complete implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review The pull request needs a code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants