Commit 84a884e
authored
fix(cmd): match Savings Plans region filters on Details.Region (#1881)
The provider-side half of #1582 was already merged. This closes the CLI half, which the issue names explicitly and which was left untouched.
AWS Savings Plans recommendations never populate the top-level `Region`. `providers/aws/recommendations/parser_sp.go` sets it only inside the nested `Details: &common.SavingsPlanDetails{...}` struct. `passesDimensionFilters` was calling `shouldIncludeRegion(rec.Region, cfg)` with that bare field, which is `""` for every SP recommendation, so `--include-regions` silently dropped all of them and `--exclude-regions` silently let them all through. The user saw fewer recommendations, or the wrong ones, with no explanation either way.
## What changed
`passesDimensionFilters` routes through a four-line helper that asks `IsRegionAgnostic` first and otherwise matches on `EffectiveRegion`. Those two predicates already existed on the provider side and are reused rather than reimplemented; they were unexported, so the change exports them, which is a pure identifier rename with no logic touched. `cmd` already imports `providers/aws`, so no new dependency edge. Moving them to `pkg/common` was rejected because `isAccountLevelSPPlanType` compares against `sptypes.SavingsPlanType` SDK members and the `pkg/` module carries no `savingsplans` dependency.
**Empty is not region-agnostic.** The fix deliberately does not make a blank `Region` match every filter. A genuinely region-agnostic Savings Plan (Compute, SageMaker, Database) and an EC2Instance plan whose region failed to parse are different things, and only the first is exempt. `IsRegionAgnostic` decides that on positive plan-type evidence, so the fix cannot turn a silent drop into a silent over-inclusion, which on a purchasing tool is the worse failure.
Exporting those helpers widened what they can be handed, so the second commit confines them to `common.ProviderAWS`. While package-private they only ever saw recommendations the AWS parsers built, and "these Details are AWS Savings Plans Details" held by construction; exported, the invariant rested on no caller making that mistake. `common.SavingsPlanDetails` and `common.CommitmentSavingsPlan` are shared types, and Azure's savings plans client type-asserts on the former in three places, so a non-AWS recommendation carrying those fields would have been read with the AWS meaning. Not reachable today: no Azure code constructs a `common.Recommendation` with `CommitmentSavingsPlan`, the only non-AWS assignment of that constant being on a `common.Commitment`, a different type. The guard restores an invariant this change weakened rather than defending a reachable state, and it sits in the helpers so every caller inherits it instead of just the one call site.
## How it was verified
`TestApplyFilters_SavingsPlansRegionFilters` drives seven cases through the real `applyFilters` path. With the production line reverted it fails three ways: an in-region EC2Instance SP dropped by `--include-regions`, a region-agnostic Compute SP dropped by `--include-regions`, and an EC2Instance SP leaking past `--exclude-regions`. The four already-correct cases pin the over-inclusion trap, since an EC2Instance SP with an empty `Details.Region` is region-scoped, not agnostic, and stays dropped.
`TestRegionHelpers_NonAWSRecommendation` pins the provider gate, and each half was checked for teeth independently rather than together: removing only the `IsRegionAgnostic` guard fails `IsRegionAgnostic_is_false_for_a_non-AWS_rec`, and removing only the `EffectiveRegion` guard fails `EffectiveRegion_does_not_read_Details_of_a_non-AWS_rec`. Tested jointly, the first assertion aborting would have masked whether the second was pinned at all.
`go build ./...`, the full `cmd` package, the `providers/aws` module, `go vet` and `gofmt` all clean. `gocyclo -over 10` clean, confirmed to be scanning by a `-over 6` run reporting 134 functions. `passesDimensionFilters` stays at complexity 5.
The first CI attempt failed in `lint` before analysing any code: `golangci-lint config verify` fetches its JSON schema over the network and the request timed out. Re-run, green.
## Sibling dimension filters: checked, neither is the same defect
**Instance type** does drop SP recommendations, because `ResourceType` is empty. But `SavingsPlanDetails` has no instance type; it has `InstanceFamily` (`"m5"`), a different granularity, only for EC2Instance plans. Matching one against the other needs a semantics decision this issue does not specify, and there is no provider-side instance-type filter to mirror. Left alone deliberately.
**Engine** has no bare-field bug: `SavingsPlanDetails` carries no engine attribute, because Cost Explorer returns none for any SP plan type.
## Noted, not fixed
`shouldIncludeRegion` does not skip blank entries the way the provider's `regionSet` does, so `--include-regions "us-east-1,"` can admit an unknown-region recommendation. Pre-existing, affects all recommendation types, and strictly improved for Savings Plans by this change.
Not verified: no live AWS run, no credentials in this environment.
Closes #15821 parent ae1e632 commit 84a884e
4 files changed
Lines changed: 210 additions & 17 deletions
File tree
- cmd
- providers/aws
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | | - | |
| 90 | + | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| |||
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
125 | 145 | | |
126 | 146 | | |
127 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
146 | 146 | | |
147 | | - | |
148 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
149 | 156 | | |
150 | 157 | | |
151 | 158 | | |
| |||
154 | 161 | | |
155 | 162 | | |
156 | 163 | | |
157 | | - | |
| 164 | + | |
158 | 165 | | |
159 | 166 | | |
160 | 167 | | |
| |||
186 | 193 | | |
187 | 194 | | |
188 | 195 | | |
189 | | - | |
190 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
191 | 203 | | |
192 | 204 | | |
193 | 205 | | |
| |||
236 | 248 | | |
237 | 249 | | |
238 | 250 | | |
239 | | - | |
| 251 | + | |
240 | 252 | | |
241 | 253 | | |
242 | 254 | | |
243 | 255 | | |
244 | 256 | | |
245 | 257 | | |
246 | | - | |
| 258 | + | |
247 | 259 | | |
248 | 260 | | |
249 | 261 | | |
| |||
253 | 265 | | |
254 | 266 | | |
255 | 267 | | |
256 | | - | |
| 268 | + | |
257 | 269 | | |
258 | 270 | | |
259 | 271 | | |
260 | 272 | | |
261 | 273 | | |
262 | 274 | | |
263 | | - | |
| 275 | + | |
264 | 276 | | |
265 | 277 | | |
266 | 278 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
| 355 | + | |
355 | 356 | | |
356 | 357 | | |
357 | 358 | | |
358 | 359 | | |
359 | 360 | | |
360 | 361 | | |
| 362 | + | |
361 | 363 | | |
362 | 364 | | |
363 | 365 | | |
| |||
410 | 412 | | |
411 | 413 | | |
412 | 414 | | |
413 | | - | |
| 415 | + | |
414 | 416 | | |
415 | 417 | | |
416 | 418 | | |
| |||
453 | 455 | | |
454 | 456 | | |
455 | 457 | | |
456 | | - | |
| 458 | + | |
457 | 459 | | |
458 | 460 | | |
459 | 461 | | |
460 | | - | |
461 | | - | |
| 462 | + | |
| 463 | + | |
462 | 464 | | |
463 | 465 | | |
464 | 466 | | |
| |||
504 | 506 | | |
505 | 507 | | |
506 | 508 | | |
507 | | - | |
| 509 | + | |
508 | 510 | | |
509 | 511 | | |
510 | 512 | | |
511 | 513 | | |
512 | 514 | | |
513 | 515 | | |
| 516 | + | |
514 | 517 | | |
515 | 518 | | |
516 | 519 | | |
| |||
532 | 535 | | |
533 | 536 | | |
534 | 537 | | |
| 538 | + | |
535 | 539 | | |
536 | 540 | | |
537 | 541 | | |
| |||
548 | 552 | | |
549 | 553 | | |
550 | 554 | | |
| 555 | + | |
551 | 556 | | |
552 | 557 | | |
553 | 558 | | |
| |||
559 | 564 | | |
560 | 565 | | |
561 | 566 | | |
| 567 | + | |
562 | 568 | | |
563 | 569 | | |
564 | 570 | | |
| |||
569 | 575 | | |
570 | 576 | | |
571 | 577 | | |
| 578 | + | |
572 | 579 | | |
573 | 580 | | |
574 | 581 | | |
| |||
581 | 588 | | |
582 | 589 | | |
583 | 590 | | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
0 commit comments