Skip to content

CostManagement: tolerate NotFound 'returns null or empty list for id' for new/parked subscriptions - #59

Open
JanElholm wants to merge 1 commit into
JulianHayward:mainfrom
JanElholm:fix/costmanagement-notfound-null-empty-list
Open

CostManagement: tolerate NotFound 'returns null or empty list for id' for new/parked subscriptions#59
JanElholm wants to merge 1 commit into
JulianHayward:mainfrom
JanElholm:fix/costmanagement-notfound-null-empty-list

Conversation

@JanElholm

Copy link
Copy Markdown

Fixes #58.

Problem

New or "parked" subscriptions that Cost Management has not onboarded yet return HTTP 404 with a string-coded error.code of NotFound:

GtmDimensionDataProvider.GetAzureSubscriptionsById returns null or empty list for id: <subscriptionId>

The CostManagement rule set tolerated the numeric 404 ("created recently") and two specific NotFound messages, but not this one. The call therefore fell through to the generic Stop handler and aborted the entire run (observed in Azure Governance Visualizer -DoAzureConsumption with a parked CSP subscription).

Fix

Treat this NotFound message like the existing numeric-404 "created recently" case: skip the subscription and return an empty collection (action = 'returnCollection').

Changes were made under pwsh/module/dev and the module was rebuilt with buildModule.ps1 -test, so pwsh/module/build is regenerated accordingly.

Notes

  • No version bump (rule-set tolerance change only).
  • Script parses cleanly; style matches the surrounding CostManagement handlers.

New/parked subscriptions not yet onboarded to Cost Management return a
string-coded 'NotFound' ('GtmDimensionDataProvider.GetAzureSubscriptionsById
returns null or empty list for id: ...'). This was not matched by the
CostManagement rule set and fell through to the generic Stop handler,
aborting the whole run.

Treat it like the existing numeric-404 'created recently' case: skip the
subscription and return an empty collection.

Fixes JulianHayward#58

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kaiaschulz

Copy link
Copy Markdown
Collaborator

Hey @JanElholm,
we have the same issue within our tenant and I can reproduce it with the AzGovViz.

The problem seems to be random and not affecting each and every time the same subscription.
This might be related as the data is unsorted and every time another subscription is causing the terminating error.

On the 30th of June it was the last successful run and with the 1st of July the problem started.

I understood and saw the issue in the Azure Portal as well:
image
Instead of Current cost of 0,00€ we saw an Not available.
Our subscription is fully onboarded, but we don't have a resource insight which is causing some costs.

However, I like your Pull Request but I suggest to adjust it, as the AzAPICall is having an exception which should be documented.
This can be done, but for that, we should change the response to:

        if ($catchResult.error.code -eq 'NotFound' -and $catchResult.error.message -like '*returns null or empty list for id*') {
            Logging -preventWriteOutput $true -logMessage "$defaultErrorInfo - (plain : $catchResult) - AzAPICall: seems Subscription is not onboarded to CostManagement yet (new/parked subscription) - skipping"
            $response = @{
                action    = 'return' #break or return or returnCollection
                returnVar = 'NotFoundNotSupported'
            }
            return $response
        }

With that, we ensure that the return is NotFoundNotSupported and the AzGovViz will handle it with an exception instead of returning an empty collection and continue.

@kaiaschulz

Copy link
Copy Markdown
Collaborator

Hi @JanElholm,
any chance to check and adjust the code in your PR?
Otherwise, we will use another PR to proceed further.

Thanks a lot.

Cheers,
Kai

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.

CostManagement: NotFound ("returns null or empty list for id") for new/parked subscriptions aborts the whole run

2 participants