-
-
Notifications
You must be signed in to change notification settings - Fork 121
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
Updated RetrieveDailyCost method to handle pagination. Uses nextLink from API response. #142
Updated RetrieveDailyCost method to handle pagination. Uses nextLink from API response. #142
Conversation
Thanks for opening this pull request! |
Thanks, that looks like a nice addition! We need it in all the places where there is paging support. Maybe even in a more generic way; a mapper that knows how to convert it to the target format and a generic reader that knows how to handle the next link. There is already a lot of duplication. |
Ok, leave it with me and I'll see what I can come up with. Good points. |
…n helper methods. Refactor ExecuteCallToCostApi to cater for pagination. No major changes to callers.
Ok, so I looked at a few different approaches and whilst this new one may not be the most elegant, the main advantage was that it results in almost zero change to the caller methods. Firstly, I created an overload of ExecuteCallToCostApi that doesn't except a payload - for our get requests. Secondly, I thought it best to ensure the callers of ExecuteCallToCostApi with a payload could call in the same manner post pagination changes (for me less change in those areas means I don't have to delve into them too much and less chance of breaking changes). I then proceeded to refactor the new version of ExecuteCallToCostApi with helper methods to try and reduce complexity and increase readability. Please let me know what you think. I am still learning in many areas.... I did perform a reasonable number of tests to cover paginated and non-paginated requests across commands, however it may be useful to conduct further testing if possible. |
Thanks for your ideas. I was trying to get my head around it as well; minimizing changes but still supporting paging. I believe there are three kinds of calls in the class (which is most likely too large as well):
The first one always has a known return type: So in hindsight; the I took a slightly different approach in this PR #147: the newly introduced - var response = await ExecuteCallToCostApi(includeDebugOutput, payload, uri);
-
- CostQueryResponse? content = await response.Content.ReadFromJsonAsync<CostQueryResponse>();
+ var content = await ExecutePagedCallToCostApi(includeDebugOutput, payload, uri); For the typed calls (like fetching the subscriptions), I have a ![]() And then I still have the old skool But the The PR #147 is just a draft, I have not done any extensive testing, just want to get your feedback on this idea. Your remark about tests; yes that is a big miss here. Mostly because there will need to be a lot of mocking, but that should not be an excuse. |
Closing |
I was using the daily cost component with --dimension ResourceId and noticed that it can handle max 5000 rows as this is the max for a single API call.
For this single method I have added support for obtaining the full dataset by following the nextlink returned in the response until empty\null.
I find this useful, as combined with the time frame function my results are often more than 5000 rows.
Please let me know what you think and if you want I can add the same logic to the other calls.
Thank you for this great tool!