Skip to content

[BUG Bash] Bug in usage operation of CostManagementClient #15312

Description

Describe the bug
Inside QueryFilter key dimension should be dimensions: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/costmanagement/azure-mgmt-costmanagement/azure/mgmt/costmanagement/models/_models_py3.py#L811

Exception or Stack Trace

ErrorResponseException                    Traceback (most recent call last)
<ipython-input-22-225ed7001742> in <module>
     17 # Query
     18 q_definition = QueryDefinition(type='ActualCost', timeframe='Custom', time_period=q_period, dataset=ds_defintion)
---> 19 results = costmanagement_client.query.usage(scope=f'/subscriptions/{SUBSCRIPTION_ID}', parameters=q_definition)
     20 print(list(results.rows)[0][0])

~/.local/my_proj/lib/python3.8/site-packages/azure/mgmt/costmanagement/operations/_query_operations.py in usage(self, scope, parameters, custom_headers, raw, **operation_config)
    108         response = self._client.send(request, stream=False, **operation_config)
    109 
--> 110         if response.status_code not in [200]:
    111             raise models.ErrorResponseException(self._deserialize, response)
    112 

ErrorResponseException: (BadRequest) Invalid query definition: Invalid dataset filter; on a QueryFilter one and only one of and/or/not/dimension/tag can be set.

 (Request ID: xx-xx-xx)

To Reproduce
Steps to reproduce the behavior:

Code Snippet

from_ts = '2020-11-07T00:00:00+00:00'
to_ts = '2020-11-13T23:59:59+00:00'
resourceGroupName = 'my_resource'

# Aggregation
q_aggregation = QueryAggregation(name='Cost', function='Sum')
# Dimension
dim = QueryComparisonExpression(name='ResourceGroupName', operator='In', values=[resourceGroupName])
# Filter
q_filter = QueryFilter(dimension=dim, dimensions=dim)
# Query
ds_defintion = QueryDataset(aggregation={'totalCost': q_aggregation}, granularity='None', filter=q_filter)
# Date Filter
q_period = QueryTimePeriod(from_property=from_ts, to=to_ts)
# Query
q_definition = QueryDefinition(type='ActualCost', timeframe='Custom', time_period=q_period, dataset=ds_defintion)
results = costmanagement_client.query.usage(scope=f'/subscriptions/{SUBSCRIPTION_ID}', parameters=q_definition)
print(list(results.rows)[0][0])

Expected behavior

Return a number which is cost in USD

Setup (please complete the following information):

  • Python Version: Python 3.8
  • SDK Version: azure-mgmt-resource==10.2.0 (but present in master as well)

Additional context
I compared the portal AJAX Request and found dimensions rather than dimension

Information Checklist

Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Metadata

Metadata

Labels

MgmtThis issue is related to a management-plane library.Service AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-author-feedbackWorkflow: More information is needed from author to address the issue.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions