Skip to content

Mark the main summary row of a subscription whose consumption failed - #64

Merged
stefoy merged 13 commits into
awslabs:mainfrom
pmorgenrood:upstream-pr/summary-consumption-row
Nov 25, 2026
Merged

stefoy merged 13 commits into
awslabs:mainfrom
pmorgenrood:upstream-pr/summary-consumption-row

Conversation

@pmorgenrood

@pmorgenrood pmorgenrood commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

When a subscription's consumption (billing usage) collection fails during a Run-AllSubscriptions.ps1 run, its row in the main summary (MainSummary_<timestamp>.html) now says consumption incomplete instead of ok. A collection fails when a usage page still cannot be read after its retries, or when the context cannot be switched to the subscription. The row is also marked when the subscription's consumption phase is skipped because no usable Azure token could be had, for example when the sign-in can no longer be refreshed partway through a long run.

Before this change, every row said ok and only the banner reported the problem: 1 subscription(s) had consumption (billing) issues. Under -Obfuscate the banner gives a count and no names, so the obfuscated summary could not say which subscription was missing its cost data. A consumption phase skipped for sign-in was not in the summary at all: the console counted it under Consumption Failures without naming the subscription, printed the FAILED (auth) block, and the run exited 3.

How it works:

  • ResourceInventory.ps1 records the name of the report folder it writes to (ReportFolder) on each subscription's consumption failure entry, and on the entry it writes when the consumption phase is skipped for sign-in.
  • New-RdaAllSubHtmlSummary marks the row of that folder. The folder links an entry to its row, which works even when every name in the summary is an obfuscation token.
  • In a -ParallelStreams run, each stream worker passed its consumption failure list through Select-Object -Unique. That cmdlet treats any two of these entries as equal, so each stream kept only its first failure. With two failures in one stream, the banner counted one and named only the first. The worker now keeps every entry, as it already does for the metrics and collector lists and as the sequential path does.

Behaviour notes

  • In the table, only the Health text of the affected rows changes (the privacy banner changes too; see Update below). There is no new or renamed column, no new exit code and no new stop. A run with a failed consumption collection exits with the same code as before, and a run with a consumption phase skipped for sign-in still exits 3.
  • The marked rows are the subscriptions the consumption banner counts, plus any subscription whose consumption phase was skipped for sign-in. The banner still does not count a sign-in skip (unchanged): that entry is named (all subscriptions), not after the subscription. The console reports it as before.
  • A subscription with 0 resources whose consumption failed shows consumption incomplete and still counts in the "Empty (0 resources)" card.
  • In a parallel run where one stream had more than one consumption failure, the counts are now higher than before: the banner, the console's Consumption Failures line and the Consumption failed subs line of RunSummary.log. Each now matches the number of affected subscriptions, as in a sequential run.
  • Each consumption failure entry, including the sign-in skip entry, gains one field, ReportFolder, and so does each metrics entry written when the metrics phase is skipped for sign-in. The console list, RunSummary.log and the diagnostics log read their fields by name, so their output is unchanged.

How to test

Offline, no Azure needed:

Invoke-Pester ./Tests/AllSubHtmlSummary.Tests.ps1, ./Tests/ConsumptionIncompleteRow.Tests.ps1, ./Tests/MainSummaryLiteralPath.Tests.ps1, ./Tests/MaskedTokenShapes.Tests.ps1 -Output Detailed
  • AllSubHtmlSummary.Tests.ps1 gains tests for the row: obfuscated and plain runs, a 0-resource subscription, a sign-in skip entry that names its folder (the row is marked, the banner does not count it), and entries without a usable ReportFolder (missing, empty, not a string, a folder of another run, a path, a sign-in skip entry without one), none of which marks a row.
  • ConsumptionIncompleteRow.Tests.ps1 runs the real ResourceInventory.ps1 (the way the sequential loop calls it) and the real Run-AllSubscriptions.Stream.ps1 in a child pwsh. Stand-ins replace the Azure CLI and the Az cmdlets, and HOME points at a temp folder. One subscription's usage page fails in the sequential case and two in the stream case. In a third case, one subscription's Azure token cannot be refreshed once its consumption phase starts. The test checks each report folder's consumption rows, the failure entries and the Health of each row. It is skipped on Windows, where the inner script writes to C:\InventoryReports without -OutputDirectory.

