azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

usage_details.list does not seem to filter by date

Open nancybelser opened this issue 6 years ago • 13 comments

  • Package Name: https://github.com/Azure/azure-sdk-for-python/tree/fd643a07a08f5ae912344c45f91ecd7278e9049b/sdk/consumption/azure-mgmt-consumption
  • Package Version:
  • Operating System: mac os
  • Python Version: 3.7.6

Describe the bug I wrote a script to get usage_details and filter by date.

def get_consumption(credentials, subscription_id, env): consumption_client = ConsumptionManagementClient(credentials,subscription_id,base_url=None)

scope = "\/subscriptions\/" + subscription_id + "\/"
print(scope)
date_filter ='usageStart gt '+ str('2020-02-03T00:00:00Z')
print(date_filter)

for item in consumption_client.usage_details.list(scope, filter=date_filter):
    #print("\tProduct: {}".format(item.product))
    print(item.date_property,",", item.meter_id, ",", item.name, ",", item.product,",", item.quantity, ",", item.effective_price, ",", item.cost,",", item.unit_price)
    #print (item)

To Reproduce Steps to reproduce the behavior:

  1. See code snipped

Expected behavior I expected the results to only return usage items where date_property matched the date filter. Instead I get everything for the February billing period.

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

Additional context You can see in the screenshot of results, I am getting items back before the start date of 2020-02-03.

nancybelser avatar Feb 04 '20 21:02 nancybelser

Anyone looking into this?

nancybelser avatar Feb 06 '20 14:02 nancybelser

@nancybelser thanks for following up, @nickzhums can you take a look at this

kaerm avatar Feb 06 '20 18:02 kaerm

@RodgeFu seems like the API behavior is not what the user expected, could you have someone take a look and double check. Thanks!

nickzhums avatar Feb 07 '20 01:02 nickzhums

The response is from consumption service, and we need consumption team's help

dw511214992 avatar Feb 07 '20 03:02 dw511214992

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

ghost avatar Feb 07 '20 03:02 ghost

Any updates on this issue?

nancybelser avatar Feb 11 '20 20:02 nancybelser

Hi @nancybelser thanks so much for the feedback and the patience. I'm working to route this issue to someone on the Consumption team. I apologize for the delay.

lilyjma avatar Feb 11 '20 21:02 lilyjma

@ms-premp please loop in the right people to take a look at the issue. Thanks!

lilyjma avatar Feb 12 '20 00:02 lilyjma

Any updates on this?

nancybelser avatar Feb 18 '20 14:02 nancybelser

@addesai please have a look... it looks like the filter is not passed in correctly.

ms-premp avatar Feb 18 '20 18:02 ms-premp

If the filter logic I am using is incorrect, can someone give me the correct syntax, please? Thanks.

nancybelser avatar Feb 25 '20 14:02 nancybelser

What I am gathering is the test case example I found in this repo is not a valid option for usage_details. def test_consumption_subscription_usage_filter(self): date_filter ='usageEnd le '+ str(MgmtConsumptionTest.endDate) pages = self.consumption_client.usage_details.list(expand='meterDetails', filter=date_filter, top=10) first_page = pages.advance_page() output = list(first_page) self.assertEqual(10, len(output)) self._validate_usage(output[0], include_meter_details=True)

Here is where I found the logic: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/consumption/azure-mgmt-consumption/tests/test_mgmt_consumption.py .

nancybelser avatar Feb 26 '20 19:02 nancybelser

@nancybelser apologies for bad examples. we will work on fixing those. Meanwhile, please use following as example on how to pass in date filters for calling consumption.

https://github.com/ms-premp/AzureConsumptionSamples/blob/master/Python_sdk/usage_details_list_python_sdk_example.py

Please note that API expects both start and end dates to be able to filter data as mentioned in following doc https://docs.microsoft.com/en-us/rest/api/consumption/#working-with-billing-periods-and-date-ranges

Hope this helps.

ms-premp avatar Feb 27 '20 09:02 ms-premp