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

Port Azure SDK patches to Consumption API v1.1.0 #1

Conversation

zmoog
Copy link
Collaborator

@zmoog zmoog commented Nov 29, 2023

This PR ports two patches to the Azure SDK to address the following problems:

  • Add StartDate/EndDate parameters for MCA users
  • URL encode 'next link' in multipage responses

Add StartDate/EndDate parameters for MCA users

According to the Microsoft docs, modern customers with a Microsoft Customer Agreement (MCA) must use the StartDate and EndDate query parameters to get the usage details for a specific date range.

Unfortunately, the API spec does include these query parameters, so we are manually adding them to the generated client.

If we don't add the query parameters, MCA users will get (many more) usage details items outside the intended time range.

URL encode 'next link' in multipage responses

When there are more than 1000 usage details items, the Consumption API paginates the response. Each response page contains a 'next link' to the following page.

The $filter query parameters contain a date range expression like the following:

properties/usageStart eq '2023-11-16' and properties/usageEnd eq '2023-11-16'

Unfortunately, the Azure service adds the query parameters value to the 'next link' without URL-encoding them. Since one of the parameters, $filter contains space, it breaks the URL, causing the following query parameters to get lost causing the error.

According to the MS docs [1], modern customers with a Microsoft
Customer Agreement (MCA) must use the `StartDate` and `EndDate`
query parameters to get the usage details for a specific date range.

Unfortunately, the API spec [2] does include these query parameters,
so we are manually adding them to the generated client.

If we don't add the query parameters, MCA users will get (many more)
usage details items outside the intended time range.

[1]: https://learn.microsoft.com/en-us/azure/cost-management-billing/costs/manage-automation#get-usage-details-for-a-scope-during-specific-date-range
[2]: https://github.com/Azure/azure-rest-api-specs/blob/main/specification/consumption/resource-manager/Microsoft.Consumption/stable/2023-11-01/consumption.json#L106-L147
When there are more than 1000 usage details items, the Consumption API
paginates the response. Each response page contains a 'next link' to
the following page.

The `$filter` query parameters contain a date range expression like
the following:

```
properties/usageStart eq '2023-11-16' and properties/usageEnd eq '2023-11-16'
```

Unfortunately, the Azure service adds the query parameters value to the
'next link' without encoding them. Since one of the parameters,
`$filter` contains space, it breaks the URL, causing the following
parameters to get lost.
@zmoog zmoog self-assigned this Nov 29, 2023
@zmoog zmoog added the bug Something isn't working label Nov 29, 2023
@zmoog zmoog changed the title Zmoog/sdk/resourcemanager/consumption/armconsumption/v1.1.0 elastic Port Azure SDK patches to Consumption API v1.1.0 Nov 29, 2023
@zmoog zmoog marked this pull request as ready for review November 29, 2023 20:59
Copy link

@tommyers-elastic tommyers-elastic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the detail in the comments and PR descriptions are incredibly valuable. thanks for taking the time to write them.

@zmoog zmoog merged commit 6375973 into sdk/resourcemanager/consumption/armconsumption/v1.1.0-elastic Nov 30, 2023
1 check passed
@zmoog zmoog deleted the zmoog/sdk/resourcemanager/consumption/armconsumption/v1.1.0-elastic branch November 30, 2023 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants