fix(powershell): return full export run history in Get-FinOpsCostExport#2183
Open
RolandKrummenacher wants to merge 2 commits into
Open
fix(powershell): return full export run history in Get-FinOpsCostExport#2183RolandKrummenacher wants to merge 2 commits into
RolandKrummenacher wants to merge 2 commits into
Conversation
…rt (#2063) Get-FinOpsCostExport -RunHistory used the Cost Management list endpoint with $expand=runHistory, which truncates run history per export. When -RunHistory is specified, re-fetch each export individually via the GET endpoint, which returns the complete run history. Falls back to the list-endpoint history if the individual GET fails. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes incomplete export run history results in the FinOps Toolkit PowerShell module by changing Get-FinOpsCostExport -RunHistory to re-fetch each export via the Cost Management individual GET endpoint, which returns the full runHistory rather than the truncated list response.
Changes:
- Added per-export
GET .../exports/{name}?$expand=runHistorycalls when-RunHistoryis specified, with a fallback to the list-provided run history on failure. - Updated Pester unit tests to validate full run history behavior, no extra calls when
-RunHistoryis omitted, and handling of failure/empty histories. - Added a v15 changelog entry documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/powershell/Public/Get-FinOpsCostExport.ps1 | Re-fetch each export individually to return full run history when -RunHistory is used, with fallback behavior. |
| src/powershell/Tests/Unit/Get-FinOpsCostExport.Tests.ps1 | Expands unit test coverage for full history retrieval, no-expand behavior, fallback, and empty run history cases. |
| docs-mslearn/toolkit/changelog.md | Documents the Get-FinOpsCostExport -RunHistory fix in the v15 changelog. |
Comment on lines
+258
to
+262
| # Assert | ||
| $result | Should -Not -BeNullOrEmpty | ||
| $result.RunHistory | Should -HaveCount 1 | ||
| $result.RunHistory[0].RunId | Should -Be 'run1' | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🪲 Fixes
Fixes #2063
Get-FinOpsCostExport -RunHistoryreturned fewer runs than expected because it relied solely on the Cost Management list endpoint (GET .../exports?$expand=runHistory), which truncates therunHistory.valuearray per export. The individual get endpoint (GET .../exports/{name}?$expand=runHistory) returns the complete run history.🛠️ Changes
-RunHistoryis specified, after the list call the cmdlet now makes an additional individualGETper export to retrieve the full run history (one extra API call per export).GETfails, it falls back to the run history returned by the list response so the cmdlet still returns data.-RunHistoryis unchanged (single list call, no$expand, no per-export calls).✔️ Testing
Updated/added unit tests in
Get-FinOpsCostExport.Tests.ps1:$expandis made when-RunHistoryis omitted.All 5 tests pass; PSScriptAnalyzer reports no findings.
📃 Documentation
🤖 Generated with Claude Code