Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.27k stars 3.87k forks source link

Bad examples for `Invoke-AzCostManagementQuery` #26204

Open odegroot opened 1 month ago

odegroot commented 1 month ago

Type of issue

Code doesn't work

Feedback

People would use Invoke-AzCostManagementQuery to retrieve cost information, but the listed examples do not return any actual cost data. This is due to the way the underlying API is designed: if you don't request any aggregations, then you just get empty response rows.

For contrast, here's an API request as sent by the Azure Portal. Notice the aggregation property.

POST https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.CostManagement/query?api-version=2021-10-01&$top=5000
{
  "type": "ActualCost",
  "dataSet": {
    "granularity": "None",
    "aggregation": {
      "totalCost": {
        "name": "Cost",
        "function": "Sum"
      },
      "totalCostUSD": {
        "name": "CostUSD",
        "function": "Sum"
      }
    },
    "grouping": [
      {
        "type": "Dimension",
        "name": "ResourceGroupName"
      },
      {
        "type": "Dimension",
        "name": "ChargeType"
      },
      {
        "type": "Dimension",
        "name": "PublisherType"
      }
    ]
  },
  "timeframe": "Custom",
  "timePeriod": {
    "from": "2024-09-01T00:00:00+00:00",
    "to": "2024-09-30T23:59:59+00:00"
  }
}

Mimicking that API call, here's an example for Invoke-AzCostManagementQuery that does return cost data:

Invoke-AzCostManagementQuery -Scope /subscriptions/00000000-0000-0000-0000-000000000000 -Timeframe MonthToDate -Type ActualCost -DatasetGranularity 'Monthly' -DatasetAggregation @{ 'totalCost' = @{ 'name' = 'Cost' } }
Column                         Row
------                         ---
{Cost, BillingMonth, Currency} {1.54425705929919 01 Sept 2024 00:00:00 EUR}

Could you update the docs to list more helpful examples?

Related: #20749

Page URL

https://learn.microsoft.com/en-us/powershell/module/az.costmanagement/invoke-azcostmanagementquery?view=azps-12.3.0&viewFallbackFrom=azps-10.4.1

Content source URL

https://github.com/Azure/azure-powershell/blob/main/src/CostManagement/CostManagement/help/Invoke-AzCostManagementQuery.md

Author

@mikefrobbins

Document Id

3dff2f6a-7cc0-e478-2079-8a417fc895dd

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

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