Results on the current head (Linux, PowerShell 7): AllSubHtmlSummary.Tests.ps1 37 of 37, ConsumptionIncompleteRow.Tests.ps1 9 of 9, MainSummaryLiteralPath.Tests.ps1 2 of 2 and MaskedTokenShapes.Tests.ps1 20 of 20 pass. The same test files on main: 26 of 37, 3 of 9, 0 of 2 and 12 of 20 pass.

In a real run: when the console prints Consumption query failed for <subscription>, or Consumption: SKIPPED - could not establish a usable Azure context/token for a subscription, open the run's MainSummary_*.html. That subscription's row says consumption incomplete and the other rows say ok.

Update: what the current head adds

  • Metrics skipped for sign-in mark the row too. When the metrics phase is skipped because no usable Azure token could be had, ResourceInventory.ps1 now records ReportFolder on that subscription's metrics entry (also on the (subscription) entry it writes when no subscription matches). The row then says metrics incomplete, or consumption and metrics incomplete when both were hit. This works under -Obfuscate too.
  • The privacy banner follows -Obfuscate, not a sample. The main summary's banner and its console line (Privacy: ...) now come from whether the run masked its output. A -Obfuscate run says Obfuscated ... Safe to share, even when its reports hold no records to sample (before, such a run said Identifiable). A run without -Obfuscate whose sampled names only look masked now says Obfuscated, adds that only a sample was checked, and asks you to review the reports before sharing them; the console line reads Privacy: obfuscated (sample only; review before sharing). Before, that run was also called safe to share.
  • Masked names with a type hint count as masked. The sample check in the main summary and in each subscription's report now also accepts masked names such as prod_aks_<guid>, prod_vmss_<guid> and prod_databricks_<guid>. Before, those names counted as real ones.
  • Folder names with [ or ]. The main summary is now written by its literal path, so a run folder or file name holding [ or ] works.
  • Strict mode. The summary renders under Set-StrictMode -Version Latest, also for health entries that carry no ReportFolder (an older caller) and for a run with no reports.
  • No new exit code, parameter or stop. The exit codes are the same as before.

Merge order. Both #64 and #67 are on main and can merge alone. Merge #64 first, then #67. #67 carries the same privacy-banner and masked-name edits, so after #64 it has one conflict, in Functions/AllSubHtmlSummary.Functions.ps1 where the main summary is written: take #67's side (it writes under a private name, then moves the file into place, by literal path).

Open limits: not run live against main (main needs the Azure CLI), and not run on Windows.

Peter-John Morgenrood added 3 commits October 28, 2026 18:25
When a subscription's usage pages could not be read, its row in the main
summary still said "ok". The consumption banner names the affected
subscriptions only in a non-obfuscated run; under -Obfuscate it gives a
count, so the shareable summary could not say which subscription is
missing its cost data.

ResourceInventory.ps1 now records the name of the report folder it
writes to (ReportFolder) on each subscription's consumption failure
entry. The main summary marks the row of that folder "consumption
incomplete". It uses the same entries the banner counts, so the
sign-in skip entry, which names no subscription, marks no row. An entry
without a usable ReportFolder marks no row either. The banner, the
columns and the exit codes are unchanged.
In a -ParallelStreams run each stream worker wrote its consumption
failure entries through Select-Object -Unique, which treats any two of
these objects as equal and so kept only the first. When two
subscriptions in one stream failed consumption, the banner counted one
and named only the first, and the second subscription's row said "ok".

The worker now writes every entry, as it already does for the metrics
and collector lists and as the sequential path keeps them.
When a subscription's consumption phase is skipped because no usable Azure
token could be had, its failure entry carried no report folder, so its row
in the main summary still said "ok". The entry now names the report folder
the same way the other consumption failure entries do, and that row says
"consumption incomplete". The consumption banner still does not count a
sign-in skip, as before.
pmorgenrood pushed a commit to pmorgenrood/resource-discovery-for-azure that referenced this pull request Oct 30, 2026
pmorgenrood pushed a commit to pmorgenrood/resource-discovery-for-azure that referenced this pull request Oct 30, 2026
…wslabs#59/awslabs#61/awslabs#64/awslabs#53/awslabs#56): run the offline harnesses on the Az PowerShell path

