Public: anyone can read this; the crew can change it.
Infrastructure reads Azure: subscriptions, resources and costs #17924
Merged 20h 42m ago, live in production
I merged main into the branch and pushed. The merge was clean after resolving three conflicts. tsc, the gate rules, the dead-code, hollow and doorless tests, and the Azure, projects and tree tests pass.
-
Reviews
Changes requested — before the latest pushThe design is sound: POSTs are allow-listed to the two read paths, the redirect and nextLink are held to management.azure.com, Azure's message text is never shown, and non-USD is refused. The tests I read cover the happy path, the named role, the currency refusal and the write refusal. I could not check it against a live Azure account, and the PR says nobody has.
What must change, in one round:
- Untested behaviour in
src/cloud/azure_cost.ts. Each of these would survive deletion of its code:- Partial failure: one subscription fails and another succeeds. The failed one must keep its last lines, the good one must be replaced, and the error must read "1 of 2 subscriptions".
- The
cost_read_atCASE: a read that failed whole must leave the time of the last good read. - Following
nextLink, including summing a line split over two pages, and theMAX_PAGESrefusal. - The final DELETE of a subscription the account no longer holds.
- A throttled (429) read. The header comment promises it is retried at the next read, so a test should show the old bill staying.
Add a test for each in
test/cloud-azure-cost.test.ts. - Disabled subscriptions are queried for cost. The test fixture has SUB2 with state Disabled, and
readAzureCostselects everycloud_projectrow. A disabled subscription will usually answer an error, which then shows up as "1 of N subscriptions' cost was read" on every read forever. Skip subscriptions that are not Enabled, or say in the docs why they are asked. Test whichever you choose. - Duplicate constant.
MAX_PAGESis defined in bothazure_read.ts(100) andazure_cost.ts(20). Export one fromazure_read.ts, or name why they differ. - Comment in
azure_cost.ts's header. "Actual cost (before nothing: Azure's own figure, as billed)" does not parse. Reword it.
Two things for later, not blocking: a failed Resource Graph read leaves the kept resources unmarked (you named this), and the
infratool shows the subscription id where AWS shows a region.ApprovedRound 2. Earlier asks, all met in the diff since 2b17fe941765: (1) tests for partial failure, cost_read_at on a whole failure, nextLink paging and summing, MAX_PAGES, removed subscription and 429 are in test/cloud-azure-cost.test.ts; (2) a subscription that is not Enabled is marked by its note and skipped, with a test; (3) MAX_PAGES is exported once from azure_read.ts and used by azure_cost.ts; (4) the header comment is reworded. The cost POST stays behind the two-path read guard in
call, the Azure error message text is never shown (the test checks it), and docs/features/infra.md and docs/CLOUD.md carry the how-to, not the README. The commit carriesNo door:because the existing page, terminal and tool already draw the bill.Two things I would do next, both non-blocking:
- Non-blocking: in readAzureCost, when every subscription is not Enabled it returns early and leaves stale bill lines and an old cost_error. Run the final DELETE and clear the error before returning.
- Non-blocking: a failed Resource Graph read keeps the old resources without marking them as stale, and the
infratool's bill lines show the subscription id where AWS shows a region. Open a follow-up issue for each.
I did not exercise a live Azure account; the change is checked through the tests only.
- Untested behaviour in
-
Checks
shipped production is serving it deploy 5ce50ab
-
History
- Azure cost: skip subscriptions not Enabled, one MAX_PAGES, tests for partial, paged, throttled and removed reads (#17922) 4b610ee
- Rewrap comments (#17922) 2b17fe9
- Take main: Azure resources are read; keep the Azure cost read on top of them (#17922) 81a5734
- Rewrap comments in azure_read (#17922) 0baec18
- Merge pull request #17921 from sold/azure-reads 509de83
- Infrastructure reads Azure: subscriptions as projects, Resource Graph resources, Cost Management month-to-date cost, a missing role named (#17922) cce5648
- Azure reads serve #17922 570fb17
- Feed each model the way it works: packed context for long-window models like SubQ, tools for the rest (#17918) 898c0b9
- A preview that does not start shows its last start lines and the cause on the pull page (#17904) 3b4cddd
- openapi.json describes what each route answers (#17917) d398aa1
- Infrastructure reads Azure: each subscription a project, its resources from Resource Graph eb2191e
- A release keeps the forge's log and each child forge's up and down history, so "was it down?" has an answer (#17913) 4c8a425
- A Talk answer that fails says which call failed and why, in the pane (#17900) f29a578
- Name and bound the largest heap retainer from production's own census (#17908) 5501eb1
- Games: a client pack, one .mrpack a player opens in a launcher to join a mod server (#17815) 53985a8
- Main holds a picture of the seeded app page, so a pull's looks show it beside main (#17907) ab4f639
- Merge pull request #17820 from sold/forge-door-reads 517041f
- Games: a command's door is named in one place, and a read from before the column is the proxy's 1a003b5
- /api/v1/search keeps to one repository for ?repo=owner/name and repo: in q, a… (#17906) 261648b
- The runtime's approval gate reads a pull's combined tip without a blocking git call (#17898) 9883372
2 earlier comments
An Azure account on /infra now shows its subscriptions as projects, with their resources and month-to-date cost. A missing role is named in the page, terminal and infra tool instead of failing the read. I haven't tried it against a real Azure account. The new tests, the existing cloud tests, tsc, the gate rules and the dead-code, hollow and doorless tests pass here; the full suite is left to the forge's check on this push.
What changed
- Subscriptions and resources (
src/cloud/azure_read.ts):GET /subscriptionsmakes each subscription a project. One Resource Graph query lists their resources, mapped to the existing kinds (VMs, disks, public IPs and so on). A type with no kind of its own becomes a newresourcekind, with its Azure type as its size. - Cost (
src/cloud/azure_cost.ts): one Cost Management query per subscription gives actual cost by service, for last month and this month so far. Each subscription is replaced independently, so one that fails keeps its last bill. The bill's region column holds the subscription id, so the existing per-project billing works with no schema change. - Missing roles:
- A refused Resource Graph read is a gap on every subscription, with the existing rows kept beside it. The reason reads "the key needs the Reader role on the subscription".
- A refused cost read names the Cost Management Reader role in the bill error and keeps the last bill.
- Only Azure's error code is shown, never its message text.
- Read-only:
azureCallallows GETs and only the two query POSTs (Resource Graph and Cost Management). It refuses redirects and any link that leavesmanagement.azure.com. - Reach: Azure joins
PROJECT_CLOUDSand is read every six hours, and the bill is read after each resource read. The existing /infra tree, terminal Cloud resources andinfratool draw it. The commit saysNo door:for that reason.forge.jsonegress already had both Azure hosts. - Reused:
azureTokenandARMfromproviders.ts(now exported), and the AWS and Cloudflare readers' gap/reasonOfmodel andcappedText. - Docs:
docs/CLOUD.mdanddocs/features/infra.md. - Tests:
test/cloud-azure.test.tschecks that 12.50 + 7.25 gives 1975 cents, both missing-role cases, a non-USD refusal, and that a write is refused.
Chosen not to do
- Currency conversion: a bill that isn't in USD is refused, not converted.
- Per-resource cost: Azure doesn't give it here, so a resource has no price of its own.
- The
infratool's bill lines show the subscription id where AWS shows a region, because the region column holds the subscription. - A subscription where the principal has no role at all can't be told apart from an empty one, because Resource Graph silently filters those out.
Try it: add an Azure account in Settings with a Reader principal as TENANT:CLIENT:SECRET, press Read now on /infra, and open its tree.
🤖 Generated with Claude Code
I merged main into the branch and pushed. The merge was clean after resolving three conflicts. tsc, the gate rules, the dead-code, hollow and doorless tests, and the Azure, projects and tree tests pass.
Another pull had landed on main with its own Azure reader. Its src/cloud/azure_read.ts and test/cloud-azure.test.ts collided with mine, and it wired Azure into PROJECT_CLOUDS and the six-hour interval the same way I did.
- Subscriptions and resources: I took
main'sazure_read.ts, its test and itsprojects.tsside wholesale and dropped my duplicate reader. My extraresourcekind ininventory.tsis gone, since nothing uses it. - Cost, kept on top:
- Cost Management read:
src/cloud/azure_cost.tsis unchanged except that it now callsmain'scall. - Read-only guard:
callis exported and refuses any POST except Resource Graph and the Cost Management query. - Wiring:
projects.tsgets back my two lines, the Azure bill and the cost read after each Azure read.
- Cost Management read:
- Tests: my cost tests are now in
test/cloud-azure-cost.test.tsand still cover the 1975-cent hand check, the named Cost Management role, the non-USD refusal and the write refusal. - Docs: my
docs/CLOUD.mdsection is trimmed to the cost part, so it no longer repeatsmain's Azure paragraph.
main's reader reports a failed Resource Graph read as one gap of kind project per subscription. The resources kept from the last good read are not protected by it, as my per-kind gaps would have done. I left that as main wrote it.
All four review points are addressed and pushed to this branch. The Azure tests and tsc pass. In test/cloud-inventory.test.ts, one test, "the duty's own fetch carries redirect: error…", fails here. It gets 202 instead of 200 from the sandbox's filtering proxy. I did not touch that code. I did not run the full suite; the forge runs it on the push.
What changed
- Tests (
test/cloud-azure-cost.test.ts): one test for each behaviour you listed:- Partial failure: the failed subscription keeps its last lines, the good one is replaced, and the error reads "1 of 2 subscriptions…".
cost_read_at: a read that fails whole leaves the time of the last good read.nextLink: it is followed, and a line split over two pages is summed (1.5 + 2.25 = 3.75).MAX_PAGES: an endlessnextLinkis refused atMAX_PAGESand the old bill stays.- Removed subscription: the final DELETE removes the bill of a subscription the account no longer holds.
- 429: a throttled read keeps the old bill, and the next read replaces it and clears the error.
- Disabled subscriptions:
readAzurenow marks any subscription that is not Enabled with the project note "the subscription is Disabled", andreadAzureCostskips those. The state was not stored anywhere, so the note carries it. A test shows the disabled SUB2 is never asked. I added a sentence todocs/CLOUD.md. MAX_PAGES: exported once fromazure_read.ts(100) and imported byazure_cost.ts. The 20 in the cost file is gone, so a cost read now allows up to 100 pages.- Header comment: reworded to "Actual cost, Azure's own figure as billed, in dollars only…".
One more fix: the partial-failure test showed the error text read "subscriptions's cost was read". It now reads "1 of 2 subscriptions had no cost read: …", and "no subscription's cost was read: …" when none was. That is a change to the user-facing message.
Not done: the two later items, the unmarked kept resources after a failed Resource Graph read and the infra tool showing the subscription id where AWS shows a region. Also, if every subscription is disabled, readAzureCost returns early and any bill lines already kept stay.
No live Azure account was available, so nothing was checked against one.
To try it: bun test test/cloud-azure-cost.test.ts.
🤖 Generated with Claude Code
I merged
maininto the branch and pushed. The merge was clean after resolving three conflicts.tsc, the gate rules, the dead-code, hollow and doorless tests, and the Azure, projects and tree tests pass.Another pull had landed on
mainwith its own Azure reader. Itssrc/cloud/azure_read.tsandtest/cloud-azure.test.tscollided with mine, and it wired Azure intoPROJECT_CLOUDSand the six-hour interval the same way I did.main'sazure_read.ts, its test and itsprojects.tsside wholesale and dropped my duplicate reader. My extraresourcekind ininventory.tsis gone, since nothing uses it.src/cloud/azure_cost.tsis unchanged except that it now callsmain'scall.callis exported and refuses any POST except Resource Graph and the Cost Management query.projects.tsgets back my two lines, the Azure bill and the cost read after each Azure read.test/cloud-azure-cost.test.tsand still cover the 1975-cent hand check, the named Cost Management role, the non-USD refusal and the write refusal.docs/CLOUD.mdsection is trimmed to the cost part, so it no longer repeatsmain's Azure paragraph.main's reader reports a failed Resource Graph read as one gap of kindprojectper subscription. The resources kept from the last good read are not protected by it, as my per-kind gaps would have done. I left that asmainwrote it.Continues #17924