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

consumption SDK usage_details.list does not filter by date

Open izilic333 opened this issue 5 years ago • 8 comments

  • Package Name: https://github.com/Azure/azure-sdk-for-python/tree/fd643a07a08f5ae912344c45f91ecd7278e9049b/sdk/consumption/azure-mgmt-consumption
  • Package Version: 3.0.0, 8.0.0b1, 8.0.0
  • Operating System: linux (ubuntu)
  • Python Version: 3.8.10

Describe the bug We are developing a new feature and we use the Azure SDK Consumption client to fetch data from azure.

To Reproduce Steps to reproduce the behavior:

from azure.mgmt.consumption import ConsumptionManagementClient

from azure.identity import ClientSecretCredential

credential = ClientSecretCredential(tenant_id=account_number, client_id=access_key, client_secret=secret)

subscription_id = "some_subscription_id"

consumption_client = ConsumptionManagementClient(credential, subscription_id)
date_filter = "properties/usageStart ge '2021-05-01' AND properties/usageStart lt '2021-02-27'"
data_list = consumption_client.usage_details.list(scope='/subscriptions/subscription_id', filter=date_filter)
data = [item.as_dict() for item in data_list]

print(data)

if we use the filter from the azure consumption SDK test: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/consumption/azure-mgmt-consumption/tests/test_mgmt_consumption.py

for example: endDate = '2021-05-28T00:00:00Z' date_filter ='usageEnd le '+ str(endDate) following this example: Selection_110

and after that, the same thing, we don't get results for the required period, instead, we get everything for June.

These DateTime filters do not work on azure python SDK Consumption client and usage_details.list()

Expected behavior I expected the results to only return usage items where date_property matched the date filter. Instead, I get everything for June (I guess always returns everything for the current month, and the consumption client seems to simply ignore the DateTime range filters).

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

Selection_109

Additional context Add any other context about the problem here.

izilic333 avatar Jun 30 '21 13:06 izilic333

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

Issue Details
  • Package Name: https://github.com/Azure/azure-sdk-for-python/tree/fd643a07a08f5ae912344c45f91ecd7278e9049b/sdk/consumption/azure-mgmt-consumption
  • Package Version: 3.0.0, 8.0.0b1, 8.0.0
  • Operating System: linux (ubuntu)
  • Python Version: 3.8.10

Describe the bug We are developing a new feature and we use the Azure SDK Consumption client to fetch data from azure.

To Reproduce Steps to reproduce the behavior:

from azure.mgmt.consumption import ConsumptionManagementClient

from azure.identity import ClientSecretCredential

credential = ClientSecretCredential(tenant_id=account_number, client_id=access_key, client_secret=secret)

subscription_id = "some_subscription_id"

consumption_client = ConsumptionManagementClient(credential, subscription_id)
date_filter = "properties/usageStart ge '2021-05-01' AND properties/usageStart lt '2021-02-27'"
data_list = consumption_client.usage_details.list(scope='/subscriptions/subscription_id', filter=date_filter)
data = [item.as_dict() for item in data_list]

print(data)

if we use the filter from the azure consumption SDK test: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/consumption/azure-mgmt-consumption/tests/test_mgmt_consumption.py

for example: endDate = '2021-05-28T00:00:00Z' date_filter ='usageEnd le '+ str(endDate) following this example: Selection_110

and after that, the same thing, we don't get results for the required period, instead, we get everything for June.

These DateTime filters do not work on azure python SDK Consumption client and usage_details.list()

Expected behavior I expected the results to only return usage items where date_property matched the date filter. Instead, I get everything for June (I guess always returns everything for the current month, and the consumption client seems to simply ignore the DateTime range filters).

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

Selection_109

Additional context Add any other context about the problem here.

Author: izilic333
Assignees: -
Labels:

Consumption, Mgmt, Service Attention, bug, customer-reported

Milestone: -