The child-process harnesses of these PRs answered sign-in, the subscription
list and Resource Graph through an 'az' stand-in. awslabs#66 drops the Azure CLI, so
that stand-in is never called. Tests/Helpers/AzPsStandIns.ps1 now gives every
harness Get-AzSubscription, Get-AzAccessToken -TenantId, a signed-in context
and Resource Graph paging through Invoke-AzRestMethod with skip tokens, and
answers each page from the harness's own graph stand-in (renamed
Invoke-StandInGraph). Discovery queries go through Invoke-DiscoveryGraphQuery
(awslabs#59), so the -HideRawOutput check reads those calls. awslabs#59's unparsable page is
now a cut-off page (an empty property name is kept since awslabs#66), and awslabs#52's setup
stop is shown with a missing Az module instead of a missing Azure CLI.
Peter-John Morgenrood added 9 commits November 9, 2026 10:13
…d for sign-in

When the metrics phase was skipped because the sign-in could no longer be
refreshed, the main summary named the subscription in its metrics banner
but still marked its row 'ok'. The metrics entry now records the report
folder its run writes to, as the consumption entry does, and the main
summary marks that row 'metrics incomplete' ('consumption and metrics
incomplete' when both), so an obfuscated summary also says which
subscription it is.
…ample

New-RdaAllSubHtmlSummary picked the privacy banner from the obfuscation
status sampled from the reports, so an -Obfuscated summary whose reports hold
no records showed the Identifiable banner, while the names were hidden. The
banner now follows the gate that hides the tenant id and subscription names,
and says "Safe to share" only under -Obfuscated, which the wrapper passes for
an -Obfuscate run: names that only look masked in a sample of records prove
nothing about the rest, so that banner asks for a check before sharing.

The same change is in the summary wording PR, line for line, so the two
merge cleanly in either order.
The metrics and the consumption failure entries both built the report
folder name from $Global:DefaultPath with their own copy of the same
expression, and the main summary matches rows by that exact name. Both now
call Get-ReportFolderName, so the two cannot drift apart. No output change.
The console line after the main summary is written read the sampled status,
so an -Obfuscated run whose reports hold no records to sample printed
'Privacy: identifiable'. It now follows $IsObfuscated, the gate the privacy
banner and the redaction already use.
Without -Obfuscated, a run whose sampled names look masked printed
'Privacy: obfuscated', while the banner asks for a check before sharing.
The console line now says 'obfuscated (sample only; check before
sharing)' in that case. The two comments above the banner are one.
…ts, under strict mode

The consumption and metrics row marks read ReportFolder from entries that may not have it, and the privacy sample count and the run total read .Count and .Sum of what can be one item or none; under Set-StrictMode each stopped the summary. The row marks skip an entry without a folder, and the two counts are taken as on the summary-package branch, with the same text so the two merge cleanly.
Out-File -FilePath reads the path as a wildcard, so a run folder or file
name with [ or ] gave no summary, or wrote one under another name.
Under -Obfuscate the collector names a Databricks, AKS-managed or scale-set resource prod_databricks_<guid>, prod_aks_<guid> or prod_vmss_<guid> (nonprod_ alike), but the masked-report check of Summary.ps1 and of the main summary matched only prod_<guid> and nonprod_<guid>. A masked report made mostly of such resources could read as identifiable. Both patterns now allow those three hints; Tests/MaskedTokenShapes.Tests.ps1 (the same file on sync/pr-64, sync/pr-67 and upstream-pr/summary-wording) checks every shape.
pmorgenrood pushed a commit to pmorgenrood/resource-discovery-for-azure that referenced this pull request Nov 17, 2026
@pmorgenrood
pmorgenrood force-pushed the upstream-pr/summary-consumption-row branch from 3c59516 to 79d366d Compare November 17, 2026 23:59
@stefoy
stefoy merged commit df75136 into awslabs:main Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants