Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.44k stars 2.75k forks source link

CostManagementClient does not return tags associated with resource groups #36366

Open ash-dey-sa opened 1 month ago

ash-dey-sa commented 1 month ago

Describe the bug CostManagementClient does not return tags associated with resource groups

To Reproduce Steps to reproduce the behavior:

  1. Run CostManagementClient with the following query.

    {
    "type":"ActualCost",
    "dataSet":{
    
       "aggregation":{
         "consumedquantities":{
            "name":"UsageQuantity",
            "function":"Sum"
         },
         "totalCostUSD":{
            "name":"PreTaxCostUSD",
            "function":"Sum"
         }
      },
      "granularity":"none",
      "grouping":[
         {
            "type":"Dimension",
            "name":"ResourceGroupName"
         },
         {
            "type":"Dimension",
            "name":"SubscriptionName"
         }
      ],
      "include":[
         "Tags"
      ]
    },
    "timeframe":"Custom",
    "timePeriod":{
      "from":"from_time",
      "to":"to_time"
    }
    }

The type column output I get

'columns': [<azure.mgmt.costmanagement.models._models_py3.QueryColumn object at 0x7f757ca238d0>, <azure.mgmt.costmanagement.models._models_py3.QueryColumn object at 0x7f757ca23950>, <azure.mgmt.costmanagement.models._models_py3.QueryColumn object at 0x7f757ca23990>, <azure.mgmt.costmanagement.models._models_py3.QueryColumn object at 0x7f757ca239d0>, <azure.mgmt.costmanagement.models._models_py3.QueryColumn object at 0x7f757ca23a10>]

Expected behavior The column output should be as per below (which can be validated from API play ground in Azure portal by running the same query with latest API version i.e. "2023-11-01"). the scope /subscriptions/{subscription_id}/providers/Microsoft.CostManagement/query?api-version=2023-11-01


 "columns": [
      {
        "name": "UsageQuantity",
        "type": "Number"
      },
      {
        "name": "PreTaxCostUSD",
        "type": "Number"
      },
      {
        "name": "ResourceGroupName",
        "type": "String"
      },
      {
        "name": "SubscriptionName",
        "type": "String"
      },
      {
        "name": "Tags",
        "type": "Array"
      },
      {
        "name": "Currency",
        "type": "String"
      }
    ]

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Tried to run the cost management client by specifying the latest version of API, but still does not work. cost_management_client = CostManagementClient(credential=cost_credential, api_version="2023-11-01")

pvaneck commented 1 month ago

Hey, thanks for the issue. Seems like you are getting Python objects QueryColumn which have the name and type properties when you expect the JSON/dict representation of it (i.e. the Python object deserialized) in the response?

@msyyc Is this expected?

ash-dey-sa commented 1 month ago

@pvaneck, the primary problem due to the bug is the JSON output returned by the query is missing all the tags for the resource groups. Other information seems to be returned as expected i.e. resource group name, subscription name, costs etc. Expected out put should include an array of each resource group tags along with other values specified above.

msyyc commented 1 month ago

@ChenxiJiang333 Please help on this issue

ChenxiJiang333 commented 1 month ago

got it

ChenxiJiang333 commented 1 month ago

Hi @ash-dey-sa, the issue occurs because the model QueryDataset does not have the property include, which caused serialization bug to build the correct request body. And since SDKs is auto generated by swagger definitions, I have opened issue https://github.com/Azure/azure-rest-api-specs/issues/29719 to request an update for the swagger. Once the swagger is updated, python would release a new version to fix the issue.

ash-dey-sa commented 1 month ago

Look forward to the bug fix. Thank you for your help.

ChenxiJiang333 commented 1 month ago

Hope we can have a quick response.