Repository navigation
Commit 4b2d54d
authored
fix(cli): rescale count-derived money when --override-count replaces a row's count (#1844)
--override-count replaced a recommendation's Count without touching the money derived from it, so the reported savings stopped corresponding to what would be bought. This is the sibling of the truncation defect fixed in #1830 and reuses that helper rather than adding a second scaling path, since two implementations of the same arithmetic drift.
On the semantics, which was the judgement call: scaling up is accurate rather than fabricated, because RI and Savings Plan unit pricing has no volume tiering, so 200 units cost exactly twice 100. The alternatives were rejected with reasons. Capping savings while scaling costs needs bespoke arithmetic outside the shared helper and yields an internally inconsistent row where EstimatedSavings no longer equals OnDemandCost minus CommitmentCost. Refusing outright is disproportionate for a documented flag whose purpose is to override the provider, since an operator may legitimately know demand is growing. The chosen behaviour scales and warns explicitly, which is the warn-loudly branch rather than a silent fallback.
The warning boundary is RecommendedCount, not the row's current Count. Overriding back up to a figure the provider itself proposed is interpolation within its own evidence, not extrapolation beyond it: --coverage 80 sizes a 100-instance proposal down to 80, so an override back to 100 should not warn. RecommendedCount is populated only on the AWS RI path and stays zero for Savings Plans, --input-csv and non-AWS, so it falls back to the current Count where the provider recorded nothing. Both sides of that boundary are pinned by a test.
Ordering with --max-instances composes to a single net ratio against the provider's figures, so there is no double-scaling. Pre-fix the cap derived its ratio from a base the override had already corrupted and faithfully preserved the error; post-fix the base is correct before the cap sees it, pinned against an independently computed expectation.
Verified by mutation, each failure by assertion rather than panic, including the mutation that makes evidencedCount ignore RecommendedCount and so warn on interpolation. Absent-versus-zero is preserved: a nil pointer stays nil rather than gaining a fabricated zero.
The --override-count functions are extracted into cmd/helpers_count_override.go as a pure move, 0 additions and 87 deletions in cmd/helpers.go with an identical 24-function set either side. That file was already 813 lines before this PR and is now 794, below where it started; the remaining excess is pre-existing debt across six files under cmd/, tracked in #1834.
Deferred and tracked: #1845 (truncation does not re-derive ProjectedCoverage), #1834 (the file-size baseline).
Closes #18441 parent 560175e commit 4b2d54d
5 files changed
Lines changed: 411 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | 495 | | |
515 | 496 | | |
516 | 497 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
0 commit comments