Azure / azure-cli

Azure Command-Line Interface
MIT License
3.98k stars 2.95k forks source link

Usage start error using az consumption usage list on Azure CLI version 2.57.0 #28323

Open raim4033 opened 7 months ago

raim4033 commented 7 months ago

Describe the bug

az consumption usage list --start-date 2021-10-01 --end-date 2021-11-01 This command is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus The command failed with an unexpected error. Here is the traceback: 'usageStart' Traceback (most recent call last): File "/home/raimond/.local/lib/python3.8/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 664, in execute raise ex File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 729, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 711, in _run_job result = list(result) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/aaz/_paging.py", line 87, in next return next(self._page_iterator) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/aaz/_paging.py", line 46, in next curr_page, self._next_link = self._extract_result() File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in _output result = list([transform_usage_output(item) for item in result]) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in result = list([transform_usage_output(item) for item in result]) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/command_modules/consumption/custom.py", line 95, in transform_usage_output usageStart = parser.parse(result['usageStart']) KeyError: 'usageStart' To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

Related command

az consumption usage list

Errors

The command failed with an unexpected error. Here is the traceback: 'usageStart' Traceback (most recent call last): File "/home/raimond/.local/lib/python3.8/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 664, in execute raise ex File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 729, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 711, in _run_job result = list(result) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/aaz/_paging.py", line 87, in next return next(self._page_iterator) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/aaz/_paging.py", line 46, in next curr_page, self._next_link = self._extract_result() File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in _output result = list([transform_usage_output(item) for item in result]) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in result = list([transform_usage_output(item) for item in result]) File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/command_modules/consumption/custom.py", line 95, in transform_usage_output usageStart = parser.parse(result['usageStart']) KeyError: 'usageStart' To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

Issue script & Debug output

debug1.txt

Expected behavior

Result from az consumption list

Environment Summary

azure-cli 2.57.0 core 2.57.0 telemetry 1.1.0 Extensions: account 0.2.5 aks-preview 1.0.0b5 application-insights 1.2.0 costmanagement 0.3.0 rdbms-connect 1.0.4 resource-graph 2.1.0 storage-preview 1.0.0b1 virtual-wan 0.3.0

Dependencies: msal 1.26.0 azure-mgmt-resource 23.1.0b2

Python location '/usr/bin/python3' Extensions directory '/home/raimond/.azure/cliextensions'

Python (Linux) 3.8.10 (default, Nov 22 2023, 10:22:35) [GCC 9.4.0]

Your CLI is up-to-date

Additional context

No response

yonzhan commented 7 months ago

Thank you for opening this issue, we will look into it.

triatic commented 7 months ago

Same issue here.

PS C:\> az consumption usage list --start-date 2024-01-01 --end-date 2024-02-01
This command is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
The command failed with an unexpected error. Here is the traceback:
'usageStart'
Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 664, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 729, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 711, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/aaz/_paging.py", line 87, in __next__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/aaz/_paging.py", line 46, in __next__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/consumption/custom.py", line 85, in _output
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/consumption/custom.py", line 85, in <listcomp>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/consumption/custom.py", line 95, in transform_usage_output
KeyError: 'usageStart'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
orangesharing commented 7 months ago

hi Everyone - I can confirm the same issue.

I am currently running some tests using Azure DevOps Pipelines, and have prepared a pipeline that runs two jobs in parallel, both run the following command against two different subscriptions (service connections) under the same tenant:

        az consumption usage list
        --billing-period-name $(lastMonth)
        --include-additional-properties
        --include-meter-details
        --query "[].[instanceId, consumedService, instanceName, instanceLocation, product, pretaxCost, usageStart, usageEnd]"
        --output tsv

I ran this command 6 times within the span of about 40 minutes:

Hope that sheds a bit of light and helps your troubleshooting efforts.

aglazer7 commented 7 months ago

urllib3.connectionpool: https://management.azure.com:443 "GET /subscriptions/895cda87-06a5-4a91-b04c-d023ccbc6525/providers/Microsoft.Consumption/usageDetails?$filter=properties%2FusageEnd%20ge%20%272024-01-08T00%3A00%3A00Z%27%20and%20properties%2FusageEnd%20le%20%272024-01-09T00%3A00%3A00Z%27&$top=1&api-version=2023-05-01 HTTP/1.1" 200 2976 cli.azure.cli.core.sdk.policies: Response status: 200

