Skip to content

feat(common): add EC2 platform, tenancy and scope dimensions to Commitment - #458

Merged
cristim merged 1 commit into
mainfrom
fix/323-dedupe-ec2-account-dims
Oct 16, 2026
Merged

cristim merged 1 commit into
mainfrom
fix/323-dedupe-ec2-account-dims

Conversation

@cristim

@cristim cristim commented Oct 16, 2026

Copy link
Copy Markdown
Member

Summary

This is PR 1a of the first #323 slice. It is behaviour-neutral by design.

The slice fixes the recfilter duplicate check for AWS EC2. A recent Windows, dedicated or zonal reservation currently counts as covering a Linux, default-tenancy or regional recommendation.

This PR only adds the data and the normalizers:

  • New common.Commitment fields: Platform, Tenancy, Scope and AvailabilityZone. They are flat and omitempty, following the Engine/Deployment precedent. An empty value means unknown, and the dedupe treats it as a wildcard that still covers. Account already exists and is unchanged.
  • common.NormalizeTenancyName:
    • "shared" and "default" both become "default".
    • "dedicated" and "host" stay distinct.
  • common.NormalizeScopeName:
    • "region" and "regional" become ScopeRegional.
    • "availability zone", "availability-zone" and "zonal" become ScopeZonal.
  • Both normalizers: they trim, ignore case, and return "" for anything they don't recognize. That makes an unknown value the fail-safe wildcard, never a value that matches nothing and lets a duplicate through. They mirror the inputs that parseEC2Tenancy and parseEC2Scope accept in providers/aws/services/ec2/client.go, which pkg cannot import, and cross-reference them.

Nothing reads the new fields yet. PR 1b adds the dedupe matching. Its core is scopeCovers, defined by an explicit truth table: a regional RI covers zonal usage, and a zonal RI never covers regional usage. PR 2 has the EC2 listing fill these fields.

Account keying is deliberately out of scope. With RI sharing, which is the Organizations default, keying on account would let a duplicate through. See the design note on #323.

Refs #323

Verification (macOS, Go 1.26.9)

  • (cd pkg && GOWORK=off go test -race -short ./...) passes.
  • make build and make vet pass.
  • golangci-lint v2.10.1 (CI pin) reports 0 issues.
  • GOWORK=off go build ./... passes in all five modules.
  • gofmt is clean.
  • The new tests are table tests for both normalizers, including the SDK spellings "Region" and "Availability Zone" and {"Bogus",""}. TestCommitment_EC2DimensionsJSON checks the fields are absent when empty, survive a round trip, and that an old payload without them still unmarshals.
  • Review: the plan went through review passes and two truth-table iterations with a non-author reviewer. The same reviewer did two diff passes. Pass 1 changed the unrecognized-input behaviour from pass-through to "" (fail-safe). There are no actionable findings on the final commit.

Unit tests only. No cloud call.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 4 billable files and costs up to $1.00.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 55 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 66 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-go/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 4dbbc1da-3868-4c71-a58a-812adf4fc864
📥 Commits

Reviewing files that changed from the base of the PR and between e75ac25 and 30e042d.

📒 Files selected for processing: 4
  • pkg/common/engine.go
  • pkg/common/engine_test.go
  • pkg/common/types.go
  • pkg/common/types_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@cristim cristim added priority/p2 Backlog-worthy severity/medium Moderate harm effort/l Weeks urgency/this-quarter Within the quarter impact/many Affects most users type/bug Defect triaged Item has been triaged labels Oct 16, 2026
@cristim

cristim commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim

cristim commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

Independent review verdict: CLEAN at 64c9741

Reviewer: fresh Claude agent (Sonnet, high effort), not the author, cold brief. The PR body was treated as a claim. Coordinator: claude-cc-reviewer.

Blocking findings: none.

No behaviour change:

  • The PR is +103/-0. A grep over the repo finds no non-test use of the new fields or the two new normalizers. The ScopeRegional hits are the AWS SDK constant.
  • The fields are flat and omitempty. A JSON test shows an empty Commitment emits none of the new keys, round-trips, and still unmarshals old JSON.
  • pkg has no reflect, gob or csv use, and no == on Commitment values.
  • The platform and cli repos were not checked, but the fields are zero-valued and omitted from JSON, so the risk is low.

Normalizers (pkg/common/engine.go, all lowercase and trim):

Function Mapping Anything else
NormalizePlatformName (unchanged) linux, unix → linux/unix; drops " (amazon vpc)" Passes through lowercased
NormalizeTenancyName (new) default, shared → default; dedicated → dedicated; host → host ""
NormalizeScopeName (new) region, regional → regional; availability zone, availability-zone, zonal → zonal ""

Notes for slice 1b (non-blocking):

  1. Unknown values become a wildcard. An unrecognised tenancy or scope normalizes to "", which this PR documents as "covers". In the 1b dedupe, an unexpected AWS value would then fail open and allow a duplicate purchase. Platform does the opposite and passes unknowns through. Consider an explicit unknown value, or an error.
  2. Scope tokens differ between layers. common uses regional/zonal, while the EC2 client and SDK use Region/Availability Zone. 1b needs an explicit mapping.
  3. Tenancy comment is slightly off. It says the normalizer mirrors parseEC2Tenancy, but that function (client.go:322) rejects host and this normalizer accepts it.
  4. No caller yet: the fields are unused until 1b.

What was attacked and how (pkg, GOWORK=off):

  • go vet ./common/... is clean, and go test -race -count=1 ./... passes 15 packages.
  • Mutation probes were not run: the reviewer's scratch-edit command was blocked by the local permission policy. Test coverage of the normalizer branches (e.g. "shared", "availability-zone") was confirmed by reading the tests only.

Gate:

@cristim

cristim commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

CI is green on head 64c97419: pre-commit 38948413371 and Build & Test 38948413351.

…tment

Behaviour-neutral first part of the #323 slice-1 dedupe fix. Adds flat
omitempty Platform, Tenancy, Scope and AvailabilityZone fields on
Commitment, plus NormalizeTenancyName and NormalizeScopeName next to
NormalizePlatformName. Nothing in pkg/recfilter reads the new fields yet,
so no dedupe result changes.

Refs #323

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cristim
cristim force-pushed the fix/323-dedupe-ec2-account-dims branch from 64c9741 to 30e042d Compare October 16, 2026 18:44
@cristim

cristim commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

Pure rebase onto main after go#453 merged. git range-diff of 64c9741 against new head 30e042d shows the commit as identical (=), so the CLEAN verdict carries. (claude-cc-reviewer)

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

Labels

effort/l Weeks impact/many Affects most users priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged type/bug Defect urgency/this-quarter Within the quarter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant