Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async fetching of cost data #26

Closed
spaelling opened this issue May 1, 2023 · 2 comments
Closed

Async fetching of cost data #26

spaelling opened this issue May 1, 2023 · 2 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@spaelling
Copy link

I have built and maintained, and rewritten, the logic for fetching and processing cost data for a few years, so I am quite intimate with these APIs, and one major issue is that getting larger amounts of data is painfully slow.

This is both due to using pagination, and that JSON is very inefficient as a large portion of the raw data fetched are json properties.

There is a much less known and poorly documented (I have had the cost management team confirm this is officially supported) way of getting large amounts of data. The endpoint looks something like below. basically just appending /download

/subscriptions/000-000-000-000-000/providers/Microsoft.Consumption/usageDetails/download?api-version=2019-10-01&metric=AmortizedCost&ln=en&startDate=2023/01/01&endDate=2023/05/01

What happens is that you get an immediate response and in the response headers the one called location contains a uri that keeps track of an async operation that is generating a csv file. You can poll this every few seconds, and eventually it will provide a link to a the csv (it uses a SAS token in a storage account).

(you could try it out in Postman or similar to get a feel of the speed)

You would then have to download the csv file and parse the data.

You would probably need some sort of logic to determine if this method is faster than getting it as json and using pagination, or maybe just a switch in the cli call.

My C# is very rusty, but would be happy to assist otherwise.

@mivano
Copy link
Owner

mivano commented May 2, 2023

Thanks for the suggestion. At the moment, the calls are performant enough for me. But I can imagine I or someone else will easily run into this issue. I do notice some rate limiting once in a while though.

Might be a nice option to offer both API calls as an option. I will have a play with it soon.

@mivano mivano added the enhancement New feature or request label May 2, 2023
@stale stale bot added the wontfix This will not be worked on label Jul 31, 2023
@mivano mivano removed the wontfix This will not be worked on label Aug 2, 2023
@stale stale bot added the wontfix This will not be worked on label Oct 31, 2023
@mivano mivano removed the wontfix This will not be worked on label Nov 1, 2023
Repository owner deleted a comment from stale bot Nov 1, 2023
Repository owner deleted a comment from stale bot Nov 1, 2023
Copy link

stale bot commented Jan 30, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jan 30, 2024
@stale stale bot closed this as completed Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants