Repository navigation
fix(recfilter): match EC2 commitments on platform, tenancy and scope when deduplicating - #460
Conversation
|
Warning Review limit reached
This review includes 3 billable files and costs up to $0.75.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 11 seconds for your next included review. View limit details
Comment |
64c9741 to
30e042d
Compare
Independent review verdict: CLEAN at 18d68a9Reviewer: fresh Claude agent (Sonnet, high effort), not the author, cold brief. The PR body was treated as a claim. Coordinator: claude-cc-reviewer. Scope: the one commit on top of #458 (64c9741). Blocking findings: none. The duplicate-purchase direction was the focus: an owned RI that stops counting is re-bought. Behaviour is unchanged today.
When PR 2 populates the fields, the same real RI and recommendation normalize equal on every dimension:
Unrecognized tenancy or scope normalizes to Gating and scope coverage:
What was attacked and how (pkg,
Gate:
|
…when deduplicating AWS EC2 and compute commitments were deduplicated by region and instance type alone, so a Windows or dedicated reservation suppressed a Linux or default-tenancy recommendation. They now match on normalized platform and tenancy (empty on either side is a wildcard) and on scope. Scope is asymmetric: a regional reservation covers regional and zonal demand, a zonal one covers only its own zone, and an unknown scope on either side is a wildcard. Entries are kept in a stable order, fewest wildcards consumed first, and a recommendation is resized once to what remains. Account stays out of the key, so a commitment in another account still suppresses. Every other service keeps its existing key. Refs #323 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
18d68a9 to
ae714be
Compare
|
CI is green on head |
|
@coderabbitai review |
|
Summary
This is PR 1b of the first #323 slice. It is stacked on #458 (PR 1a), so merge #458 first, then retarget this PR to
main. CI only runs on PRs tomain.The recfilter duplicate check keyed AWS EC2 coverage on instance type and region only. A recent Windows, dedicated or zonal reservation therefore counted as covering a Linux, default-tenancy or regional recommendation. This PR adds the dimensions that rule out coverage, whatever the RI sharing setting. The new code is in
pkg/recfilter/dedupe_ec2.go;dedupe.gogets a small hook.Gating. The new matching applies only when Provider is AWS and Service is EC2 or Compute, checked on both the commitment and the recommendation side. Every other service keeps today's key and behaviour.
Platform and tenancy. Values must be equal after
NormalizePlatformName/NormalizeTenancyName, or else empty on either side. An empty value is a wildcard that still covers.Scope. Each side gets one of three states: zonal(az), regional, or unknown.
scopeCovers(entry, rec)implements this truth table, mirrored row by row inTestScopeCovers:Matching. Each base key holds a stable-ordered slice of entries, sorted by wildcard count and then input order. No map iteration. A rec consumes exact matches before wildcards. Partial consumption is summed, and
common.ResizeCountis called once, so money scales with the count.Unrecognized values.
Account is deliberately not keyed. A commitment in another linked account still suppresses, and a test pins that. Under RI sharing, the Organizations default, keying on account would let a duplicate through. See the design note on #323.
PR 2 has the EC2 listing (
GetExistingCommitments) fill these fields. Until then, real EC2 commitments carry empty dimensions and behave as wildcards, which is exactly today's behaviour. Size-flexibility is out of scope.Refs #323
Verification (macOS, Go 1.26.9)
Build and lint
(cd pkg && GOWORK=off go test -race -short ./...)passes.make buildandmake vetpass.GOWORK=off go build ./...passes in all five modules.Tests
TestScopeCovers.TestEC2DedupeMatching:TestEC2DedupeValueDetails(value and typed-nil details).TestEC2DedupeAzureNotKeyed.TestEC2DedupeWildcardPreference: determinism, and a count-5 rec against 2 exact + 2 wildcard entries with money scaled for 1.TestEC2DedupeEntryOrder: exact matches are consumed before wildcards, and input order breaks ties.Fail-before. On 1a's code these fail: Windows vs Linux, dedicated vs default, zonal vs regional, the other-zone case, the wildcard preference test and the WARN test.
Mutation probes. The independent reviewer ran these in scratch copies, and each one fails a test:
scopeCovers, or let a zonal-empty-AZ entry cover regional;Review. The plan went through two passes plus truth-table iterations with a non-author reviewer. The same reviewer did three diff passes. Pass 1 found the vacuous ordering test, a missing platform WARN and an unneeded skip. Pass 2 found the SQL Server prefix and the WARN wording. No actionable findings remained.
Unit tests with constructed commitments and recommendations only. No cloud call.
🤖 Generated with Claude Code