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

[core-http] Throttling retry policy fix in core-http #15832

Merged
31 commits merged into from
Jun 25, 2021

Conversation

HarshaNalluru
Copy link
Member

@HarshaNalluru HarshaNalluru commented Jun 17, 2021

Fixes #15796

Problem

The throttlingRetryPolicy in core-http has the potential to retry for an extended period if the service continues returning "retry after" headers on subsequent calls.

Here's the snippet of code that handles the "retry after" retries:

  public async sendRequest(httpRequest: WebResource): Promise<HttpOperationResponse> {
    return this._nextPolicy.sendRequest(httpRequest.clone()).catch((err) => {
        // other code elided....
        return delay(delayInMs).then((_: any) => this.sendRequest(httpRequest.clone()));

Solution

Update delay such that it respects abort signal.
Similar to what I had to do for app-config at #15721

@ghost ghost added Azure.Core App Configuration Azure.ApplicationModel.Configuration labels Jun 17, 2021
@HarshaNalluru HarshaNalluru changed the title Harshan/core http/throttling policy [core-http] Throttling retry policy fix in core-http Jun 17, 2021
@HarshaNalluru HarshaNalluru marked this pull request as ready for review June 17, 2021 23:47
@@ -91,6 +91,7 @@
"@azure/core-http": "^1.2.0",
"@azure/core-paging": "^1.1.1",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-util": "^1.0.0-beta.1",
Copy link
Member

Choose a reason for hiding this comment

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

is appconfiguration in beta? if not, it should not take a dep on a beta.

Copy link
Member Author

Choose a reason for hiding this comment

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

App-config is beta, but we may soon GA in the next couple of months.
Why is core-util in beta anyways? Can't we make that GA instead?

Copy link
Member

Choose a reason for hiding this comment

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

Because we did not settle on the public surface for it yet.

appconfig is in beta but core-http and core-amqp are not IIRC and you added core-util as a dep there. My recommendation is to keep the local implementation of delay for now and have it moved to core-util in another PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I really don't want to keep 3 copies of delay (core-http, core-amqp and app-config).

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I really don't want to keep 3 copies of delay (core-http, core-amqp and app-config).

Why cannot App Config use the one in core-http?

Since this PR's main objective is around fixing an issue with the retry policy, can we stick to just that in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

@ramya-rao-a So, you're suggesting core-http and core-amqp would have delay? Can do that if weare fine with 2 copies.

(What's the point of core-util then?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of core-util then

It is pending the on the conclusion on the discussion we had today on the subject of code sharing

Copy link
Member Author

Choose a reason for hiding this comment

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

We now have two copies of (advanced) delay.. core-amqp and core-http.

Logged #15930 for core-util discussion.

@@ -12,7 +12,7 @@ import {
Constants,
RestError
} from "@azure/core-http";
Copy link
Member

Choose a reason for hiding this comment

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

Now we just need to move to corev2 so we can fix #6484

@@ -181,7 +181,7 @@ export class DefaultHttpClient extends FetchHttpClient {
}

// @public
export function delay<T>(t: number, value?: T): Promise<T | void>;
export function delay<T>(delayInMs: number, abortSignal?: AbortSignalLike, abortErrorMsg?: string, value?: T): Promise<T | void>;
Copy link
Contributor

Choose a reason for hiding this comment

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

value?: T should be the 2nd argument, otherwise this would be a breaking change.

Copy link
Member Author

@HarshaNalluru HarshaNalluru Jun 24, 2021

Choose a reason for hiding this comment

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

Good point.

I'll switch to that.
What about the core-amqp counterpart? How to get the copy of this method to stay consistent? Does that mean we can only bring consistency if we upgrade to a major version?

Copy link
Member

Choose a reason for hiding this comment

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

@HarshaNalluru I think there is no need to care about their consistency, we can just ignore them once core-util goes GA. Also, core-http is going to be phased out fairly soon anyway.

Copy link
Member

@deyaaeldeen deyaaeldeen left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

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

Nice work! A few small comments/suggestions

sdk/core/core-http/review/core-http.api.md Outdated Show resolved Hide resolved
sdk/core/core-http/src/policies/rpRegistrationPolicy.ts Outdated Show resolved Hide resolved
}
};

onAborted = (): void => {
Copy link
Member

Choose a reason for hiding this comment

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

why is this assigned? I don't see it getting assigned back to undefined can we just declare the method in scope?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just copied this from core-amqp.

Can be done, will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

image
Linter complains about this. Reverting.

sdk/core/core-http/src/util/delay.ts Show resolved Hide resolved
sdk/core/core-http/src/util/typeguards.ts Outdated Show resolved Hide resolved
@ghost
Copy link

ghost commented Jun 24, 2021

Hello @HarshaNalluru!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit bb9896d into main Jun 25, 2021
@ghost ghost deleted the harshan/core-http/throttling-policy branch June 25, 2021 01:49
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-js that referenced this pull request Sep 23, 2021
Microsoft.ApiManagement : Release api-version 2021-04-01-preview (Azure#15832)

* Adds base for updating Microsoft.ApiManagement from version preview/2021-01-01-preview to version 2021-04-01-preview

* Updates readme

* Updates API version in new specs and examples

* Added support for GraphQL API type (Azure#14851)

* Added support for GraphQL API type

* Added missing enum value for GraphQL APIs.

* add schema definition fix from 2021-01-01-preview (Azure#14883)

Co-authored-by: Alan Feng <[email protected]>

* Vanguard: Get Outbound Network Dependency (Azure#14900)

* outbound dependency

* fix resource

* Update backup/restore API for managed identities (Azure#14973)

* Update backup/restore API for system-assigned and user-assigned identities

* Fix formatting issue

* Rename user-assigned-msi-client-id with client-id

* SystemData implemenation on API Management Control Plane (Azure#14899)

* system-data

* fix spec

* remove unreferenced file

* APIM - Network Watcher Connectivity Check integration specs (Azure#15056)

* Connectivity Check API Specs

* Fix

* Fix errors

* style fixs

* Fix 202 code

* HTTPConnect request parameters

* Fix errors

Co-authored-by: Nicolás Barrera <[email protected]>

* Parameter examples added (Azure#14836)

* platformversion (Azure#15114)

* fix update service (Azure#15478)

* HttpConnect example (Azure#15493)

* HttpConnect example

* Prettifier fix

Co-authored-by: Nicolás Barrera <[email protected]>

* Added properties of difference API spec format for "SchemaDocumentProperties" (Azure#15703)

* add schema definition fix from 2021-01-01-preview

* added properties for SchemaDocumentProperties

* updated the fix

* updated fix

* [APIM]Add private endpoint connection APIs (Azure#15115)

* Add private endpoint connection apis

* add readme

* quick fixes

* fix to PE contract

* Small fixes

* small fixes

* small fixes

* Small fixes

* small fixes

* small fix

* small fixes

* small fixes

* small fixes

* Update readme.md

* fix error

* small fix

* fix format

* address comments

* small fixes

* Change to lower case

* small fixes

Co-authored-by: msyyc <[email protected]>

* Adds base for updating Microsoft.ApiManagement from version preview/2021-01-01-preview to version 2021-04-01-preview

* Updates readme

* Updates API version in new specs and examples

* Added support for GraphQL API type (Azure#14851)

* Added support for GraphQL API type

* Added missing enum value for GraphQL APIs.

* add schema definition fix from 2021-01-01-preview (Azure#14883)

Co-authored-by: Alan Feng <[email protected]>

* Vanguard: Get Outbound Network Dependency (Azure#14900)

* outbound dependency

* fix resource

* Update backup/restore API for managed identities (Azure#14973)

* Update backup/restore API for system-assigned and user-assigned identities

* Fix formatting issue

* Rename user-assigned-msi-client-id with client-id

* SystemData implemenation on API Management Control Plane (Azure#14899)

* system-data

* fix spec

* remove unreferenced file

* APIM - Network Watcher Connectivity Check integration specs (Azure#15056)

* Connectivity Check API Specs

* Fix

* Fix errors

* style fixs

* Fix 202 code

* HTTPConnect request parameters

* Fix errors

Co-authored-by: Nicolás Barrera <[email protected]>

* Parameter examples added (Azure#14836)

* platformversion (Azure#15114)

* fix update service (Azure#15478)

* HttpConnect example (Azure#15493)

* HttpConnect example

* Prettifier fix

Co-authored-by: Nicolás Barrera <[email protected]>

* Added properties of difference API spec format for "SchemaDocumentProperties" (Azure#15703)

* add schema definition fix from 2021-01-01-preview

* added properties for SchemaDocumentProperties

* updated the fix

* updated fix

* [APIM]Add private endpoint connection APIs (Azure#15115)

* Add private endpoint connection apis

* add readme

* quick fixes

* fix to PE contract

* Small fixes

* small fixes

* small fixes

* Small fixes

* small fixes

* small fix

* small fixes

* small fixes

* small fixes

* Update readme.md

* fix error

* small fix

* fix format

* address comments

* small fixes

* Change to lower case

* small fixes

Co-authored-by: msyyc <[email protected]>

* fix tenant sync contract

* fix linter issues

* examples for managed identity backup

* prettier

* Fix Apis-Get and updated comments for api-version 2021-04-01-preview (#3)

* add schema definition fix from 2021-01-01-preview

* added fix

* small fix (#6)

* 'examples' added to RepresentationContract (#7)

Co-authored-by: Alexander Zaslonov <[email protected]>
Co-authored-by: DreamlessA <[email protected]>
Co-authored-by: Alan Feng <[email protected]>
Co-authored-by: Jatin Sanghvi <[email protected]>
Co-authored-by: Nicolás Barrera <[email protected]>
Co-authored-by: Nicolás Barrera <[email protected]>
Co-authored-by: VitaliyKurokhtin <[email protected]>
Co-authored-by: RupengLiu <[email protected]>
Co-authored-by: msyyc <[email protected]>
Co-authored-by: RupengLiu <[email protected]>
Co-authored-by: VitaliyKurokhtin <[email protected]>
ghost pushed a commit that referenced this pull request Sep 9, 2022
…3019)

### Packages impacted by this PR
core-util

### Issues associated with this PR
#15930 

### Describe the problem that is addressed by this PR
- Update "delay" in core-util to support abort message
- Unduplicate "delay" function in core-http and core-amqp

### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?
- Choose the implementation with "options" parameters to keep the flexibility in case we want to add extra functionality in the future 

### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_
#15832

### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_

### Checklists
- [x ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_
- [ ] Added a changelog (if necessary)
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App Configuration Azure.ApplicationModel.Configuration Azure.Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[core-http] Throttling retry policy should account for abortSignal
6 participants