Looks like it gives the response, but a closer look at the url shows that there's 2x usageEnd. First one should be of course usageStart.

RahulSrivastav14 commented 6 months ago

I've been facing this issue with my workflow that checks for the az consumption usage list :

ERROR: The command failed with an unexpected error. Here is the traceback:
ERROR: 'usageStart'
Traceback (most recent call last):
  File "/opt/az/lib/python3.[11](https://github.com/turbotio/ops/actions/runs/8277743509/job/22648667583#step:6:12)/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
    raise ex
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 7[14](https://github.com/turbotio/ops/actions/runs/8277743509/job/22648667583#step:6:15), in _run_job
    result = list(result)
             ^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/aaz/_paging.py", line 87, in __next__
    return next(self._page_iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/aaz/_paging.py", line 46, in __next__
    curr_page, self._next_link = self._extract_result()
                                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in _output
    result = list([transform_usage_output(item) for item in result])
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in <listcomp>
    result = list([transform_usage_output(item) for item in result])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/command_modules/consumption/custom.py", line 95, in transform_usage_output
    usageStart = parser.parse(result['usageStart'])
                              ~~~~~~^^^^^^^^^^^^^^
rabe1 commented 5 months ago

I can confirm that the error still exists also in latest Azure CLI version 2.58.0. Are there meanwhile any updates on this or a workaround to make this work again? It's really bad not to be able to retrieve the detailled cost consumption per ressource via this simple CLI query since meanwhile more than a month.

agnaldocarmo commented 5 months ago

I'm facing the same issue using Azure CLI version 2.58.0

Hymian7 commented 5 months ago

I am also facing the issue in az version { "azure-cli": "2.58.0", "azure-cli-core": "2.58.0", "azure-cli-telemetry": "1.1.0", "extensions": {} }

tenjaa commented 5 months ago

As a workaround you can try an older version

docker run -it mcr.microsoft.com/azure-cli:2.56.0
tworthington commented 4 months ago

Still there in 2.61.0

FlorianDp commented 1 month ago

Experiencing it on 2.62.0 as well. az version { "azure-cli": "2.62.0", "azure-cli-core": "2.62.0", "azure-cli-telemetry": "1.1.0", "extensions": { "ai-examples": "0.2.5", "costmanagement": "0.3.0", "ml": "2.28.0", "ssh": "2.0.4" } }

CookCountyTreasurer commented 1 month ago

Same here on...

az version { "azure-cli": "2.62.0", "azure-cli-core": "2.62.0", "azure-cli-telemetry": "1.1.0", "extensions": { "ai-examples": "0.2.5", "ml": "2.28.0", "ssh": "2.0.4" } }

BenjamenJoubert commented 1 month ago

I might have found the issue on the following line: https://github.com/Azure/azure-cli/blob/29564830498870c401679e0059fddbbf5851f10c/src/azure-cli/azure/cli/command_modules/consumption/custom.py#L78

The above line reads as follows:

filter_from = "properties/usageEnd ge \'{}\'".format(start_date.strftime("%Y-%m-%dT%H:%M:%SZ"))

Note that in the above line the filter from is using usageEnd instead of usageStart.

The fixed line should read as follows:

filter_from = "properties/usageStart ge \'{}\'".format(start_date.strftime("%Y-%m-%dT%H:%M:%SZ"))

Is there someone around who can test the above code changes?

petdance commented 1 month ago

While the usageEnd/usageStart noted above seems to indeed be a problem, I patched it manually on my install (now 2.63.0) and this error still happens.

Down in the transform_error_output where the error happens, I added a dump of results and it doesn't have the usageStart and usageEnd the code is looking for, or any of the other keys the function wants. The output looks like this:

{
  "id": "...",
  "name": "...",
  "accountName": "...",
  "consumedService": "...",
  "costCenter": "...",
  "meterId": "...",
  "product": "...",
  "subscriptionName": "...",
  "tags": {
    "..."
  },
  "type": "..."
}