perf(common): extend ComputeDetails with VCPU + MemoryGB#97
Conversation
Adds optional VCPU (int) and MemoryGB (float64) fields to common.ComputeDetails so per-provider catalogue lookups can enrich compute recommendations with sizing data. Both fields use json omitempty — converters that don't yet wire a catalogue leave them at the zero value and the API payload stays clean. GetDetailDescription appends " (N vCPU / M GB)" when both values are > 0, otherwise returns the existing "platform/tenancy" form. Format uses %g so 16 GB renders as "16 GB" (not "16.000000 GB") while 0.5 GB SKUs render as "0.5 GB". Scope decision — schema-only foundation: - Azure: PR #81 (perf/azure-batched-sku-lookup) introduces the cachedSKULookup helper for cache/cosmos/database. Compute was scoped back from #81 because these fields didn't exist. With the schema in place, a follow-up PR can wire compute on top of #81 once it merges (filed as a separate issue post-merge to avoid an unmerged-PR dependency in this changeset). - AWS: ce.EC2InstanceDetails (Cost-Explorer) has no vCPU/Memory fields; populating would require a new ec2:DescribeInstanceTypes caller + cache + mocks. Substantial net-new code, tracked as a separate follow-up. - GCP: no compute recommendation converter exists today. N/A. - Frontend: api.Recommendation has no `details` field and the detail drawer renders a hard-coded list. Surfacing the new fields needs separate API + UI work; tracked as follow-up once at least one provider populates the fields. Tests: extend pkg/common/types_test.go::TestComputeDetails_GetDetail Description with 4 new table rows — VCPU-only, MemoryGB-only, integer-GB, and fractional-GB (Azure 0.5 GB SKU shape). Refs #82
|
@coderabbitai review |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
Adds
VCPU int+MemoryGB float64(bothomitempty) tocommon.ComputeDetailsso per-provider catalogue lookups can enrich computerecommendations with sizing data. Foundation work for the deferred Azure /
AWS / GCP compute SKU enrichment tracked in #82.
GetDetailDescriptionnow appends" (N vCPU / M GB)"when both valuesare populated; the existing
"platform/tenancy"form is preserved wheneither is zero (so today's call sites stay unchanged).
Scope decision — schema-only foundation
This PR intentionally lands only the shared-type schema + matcher
formatting + tests. Per-provider catalogue wiring is out of scope:
perf/azure-batched-sku-lookup) introduces thecachedSKULookuphelper for cache/cosmos/database. Compute was scopedback from perf(azure): batched SKU catalogue lookup eliminates N+1 in recommendation converters #81 because these struct fields didn't exist yet. With the
schema in place, a follow-up PR can wire compute on top of perf(azure): batched SKU catalogue lookup eliminates N+1 in recommendation converters #81 once it
merges. Filing the wiring against an unmerged PR here would create a
rebase/merge dependency that's better tracked as a separate issue.
ce.EC2InstanceDetails(Cost-Explorer) has no vCPU/Memoryfields. Populating would require a new
ec2:DescribeInstanceTypescaller + region-scoped catalogue cache + mocks/tests — substantial
net-new code, separate follow-up.
is added.
api.Recommendation(TS) has nodetailsfield and thedetail drawer renders a hard-coded list. Surfacing the new fields needs
separate API serializer + UI changes; tracked as a follow-up once at
least one provider populates the fields.
The schema change is the prerequisite that unblocks every one of those
follow-ups.
Changes
pkg/common/types.go::ComputeDetailsgainsVCPU+MemoryGB(
omitempty) with a doc comment explaining the catalogue-sourcecontract.
ComputeDetails.GetDetailDescription()appends the size suffix whenboth fields are > 0; uses
%gso16 GBrenders without trailingzeros while
0.5 GB(smallest Azure SKU) renders verbatim.pkg/common/types_test.goadds 4 table rows covering VCPU-only,MemoryGB-only (both fall back to base form), integer GB, and
fractional GB.
Test plan
go build ./...(root +pkg/)go test ./...(root)go test ./...frompkg/ComputeDetailsconsumers (Azure converter, AWS parser,cmd/main.go switch) continue compiling — no field is removed and
omitemptykeeps the JSON payload unchanged when fields aren'tpopulated
Follow-up issues (to file post-merge)
cachedSKULookupafter perf(azure): batched SKU catalogue lookup eliminates N+1 in recommendation converters #81 mergesDescribeInstanceTypesdetailstoapi.Recommendation+ render in the detaildrawer
Refs #82
Summary by CodeRabbit