Azure / Azure/azure-powershell
Get-AzConsumptionUsageDetail can't talk to Azure China due to out-of-date API version
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 54
Description
### Description
Attempting to query consumption usage for Azure China fails with InvalidResourceType, saying:
"The resource type 'UsageDetails' could not be found in the namespace 'Microsoft.Consumption' for api version '2018-01-31'. The supported api-versions are '2021-10-01,2023-03-01'."
### Issue script & Debug output
```PowerShell
PS> Get-AzConsumptionUsageDetail -Top 10 -Debug
DEBUG: 11:44:35 AM - GetAzureRmConsumptionUsageDetail begin processing with ParameterSet 'Subscription'.
DEBUG: 11:44:35 AM - using account id '212300984@geaviationchina.partner.onmschina.cn'...
DEBUG: 11:44:35 AM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: [Common.Authentication]: Authenticating using Account: '212300984@geaviationchina.partner.onmschina.cn', environment: 'AzureChinaCloud', tenant: 'e3edb652-81cd-428c-97b8-e839b26849ec'
DEBUG: 11:44:35 AM - [ConfigManager] Got nothing from [DisableInstanceDiscovery], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 11:44:35 AM - [ConfigManager] Got nothing from [EnableLoginByWam], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 11:44:35 AM - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'e3edb652-81cd-428c-97b8-e839b26849ec', Scopes:'https://management.core.chinacloudapi.cn//.default', AuthorityHost:'https://login.chinacloudapi.cn/', UserId:'212300984@geaviationchina.partner.onmschina.cn'
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.chinacloudapi.cn//.default ] ParentRequestId:
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - b9a80a9c-ef0e-4c73-9ae7-f10e8a8c4938] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - b9a80a9c-ef0e-4c73-9ae7-f10e8a8c4938] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - b9a80a9c-ef0e-4c73-9ae7-f10e8a8c4938] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - b9a80a9c-ef0e-4c73-9ae7-f10e8a8c4938] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - b9a80a9c-ef0e-4c73-9ae7-f10e8a8c4938] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z] Found 1 cache accounts and 0 broker accounts
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z] Returning 1 accounts
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29] MSAL MSAL.CoreCLR with assembly version '4.56.0.0'. CorrelationId(04cce3a6-0bdc-4622-a537-64ca1fe9fe29)
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29] === AcquireTokenSilent Parameters ===
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29] LoginHint provided: False
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29] Account provided: True
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29] ForceRefresh: False
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29]
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.chinacloudapi.cn//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29
UserAssertion set: False
LongRunningOboCacheKey set: False
Region configured:
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29] === Token Acquisition (SilentRequest) started:
Scopes: https://management.core.chinacloudapi.cn//.default
Authority Host: login.chinacloudapi.cn
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29] Access token is not expired. Returning the found cache entry. [Current time (04/11/2024 16:44:35) - Expiration Time (04/11/2024 17:24:03 +00:00) - Extended Expiration Time (04/11/2024 17:24:03 +00:00)]
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29] Returning access token found in cache. RefreshOn exists ? False
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29]
=== Token Acquisition finished successfully:
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 6.0.8 Microsoft Windows 10.0.19045 [2024-04-11 16:44:35Z - 04cce3a6-0bdc-4622-a537-64ca1fe9fe29] AT expiration time: 4/11/2024 5:24:03 PM +00:00, scopes: https://management.core.chinacloudapi.cn//user_impersonation https://management.core.chinacloudapi.cn//.default. source: Cache
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.chinacloudapi.cn//.default ] ParentRequestId: ExpiresOn: 2024-04-11T17:24:03.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: 'e3edb652-81cd-428c-97b8-e839b26849ec', UserId: '212300984@geaviationchina.partner.onmschina.cn'
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.chinacloudapi.cn/subscriptions/18d97fcf-ccbe-4698-abfd-918758b63092/providers/Microsoft.Consumption/usageDetails?$top=10&api-version=2018-01-31
Headers:
x-ms-client-request-id : 394303ef-9ddb-46a0-b37a-10af3ae5f010
Accept-Language : en-US
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
NotFound
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-failure-cause : gateway
x-ms-request-id : 20309902-4e16-48e0-9b5c-2d436dbbbc93
x-ms-correlation-request-id : 20309902-4e16-48e0-9b5c-2d436dbbbc93
x-ms-routing-request-id : CHINANORTH3:20240411T164435Z:20309902-4e16-48e0-9b5c-2d436dbbbc93
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Date : Thu, 11 Apr 2024 16:44:35 GMT
Body:
{
"error": {
"code": "InvalidResourceType",
"message": "The resource type 'UsageDetails' could not be found in the namespace 'Microsoft.Consumption' for api version '2018-01-31'. The supported api-versions are '2021-10-01,2023-03-01'."
}
}
DEBUG: 11:44:35 AM - [ConfigManager] Got nothing from [DisableErrorRecordsPersistence], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 11:44:35 AM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
Get-AzConsumptionUsageDetail: Operation returned an invalid status code 'NotFound'
DEBUG: 11:44:35 AM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 11:44:35 AM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 11:44:35 AM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 11:44:35 AM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.Billing:2.0.3; CommandName: Get-AzConsumptionUsageDetail; PSVersion: 7.2.6; IsSuccess: False; Duration: 00:00:00.3762594; Exception: Operation returned an invalid status code 'NotFound';
DEBUG: 11:44:35 AM - GetAzureRmConsumptionUsageDetail end processing.
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 7.2.6
PSEdition Core
GitCommitId 7.2.6
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Module versions
```PowerShell
ModuleType Version PreRelease Name
---------- ------- ---------- ----
Script 2.17.0 Az.Accounts
Script 2.0.3 Az.Billing
```
### Error output
```PowerShell
Get-AzConsumptionUsageDetail: Operation returned an invalid status code 'NotFound'
```
Contributor guide
Research direction
Start at the Get-AzConsumptionUsageDetail cmdlet and trace how its request selects the API version for AzureChinaCloud. Reproduce the shown request with -Debug, then verify the command uses one of the supported Microsoft.Consumption versions and successfully returns usage details.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, powershell
- Domain
- api, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100