ghost avatar Jul 06 '21 15:07 ghost

Thanks for your feedback, we'll investigate asap.

kristapratico avatar Jul 06 '21 15:07 kristapratico

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

Issue Details
  • Package Name: https://github.com/Azure/azure-sdk-for-python/tree/fd643a07a08f5ae912344c45f91ecd7278e9049b/sdk/consumption/azure-mgmt-consumption
  • Package Version: 3.0.0, 8.0.0b1, 8.0.0
  • Operating System: linux (ubuntu)
  • Python Version: 3.8.10

Describe the bug We are developing a new feature and we use the Azure SDK Consumption client to fetch data from azure.

To Reproduce Steps to reproduce the behavior:

from azure.mgmt.consumption import ConsumptionManagementClient

from azure.identity import ClientSecretCredential

credential = ClientSecretCredential(tenant_id=account_number, client_id=access_key, client_secret=secret)

subscription_id = "some_subscription_id"

consumption_client = ConsumptionManagementClient(credential, subscription_id)
date_filter = "properties/usageStart ge '2021-05-01' AND properties/usageStart lt '2021-02-27'"
data_list = consumption_client.usage_details.list(scope='/subscriptions/subscription_id', filter=date_filter)
data = [item.as_dict() for item in data_list]

print(data)

if we use the filter from the azure consumption SDK test: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/consumption/azure-mgmt-consumption/tests/test_mgmt_consumption.py

for example: endDate = '2021-05-28T00:00:00Z' date_filter ='usageEnd le '+ str(endDate) following this example: Selection_110

and after that, the same thing, we don't get results for the required period, instead, we get everything for June.

These DateTime filters do not work on azure python SDK Consumption client and usage_details.list()

Expected behavior I expected the results to only return usage items where date_property matched the date filter. Instead, I get everything for June (I guess always returns everything for the current month, and the consumption client seems to simply ignore the DateTime range filters).

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

Selection_109

Additional context Add any other context about the problem here.

Author: izilic333
Assignees: msyyc
Labels:

Consumption, Consumption-UsageDetailsandExport, Mgmt, Service Attention, bug, customer-reported

Milestone: -

ghost avatar Jul 08 '21 00:07 ghost

Here is one way you can monkey patch the client to work around this omission in the SDK. Is there a better workaround?

  filter_date = "2021-08-01"

  # Monkey patch client to include startDate and endDate in URL

  url_parts = list(urlparse.urlparse(client.usage_details.list.metadata['url']))
  query = {"startDate": filter_date, "endDate": filter_date}
  url_parts[4] = urlencode(query)
  client.usage_details.list.metadata['url'] = urlparse.urlunparse(url_parts)

The above example will retrieve one day's worth of records for 2021-08-01.

conzyor34 avatar Aug 10 '21 20:08 conzyor34

Here is one way you can monkey patch the client to work around this omission in the SDK. Is there a better workaround?

  filter_date = "2021-08-01"

  # Monkey patch client to include startDate and endDate in URL

  url_parts = list(urlparse.urlparse(client.usage_details.list.metadata['url']))
  query = {"startDate": filter_date, "endDate": filter_date}
  url_parts[4] = urlencode(query)
  client.usage_details.list.metadata['url'] = urlparse.urlunparse(url_parts)

The above example will retrieve one day's worth of records for 2021-08-01.

Thanks for this monkey patch! With this at least we can use SDK instead of plain API.

mpremus avatar Aug 16 '21 09:08 mpremus

we are working on validating the newer version of python sdk for cost management. will update once the validation is completed and released.

TiagoCrewGitHubIssues avatar Oct 14 '21 01:10 TiagoCrewGitHubIssues

Hi @izilic333. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.

ghost avatar Dec 15 '21 08:12 ghost

Hi @izilic333, since you haven’t asked that we “/unresolve” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve” to reopen the issue.

ghost avatar Dec 22 '21 10:12 ghost