openflighthpc / cloud-cost-reporter

Eclipse Public License 2.0
0 stars 0 forks source link

Consider using virtual machine API instead of availibility statuses API for getting instance status #142

Open VoxSecundus opened 2 years ago

VoxSecundus commented 2 years ago

See: https://alces.slack.com/archives/C01A4K27B37/p1633532537038800

timalces commented 2 years ago

We currently use Microsoft.Compute/virtualMachines to determine a list of instances with a compute tag (and which compute group they belong to). Then we obtain instance statuses with Microsoft.ResourceHealth/availabilityStatuses and combine the two, in order to have enough information to create Azure instance logs.

Instead of using availabilityStatuses we could use /virtualMachines to also query the statuses, by adding the query param statusOnly=true. This is likely to be more efficient as only queries virtual machines, also meaning we don't need to filter out other resources within our application. However, two queries are still required, as tags are not included when statusOnly=true and statuses are not included when it is false (presumably why we missed it as an option originally).

The most relevant status attribute from /virtualMachines for each value seems to be: ["instanceView"]["statuses"].find { |status| status["code"] == "PowerState/deallocated" }["displayStatus"]

Some logic would need to be updated to reflect/ translate different vm state descriptions. I.e. virtual machines' display statuses are "VM running" instead of "available" and "VM deallocated" instead of "unavailable".