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

[Feature]: Get-AzSubscription with SubscriptionId parameter should internally only get a single subscription instead of listing all subs then searching #19115

Closed
kwill-MSFT opened this issue Aug 1, 2022 · 2 comments
Assignees
Labels
Accounts Issues in Az.Accounts except authentication related feature-request This issue requires a new behavior in the product in order be resolved. Tracking We will track status and follow internally

Comments

@kwill-MSFT
Copy link

Description of the new feature

When calling Get-AzSubscription using the SubscriptionId parameter:
Get-AzSubscription -SubscriptionId "123582cb-b98a-4200-a7a5-edee9045a123"

Internally, this executes (GetAzureRMSubscription.cs):
this._client.TryGetSubscriptionById(TenantId, this.SubscriptionId, out result)

TryGetSubscriptionById then executes (RMProfileClient.cs)
var subscriptionList = ListSubscriptions(tenantId).Where(s => s.GetId() == subscriptionIdGuid);

This has the effect of listing all subscriptions that the caller has access to, then finding the matching SubscriptionId. Given that a SubscriptionId is unique, there is no need to list them all then find the first matching one.

For a scenario where the caller has access to thousands of subscriptions, this consumes a lot of unnecessary time and resources since the code internally has to iterate over several nextLink results and call the /subscriptions API multiple times.

Proposed implementation details (optional)

TryGetSubscriptionById should instead utilize TryGetTenantSubscription, which does a single GET on a specific subscription.

This will significantly reduce the resource load on both the client and on ARM since there will be much less data returned and fewer API calls being made.

@kwill-MSFT kwill-MSFT added feature-request This issue requires a new behavior in the product in order be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Aug 1, 2022
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Aug 1, 2022
@dingmeng-xue dingmeng-xue added the Accounts Issues in Az.Accounts except authentication related label Aug 2, 2022
@dingmeng-xue dingmeng-xue added this to the October 2022 (2022-10-04) milestone Aug 2, 2022
@dingmeng-xue dingmeng-xue removed this from the October 2022 (2022-10-04) milestone Aug 2, 2022
@dingmeng-xue
Copy link
Member

Thanks for reporting. Target to October. Let me set milestone after internal discussion.

@dingmeng-xue dingmeng-xue added the Tracking We will track status and follow internally label Oct 8, 2022
msJinLei added a commit to msJinLei/azure-powershell that referenced this issue Oct 10, 2022
msJinLei added a commit to msJinLei/azure-powershell that referenced this issue Oct 11, 2022
msJinLei added a commit to msJinLei/azure-powershell that referenced this issue Oct 12, 2022
msJinLei added a commit that referenced this issue Oct 14, 2022
#19762)

* Retreive subscription by id from server if subscription id is provided

#19115

* Fix failed test cases

* Try to fix the test cases

* Update ChangeLog.md

Co-authored-by: Yabo Hu <[email protected]>
@msJinLei
Copy link
Contributor

Resolved in Az.Accounts 2.10.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accounts Issues in Az.Accounts except authentication related feature-request This issue requires a new behavior in the product in order be resolved. Tracking We will track status and follow internally
Projects
None yet
Development

No branches or pull requests

3 participants