Place concurrency limiter middleware after retry middlewares (#3420)

This is to safeguard against the scenario where retry handlers might spawn additional requests to graph. Such retries may cause us to exceed concurrent request limits, leading to 429s ( `Application is over its MailboxConcurrency limit`) 

This PR will ensure that such retry requests are also funneled through the concurrency limiter.

---

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Abhishek Pandey 2023-05-16 13:37:52 -07:00 committed by GitHub
parent 2ad32660e8
commit 965427d491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -247,11 +247,6 @@ func kiotaMiddlewares(
) []khttp.Middleware {
mw := []khttp.Middleware{}
// Optionally add concurrency limiter middleware if it has been initialized
if concurrencyLim != nil {
mw = append(mw, concurrencyLim)
}
mw = append(mw, []khttp.Middleware{
msgraphgocore.NewGraphTelemetryHandler(options),
&RetryMiddleware{
@ -264,10 +259,18 @@ func kiotaMiddlewares(
khttp.NewParametersNameDecodingHandler(),
khttp.NewUserAgentHandler(),
&LoggingMiddleware{},
&RateLimiterMiddleware{},
&MetricsMiddleware{},
}...)
// Optionally add concurrency limiter middleware if it has been initialized.
if concurrencyLim != nil {
mw = append(mw, concurrencyLim)
}
mw = append(
mw,
&RateLimiterMiddleware{},
&MetricsMiddleware{})
if len(cc.appendMiddleware) > 0 {
mw = append(mw, cc.appendMiddleware...)
}