cost-analysis-export: Fail merge when AKS or cost imports are empty - #5959
Sebastien Tardif (SebTardif) wants to merge 2 commits into
Conversation
Return an error from importAKSData and importCostManagementData when zero files are processed, and from ImportCSV when an AKS CSV is empty. Empty Cost Management files still create the standard header table. Introduced in Azure#5393 (2025-10-24). Follow-up to Azure#5771. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
There was a problem hiding this comment.
🟡 Changes recommended
The new “no ... files found” errors can be misleading when blobs exist but all imports fail (for example, empty CSV), which reduces debuggability in the failure path this PR is targeting.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR tightens failure behavior in the examples/cost-analysis-export pipeline so Merge fails fast when AKS or Cost Management imports result in no usable data, avoiding later join/export failures against missing tables.
Changes:
- Return an error from
importAKSData/importCostManagementDatawhen no files are successfully imported. - Make
ImportCSVreturn an error on EOF for non–Cost Management tables (while preserving the empty-file behavior forcost_management). - Add unit and Azurite-backed tests covering empty AKS CSV imports and missing AKS/cost export blobs.
File summaries
| File | Description |
|---|---|
| examples/cost-analysis-export/main.go | Fail Merge earlier when imports produce no successful tables/rows; treat empty AKS CSV as an import error. |
| examples/cost-analysis-export/main_test.go | Add tests for empty ImportCSV behavior and Merge failure modes (no AKS files, empty AKS export, no cost files). |
Review details
Suppressed comments (1)
examples/cost-analysis-export/main.go:404
- Similar to AKS import,
filesProcessed == 0means no cost management files were imported successfully, which can also happen if files exist but all fail to process; “found” is misleading in that case.
if filesProcessed == 0 {
return fmt.Errorf("no cost management files found under prefix %q", a.Config.AzureStorageCostExportPrefix)
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
filesProcessed==0 used to say no files found even when matching blobs existed but ImportCSV failed (empty AKS CSV). Count matches separately and mention .csv.gz in the not-found path. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
There was a problem hiding this comment.
🟢 Approval recommended
The changes are narrowly scoped, improve correctness of failure signaling, and include targeted unit and integration-style tests for the reported scenarios.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
Follow-up to #5771. Fail the cost-analysis-export merge when AKS or Cost Management imports produce no usable rows, instead of logging an error and uploading a join of empty or missing tables.
Problem
Mergealways continues after import. Two cases look like success in logs and then fail later (or write a bad result):importAKSDataandimportCostManagementDatalogno ... files foundand stillreturn nil. Join then errors withno such table: aks_splitsorno resource ID column found.ImportCSVtreats EOF onaks_splitsas success without creating a table, incrementsfilesProcessed, and join fails the same way. Empty Cost Management files still create the standard EA header table (unchanged).This shipped in #5393 (2025-10-24).
Change
importAKSData/importCostManagementDatawhenfilesProcessed == 0.empty CSV for table aks_splitsfromImportCSVon EOF (Cost Management empty-file table create is unchanged).ImportCSV, plus AzuriteMergecases for no AKS files, empty AKS export, and no cost files.Validation
gofmt and
go vetare clean.Related
EXPORT_TIMEOUTand closed the join temp file