Skip to content

fix(cli): the CSV TOTAL row sums normalized units for rows whose own NU cell is blank #2005

Description

@cristim

Summary

The multi-service CSV writer blanks the per-row NormalizedUnits cell for non-RDS services, but buildTotalRow calls RDSInstanceNUFromType unconditionally. That helper only requires three dot-separated parts before looking up the size suffix, so an ElastiCache type like cache.r7g.large resolves to the large NU value. The TOTAL cell therefore exceeds the sum of the visible cells above it, and an operator reconciling family-NU bundling by hand cannot make the column add up.

Location

  • cmd/multi_service_csv.go:314 at 3c0f8ac (buildTotalRow)
  • cmd/multi_service_csv.go:370-373 (formatNormalizedUnitsOrBlank)
  • providers/aws/recommendations/family_nu.go:61-68 (RDSInstanceNUFromType, map at :23-38)

Failure scenario

A mixed --all-services run includes ElastiCache recs with ResourceType=cache.r7g.large, count 3. Each row's NU cell is blank; the TOTAL row adds 3 x 4 = 12 for them. The TOTAL NU is larger than the sum of the column.

Evidence

for i := range results {
    r := results[i]
    totalCount += r.Recommendation.Count
    totalNU += float64(r.Recommendation.Count) * recommendations.RDSInstanceNUFromType(r.Recommendation.ResourceType)

Suggested fix

Gate the totalNU accumulation on the same Service != ServiceRDS && != ServiceRelationalDB test formatNormalizedUnitsOrBlank uses, ideally by summing the per-row helper's own value.


Found by the 2026-09-02 codebase audit, finding A10-011, reported by one reviewer and independently confirmed by a second. Full report: docs/audits/codebase-audit-2026-09-02.md.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions