Skip to content

Conversation

@danielortega-msft
Copy link
Member

@danielortega-msft danielortega-msft commented Mar 3, 2022

Packages impacted by this PR

  • @azure/communication-phone-numbers

Issues associated with this PR

Describe the problem that is addressed by this PR

Migrate the HTTP pipeline to the new architecture in Azure Core V2. Refer to the following documentation for more details: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-rest-pipeline/documentation/core2.md

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?

For information on the Core V2 migration, refer to: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-rest-pipeline/documentation/core2.md

This migration introduced the following two compatibility issues:

  • The phone numbers API uses relative URLs for nextLink values in endpoints that support paging, which is not supported out-of-the-box in the new client. While the current REST API guidelines state that they should be absolute URLs, this was introduced after the initial release of the API (for more details, see the PR discussion that introduced the change).
  • LROs in the phone numbers API have status-monitors given by the operation-location header; however, the @azure/core-lro implementation expects it to be in the legacy azure-asyncoperation header. While the current version of the guidelines discourage the later approach, they indicate that client code should look for both. For more details, refer to the Azure REST API guidelines.

In order to solve both issues, custom pipeline policies were implemented to make the HTTP responses have the form expected by the Core V2 libraries. These policies are workarounds and should be cleaned up once the incompatibilities are addressed.

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

Yes, the test cases for the policies implemented as workarounds for compatibility issues.

Provide a list of related PRs (if any)

Checklists

  • 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 repository and link it here)
  • Added a changelog (if necessary)

Replace usages of the old @azure/core-http package in favor of the Core V2 packages.

Also, update the autorest/typescript version to the latest beta to support generating clients using the new implementation.
The phoneNumbers API uses relative URLs for the `nextLink` value, which causes issues with the Azure Core V2 library.

To address this, a pipeline policy was implemented to transform any relative `nextLink` to absolute URLs.
The phoneNumbers API uses LROs with status monitors, as described in the following URL https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#long-running-operations-with-status-monitor.

However, the current implementation of the @azure/core-lro library only supports this pattern if the legacy `azure-asyncoperation` header is present in the response of the operation. Thus, as a workaround to this limitation, a pipeline policy was implemented that adds this header to the responses of LROs, setting it with the same value as the `operation-location` header.
@danielortega-msft
Copy link
Member Author

FYI, the following issue was created to track the LRO incompatibility: #20647

},
};

this.client = new PhoneNumbersGeneratedClient(url, {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I wasn't aware of that guide. I will update accordingly!

@danielortega-msft
Copy link
Member Author

@lucasrsant the phone number that is present in the recordings is actually the sanitized value. We even explicitly use it as a fake number in one of our tests: https://github.com/danielortega-msft/azure-sdk-for-js/blob/0b5233eec003cf06439612349d9023bf50fee51a/sdk/communication/communication-phone-numbers/test/public/get.spec.ts#L37.

You can check in the recorded client configuration that the actual phone numbers are replaced with it.

const replaceableVariables: { [k: string]: string } = {
  COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING: "endpoint=https://endpoint/;accesskey=banana",
  INCLUDE_PHONENUMBER_LIVE_TESTS: "false",
  SKIP_UPDATE_CAPABILITIES_LIVE_TESTS: "false",
  COMMUNICATION_ENDPOINT: "https://endpoint/",
  AZURE_CLIENT_ID: "SomeClientId",
  AZURE_CLIENT_SECRET: "azure_client_secret",
  AZURE_TENANT_ID: "SomeTenantId",
  AZURE_PHONE_NUMBER: "+14155550100",
  COMMUNICATION_SKIP_INT_PHONENUMBERS_TESTS: "false",
};

Address the following feedback from the PR:
- Remove the logic to generate the user agent
- Specify the new major version of Azure Core used
- Add integration tests between the PhoneNumbersClient and the custom policies implemented
@danielortega-msft
Copy link
Member Author

@jeremymeng @Automagically @lucasrsant I updated the PR based on your comments, can you please do another review?

@danielortega-msft danielortega-msft requested review from automagicaly, jeremymeng and lucasrsant and removed request for ramya-rao-a March 4, 2022 20:53
@deyaaeldeen
Copy link
Member

FYI, the following issue was created to track the LRO incompatibility: #20647

The LRO bug has been fixed and I will make a release on Monday, 3/7.

@azure-sdk
Copy link
Collaborator

API changes have been detected in @azure/communication-phone-numbers. You can review API changes here

API changes

- export interface PhoneNumbersClientOptions extends PipelineOptions { }
+ export interface PhoneNumbersClientOptions extends CommonClientOptions { }

Copy link
Member

@jeremymeng jeremymeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! I only have some minor comments.

skip-enum-validation: true
title: Phone Numbers Client
v3: true
use-core-v2: true
Copy link
Member

Choose a reason for hiding this comment

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

nit: use-core-v2 is true now by default so this is not needed.

*
* For more information on the LRO guidelines, refer to: https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#long-running-operations-with-status-monitor
*/
export const phoneNumbersLroPolicy: PipelinePolicy = {
Copy link
Member

Choose a reason for hiding this comment

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

maybe create a workitem to track removing this workaround when the LRO fix is available.

requestContentType: "application/json; charset=utf-8"
};

const packageDetails = `azsdk-js-azure-communication-phone-numbers/1.2.0-beta.2`;
Copy link
Member

Choose a reason for hiding this comment

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

The azure after azsdk-js- is probably from the package-name in swagger/README.md. Could you please use @azure/communication-phone-numbers instead?

@danielortega-msft
Copy link
Member Author

Looks good to me! I only have some minor comments.

Thanks for the feedback @jeremymeng. I will merge this PR for now and, once the LRO fix is released, I will create a new one addressing your comments.

@danielortega-msft danielortega-msft merged commit 512ec36 into Azure:main Mar 7, 2022
@danielortega-msft danielortega-msft deleted the feature/core-v2-phonenumbers branch March 7, 2022 19:57
WeiJun428 pushed a commit to WeiJun428/azure-sdk-for-js that referenced this pull request Mar 20, 2022
* Migrate to Azure Core V2

Replace usages of the old @azure/core-http package in favor of the Core V2 packages.

Also, update the autorest/typescript version to the latest beta to support generating clients using the new implementation.

* Fix purchased phone numbers pagination

The phoneNumbers API uses relative URLs for the `nextLink` value, which causes issues with the Azure Core V2 library.

To address this, a pipeline policy was implemented to transform any relative `nextLink` to absolute URLs.

* Workaround for LRO polling in phone-numbers sdk

The phoneNumbers API uses LROs with status monitors, as described in the following URL https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#long-running-operations-with-status-monitor.

However, the current implementation of the @azure/core-lro library only supports this pattern if the legacy `azure-asyncoperation` header is present in the response of the operation. Thus, as a workaround to this limitation, a pipeline policy was implemented that adds this header to the responses of LROs, setting it with the same value as the `operation-location` header.

* Fix skip condition for update capabilities tests

* Fix purchase and release tests, update recordings

* Add changelog entry

* Test integration of client and custom policies

Address the following feedback from the PR:
- Remove the logic to generate the user agent
- Specify the new major version of Azure Core used
- Add integration tests between the PhoneNumbersClient and the custom policies implemented

* Run all tests

* Add missing license header, lint code

* Make `PhoneNumbersClientOptions` extend `CommonClientOptions`

* Fix metadata paths
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.

6 participants