Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

New-AzCostManagementDetailReport returns CreateExpanded error when scoped to Management Group #21203

Open danielfears opened 1 year ago

danielfears commented 1 year ago

Description

Running the New-AzCostManagementDetailReport command and assigning a scope of a management group, as per

New-AzCostManagementDetailReport -Scope "providers/Microsoft.Management/managementGroups/MG" -Metric 'ActualCost' -BillingPeriod "202302"

Throws the following error:

"New-AzCostManagementDetailReport_CreateExpanded: Expected '{' or '['. Was String: The."

Not sure if intended, as the previous command of New-AzCostManagementExport can handle scope of Management Group.

Looks like it could be an issue with the function 'New-AzCostManagementDetailReport' within /src/CostManagement/exports/New-AzCostManagementDetailReport.ps1

Issue script & Debug output

New-AzCostManagementDetailReport -Scope "providers/Microsoft.Management/managementGroups/MG" -Metric 'ActualCost' -BillingPeriod "202302"

"New-AzCostManagementDetailReport_CreateExpanded: Expected '{' or '['. Was String: The."

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.2
PSEdition                      Core
GitCommitId                    7.3.2
OS                             Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.9.1                 Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script     0.3.0                 Az.CostManagement                   {Get-AzCostManagementExport, Get-AzCostManagementExportExecutionHistory, Invoke-AzCostManageme…

Error output

No response

isra-fel commented 1 year ago

Hi @LucasYao93 could you look into this issue? Thanks

LucasYao93 commented 1 year ago

@danielfears

Can you run the following command and copy the debug messages for me?

New-AzCostManagementDetailReport -Scope "providers/Microsoft.Management/managementGroups/MG" -Metric 'ActualCost' -BillingPeriod "202302" -Debug
danielfears commented 1 year ago

@LucasYao93 output as follows

DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:

Confirm
Are you sure you want to perform this action?
Performing the operation "New-AzCostManagementDetailReport_CreateExpanded" on target "Call remote 'GenerateCostDetailsReportCreateOperation' operation".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /providers/Microsoft.Management/managementGroups/MG/providers/Microsoft.CostManagement/generateCostDetailsReport?api-version=2022-05-01
DEBUG: RequestCreated: /providers/Microsoft.Management/managementGroups/MG/providers/Microsoft.CostManagement/generateCostDetailsReport?api-version=2022-05-01
DEBUG: HeaderParametersAdded:
DEBUG: BodyContentSet:
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
POST

Absolute Uri:
https://management.azure.com/providers/Microsoft.Management/managementGroups/MG/providers/Microsoft.CostManagement/generateCostDetailsReport?api-version=2022-05-01

Headers:
x-ms-unique-id                : 19
x-ms-client-request-id        : 3f97e65c-d8a8-48d7-a224-b647a1150e0c
CommandName                   : New-AzCostManagementDetailReport
FullCommandName               : New-AzCostManagementDetailReport_CreateExpanded
ParameterSetName              : __AllParameterSets
User-Agent                    : AzurePowershell/v7.0.0,PSVersion/v7.3.2,Az.CostManagement/0.3.0

Body:
{
  "metric": "ActualCost",
  "billingPeriod": "202302"
}

DEBUG: BeforeCall:
DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
NotFound

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
Server                        : Microsoft-IIS/10.0
X-Powered-By                  : ASP.NET
x-ms-ratelimit-remaining-tenant-reads: 11999
x-ms-request-id               : d0b9c624-9787-456f-82a8-04e1191be39d
x-ms-correlation-request-id   : d0b9c624-9787-456f-82a8-04e1191be39d
x-ms-routing-request-id       : UKSOUTH:20230316T152730Z:d0b9c624-9787-456f-82a8-04e1191be39d
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Date                          : Thu, 16 Mar 2023 15:27:30 GMT

Body:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
DEBUG: [Finally]: Cannot deserialize due to Unexpected character encountered while parsing value: T. Path '', line 0, position 0.
DEBUG: [Finally]: Getting exception 'Microsoft.Azure.Commands.Common.Exceptions.AzPSResourceNotFoundCloudException: InternalException' from response
DEBUG: Finally:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: [CmdletException]: Received Exception with message 'ParserException - Expected '{' or '['. Was String: The. :    at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Runtime.Json.JsonParser.ReadNode()
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Runtime.Json.JsonNode.Parse(SourceReader sourceReader)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Runtime.Json.JsonNode.Parse(String text)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.CostManagement.<>c.<GenerateCostDetailsReportCreateOperation_Call>b__58_1(Task`1 body)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Cmdlets.NewAzCostManagementDetailReport_CreateExpanded.onDefault(HttpResponseMessage responseMessage, Task`1 response)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.CostManagement.GenerateCostDetailsReportCreateOperation_Call(HttpRequestMessage request, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.CostManagement.GenerateCostDetailsReportCreateOperation_Call(HttpRequestMessage request, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.CostManagement.GenerateCostDetailsReportCreateOperation(String scope, IGenerateCostDetailsReportRequestDefinition body, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Cmdlets.NewAzCostManagementDetailReport_CreateExpanded.ProcessRecordAsync()
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Cmdlets.NewAzCostManagementDetailReport_CreateExpanded.ProcessRecordAsync()'
DEBUG: CmdletException: ParserException - Expected '{' or '['. Was String: The. :    at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Runtime.Json.JsonParser.ReadNode()
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Runtime.Json.JsonNode.Parse(SourceReader sourceReader)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Runtime.Json.JsonNode.Parse(String text)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.CostManagement.<>c.<GenerateCostDetailsReportCreateOperation_Call>b__58_1(Task`1 body)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Cmdlets.NewAzCostManagementDetailReport_CreateExpanded.onDefault(HttpResponseMessage responseMessage, Task`1 response)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.CostManagement.GenerateCostDetailsReportCreateOperation_Call(HttpRequestMessage request, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.CostManagement.GenerateCostDetailsReportCreateOperation_Call(HttpRequestMessage request, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.CostManagement.GenerateCostDetailsReportCreateOperation(String scope, IGenerateCostDetailsReportRequestDefinition body, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Cmdlets.NewAzCostManagementDetailReport_CreateExpanded.ProcessRecordAsync()
   at Microsoft.Azure.PowerShell.Cmdlets.CostManagement.Cmdlets.NewAzCostManagementDetailReport_CreateExpanded.ProcessRecordAsync()
New-AzCostManagementDetailReport_CreateExpanded: Expected '{' or '['. Was String: The.
DEBUG: CmdletProcessRecordEnd:
DEBUG: AzureQoSEvent: Module: Az.CostManagement:0.3.0; CommandName: New-AzCostManagementDetailReport; PSVersion: 7.3.2; IsSuccess: True; Duration: 00:00:16.4049147
LucasYao93 commented 1 year ago

@danielfears, According to the response body is a string. Base on the definition swagger of the service. The format of the response body should be Json string that as follows:

{
   'error': 'error message'
}

So, expected '{' or '[' error been thrown.

Gianlucas94 commented 1 year ago

I'm having the same error.

I Think in my side is related to the time between reports

lc-work commented 1 year ago

I'm getting the same error:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

when attempting to do a Cost Detail Report using a HTTP request with a Management Group scope:

https://learn.microsoft.com/en-us/rest/api/cost-management/generate-cost-details-report/create-operation?tabs=HTTP

None of the examples on that page use management groups, but it does mention that "other billing scopes" can be used for {scope}, which I would assume includes management groups. Maybe the new API doesn't allow them?

danielfears commented 1 year ago

@LucasYao93 any update on the above error being thrown?

You mentioned some disparity between a string and JSON value, could you elaborate?

Looks like some other people still experiencing this issue.

microsoft-github-policy-service[bot] commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @TiagoCrewGitHubIssues.