Skip to content

cost-analysis-export: Fail merge when AKS or cost imports are empty - #5959

Open
Sebastien Tardif (SebTardif) wants to merge 2 commits into
Azure:masterfrom
SebTardif:fix/cost-export-fail-empty-import
Open

Sebastien Tardif (SebTardif) wants to merge 2 commits into
Azure:masterfrom
SebTardif:fix/cost-export-fail-empty-import

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

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

Merge always continues after import. Two cases look like success in logs and then fail later (or write a bad result):

  1. Zero matching blobs. importAKSData and importCostManagementData log no ... files found and still return nil. Join then errors with no such table: aks_splits or no resource ID column found.
  2. Empty AKS CSV. ImportCSV treats EOF on aks_splits as success without creating a table, increments filesProcessed, 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

  • Return an error from importAKSData / importCostManagementData when filesProcessed == 0.
  • Return empty CSV for table aks_splits from ImportCSV on EOF (Cost Management empty-file table create is unchanged).
  • Tests: unit coverage for empty ImportCSV, plus Azurite Merge cases for no AKS files, empty AKS export, and no cost files.

Validation

Red:  go test -run TestImportCSV_EmptyAKSSplitsReturnsError
      FAIL: An error is expected but got nil
      TestApp_Merge_NoAKSExportFiles FAIL: join error does not contain "no AKS export files"
Green: go test -count=1 .
      ok  github.com/Azure/aks-cost-analysis-export

gofmt and go vet are clean.

Related

  • #5771 applied EXPORT_TIMEOUT and closed the join temp file
  • #5393 added this example

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 / importCostManagementData when no files are successfully imported.
  • Make ImportCSV return an error on EOF for non–Cost Management tables (while preserving the empty-file behavior for cost_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 == 0 means 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.

Comment thread examples/cost-analysis-export/main.go Outdated
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>
Copilot AI review requested due to automatic review settings September 9, 2026 21:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

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.

6 participants